trying to sort out path and bits issues for 2.0a2

This commit is contained in:
benfry
2011-11-01 00:47:37 +00:00
parent 2832dcfcf9
commit d01b4e7bf4
6 changed files with 52 additions and 11 deletions

View File

@@ -6548,8 +6548,8 @@ public class PApplet extends Applet
return sketchPath + File.separator + "data" + File.separator + where;
}
/**
* Return a full path to an item in the data folder as a File object.
* See the dataPath() method for more information.
@@ -6559,6 +6559,32 @@ public class PApplet extends Applet
}
/**
* On Windows and Linux, this is simply the data folder. On Mac OS X, this is
* the path to the data folder buried inside Contents/Resources/Java
*/
public File inputFile(String where) {
// isAbsolute() could throw an access exception, but so will writing
// to the local disk using the sketch path, so this is safe here.
File why = new File(where);
if (why.isAbsolute()) return why;
String jarPath = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
if (jarPath.contains("Contents/Resources/Java/")) {
File containingFolder = new File(jarPath).getParentFile();
File dataFolder = new File(containingFolder, "data");
return new File(dataFolder, where);
}
// Windows, Linux, or when not using a Mac OS X .app file
return new File(sketchPath + File.separator + "data" + File.separator + where);
}
public String inputPath(String where) {
return inputFile(where).getAbsolutePath();
}
/**
* Takes a path and creates any in-between folders if they don't
* already exist. Useful when trying to save to a subfolder that