diff --git a/app/src/processing/app/platform/WindowsPlatform.java b/app/src/processing/app/platform/WindowsPlatform.java index 3ec8941a9..b5b1100b0 100644 --- a/app/src/processing/app/platform/WindowsPlatform.java +++ b/app/src/processing/app/platform/WindowsPlatform.java @@ -111,8 +111,29 @@ boolean register() throws UnsupportedEncodingException { // { Base.CONTRIB_BUNDLE_EXT, "Processing Contribution Bundle" } // }; - static final String REG_APP_DIR = - System.getProperty("user.dir").replace('/', '\\'); + static boolean exeFileExists(File folder) { + File exeFile = new File(folder, APP_NAME.toLowerCase() + ".exe"); + return exeFile.exists(); + } + + static String getRegAppDir() { + try { + // Get the JAR file containing this class (WindowsPlatform) + File jarFile = new File(WindowsPlatform.class.getProtectionDomain(). + getCodeSource().getLocation().toURI()); + // Get the JAR folder ("app" in the standard jpackage layout) + File jarDir = jarFile.getParentFile(); + // Get the processing.exe folder (parent of "app" in the standard layout) + File exeDir = jarDir.getParentFile(); + + if (exeFileExists(exeDir)) return exeDir.getAbsolutePath(); // standard folder layout + if (exeFileExists(jarDir)) return jarDir.getAbsolutePath(); // if exe and jar is in same folder + } catch (java.net.URISyntaxException e) { + } + return System.getProperty("user.dir"); // processing.exe not found + } + + static final String REG_APP_DIR = getRegAppDir().replace('/', '\\'); static final String REG_OPEN_COMMAND = REG_APP_DIR + "\\" + APP_NAME.toLowerCase() + ".exe \"%1\""; static final String[] APP_SCHEMES = { "pde" }; // use pde://