Skip to content

Commit

Permalink
change how sketch path is calculated to go relative to the .jar
Browse files Browse the repository at this point in the history
  • Loading branch information
benfry committed Aug 12, 2015
1 parent da7b6d5 commit 26a9ffb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
47 changes: 29 additions & 18 deletions core/src/processing/core/PApplet.java
Expand Up @@ -7345,18 +7345,26 @@ static protected String calcSketchPath() {
try {
folder = System.getProperty("user.dir");

String jarPath =
PApplet.class.getProtectionDomain().getCodeSource().getLocation().getPath();
// The jarPath from above will be URL encoded (%20 for spaces)
jarPath = urlDecode(jarPath);

// Workaround for bug in Java for OS X from Oracle (7u51)
// https://github.com/processing/processing/issues/2181
if (platform == MACOSX) {
String jarPath =
PApplet.class.getProtectionDomain().getCodeSource().getLocation().getPath();
// The jarPath from above will be URL encoded (%20 for spaces)
jarPath = urlDecode(jarPath);
if (jarPath.contains("Contents/Java/")) {
String appPath = jarPath.substring(0, jarPath.indexOf(".app") + 4);
File containingFolder = new File(appPath).getParentFile();
folder = containingFolder.getAbsolutePath();
}
} else {
// Working directory may not be set properly, try some options
// https://github.com/processing/processing/issues/2195
if (jarPath.contains("/lib/")) {
// Windows or Linux, back up a directory to get the executable
folder = new File(jarPath, "../..").getCanonicalPath();
}
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -7463,20 +7471,18 @@ static public String desktopPath(String what) {


/**
* Return a full path to an item in the data folder.
* <b>This function almost certainly does not do the thing you want it to.</b>
* The data path is handled differently on each platform, and should not be
* considered a location to write files. It should also not be assumed that
* this location can be read from or listed. This function is used internally
* as a possible location for reading files. It's still "public" as a
* holdover from earlier code.
* <p>
* This is only available with applications, not applets or Android.
* On Windows and Linux, this is simply the data folder, which is located
* in the same directory as the EXE file and lib folders. On Mac OS X, this
* is a path to the data folder buried inside Contents/Java.
* For the latter point, that also means that the data folder should not be
* considered writable. Use sketchPath() for now, or inputPath() and
* outputPath() once they're available in the 2.0 release.
* <p>
* dataPath() is not supported with applets because applets have their data
* folder wrapped into the JAR file. To read data from the data folder that
* works with an applet, you should use other methods such as createInput(),
* createReader(), or loadStrings().
* Libraries should use createInput() to get an InputStream or createOutput()
* to get an OutputStream. sketchPath() can be used to get a location
* relative to the sketch. Again, <b>do not</b> use this to get relative
* locations of files. You'll be disappointed when your app runs on different
* platforms.
*/
public String dataPath(String where) {
return dataFile(where).getAbsolutePath();
Expand All @@ -7503,7 +7509,12 @@ public File dataFile(String where) {
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);
File workingDirItem =
new File(sketchPath + File.separator + "data" + File.separator + where);
// if (workingDirItem.exists()) {
return workingDirItem;
// }
// // In some cases, the current working directory won't be set properly.
}


Expand Down
17 changes: 10 additions & 7 deletions core/todo.txt
@@ -1,13 +1,15 @@
0242 core (3.0b4)

earlier
X are we clear on sketchPath() for OS X?
X working dir (user.dir?) returns home dir, not app dir in Oracle Java
X could add -Dapp.root=$APP_ROOT and get via System.getProperty("app.root")
X https://github.com/processing/processing/issues/2181

opengl
X filter(PShader) broken in HDPI mode
X https://github.com/processing/processing/issues/3577
_ Use PBOs for async texture copy
_ https://github.com/processing/processing/issues/3569
_ filter(PShader) broken in HiDPI mode
_ https://github.com/processing/processing/issues/3577


docs
_ note that full screen and present are now different
Expand All @@ -30,9 +32,6 @@ _ use the BufferStrategy directly from the Frame object?
_ might fix performance issues w/ Presentation mode
_ sketch placement (window insets) not properly set on Linux
_ https://github.com/processing/processing/issues/2063
_ are we clear on sketchPath() for OS X?
_ working dir (user.dir?) returns home dir, not app dir in Oracle Java
_ could add -Dapp.root=$APP_ROOT and get via System.getProperty("app.root")


javafx
Expand Down Expand Up @@ -71,6 +70,10 @@ _ https://www.linkedin.com/pulse/oracle-just-removed-javafx-support-arm-jan-sn


opengl
_ Use PBOs for async texture copy
_ https://github.com/processing/processing/issues/3569
_ filter(PShader) broken in HiDPI mode
_ https://github.com/processing/processing/issues/3577
_ hard crash at 1920x1080, mirrored, Casey's GT 650M 1GB
_ window loses focus after maximizing
_ https://github.com/processing/processing/issues/3339
Expand Down
8 changes: 6 additions & 2 deletions todo.txt
Expand Up @@ -3,11 +3,17 @@ X Fix NullPointerException with some sketches that have no size() command
X https://github.com/processing/processing/issues/3585
X Invalid OS X code signature
X https://github.com/processing/processing/issues/3575
_ canceling the "create folder, move sketch, and continue?" will cause crash
_ throws an NPE and then forces a quit

gsoc
X Second round of arm patches (v5)
X https://github.com/processing/processing/pull/3583

earlier
X closing the color selector makes things freeze (only Linux and Windows?)
X https://github.com/processing/processing/issues/2381


known issues
_ launch4j doesn't work from folders with non-native charsets
Expand Down Expand Up @@ -189,8 +195,6 @@ _ disable the Export button if no platforms selected on Export to Application
help me
_ "String index out of range" error
_ https://github.com/processing/processing/issues/1940
_ closing the color selector makes things freeze (only Linux and Windows?)
_ https://github.com/processing/processing/issues/2381
_ problems with non-US keyboards and some shortcuts
_ https://github.com/processing/processing/issues/2199
_ clean up 'ant doc' target to remove warnings
Expand Down

0 comments on commit 26a9ffb

Please sign in to comment.