Created
May 16, 2016 05:55
-
-
Save monkstone/e817fd20ae2d5fa8025d094725ab4dbf to your computer and use it in GitHub Desktop.
PApplet line 7475 or thereabouts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a full path to an item in the data folder as a File object. | |
* See the dataPath() method for more information. | |
*/ | |
public File dataFile(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/Java/")) { | |
// The path will be URL encoded (%20 for spaces) coming from above | |
// http://code.google.com/p/processing/issues/detail?id=1073 | |
File containingFolder = new File(urlDecode(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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment