Skip to content

Commit

Permalink
Root properties fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vzor- committed Apr 10, 2021
1 parent fd5fdc1 commit 48c1f4a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 20 deletions.
1 change: 0 additions & 1 deletion ant/apple/installer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
-->

<!-- payload/Contents/ -->
<mkdir dir="${build.dir}/scripts/payload/Resources"/>
<copy todir="${build.dir}/scripts/payload/Contents">
<fileset dir="${dist.dir}"/>
</copy>
Expand Down
2 changes: 1 addition & 1 deletion src/qz/common/SecurityInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static SortedMap<String,String> getLibVersions() {
Method method = VersionInfo.getMethod("getVersion");
Object version = method.invoke(null);
libVersions.put("javafx", (String)version);
if (fxPath.contains(SystemUtilities.detectJarPath()) || fxPath.contains("/tray/")) {
if (fxPath.contains(SystemUtilities.getJarPath()) || fxPath.contains("/tray/")) {
libVersions.put("javafx (location)", "Bundled/" + Constants.ABOUT_TITLE);
} else {
libVersions.put("javafx (location)", "System/" + Constants.JAVA_VENDOR);
Expand Down
1 change: 1 addition & 0 deletions src/qz/installer/MacInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public Installer removeLegacyStartup() {
return this;
}

//fixme: overlaps systemUtilities.getAppPath
public static String getAppPath() {
// Return the Mac ".app" location
String target = SystemUtilities.getJarPath();
Expand Down
2 changes: 1 addition & 1 deletion src/qz/installer/certificate/CertificateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static File getWritableLocation(String ... subDirs) throws IOException {

if (subDirs.length == 0) {
// Assume root directory is next to jar (e.g. qz-tray.properties)
Path appPath = SystemUtilities.detectAppPath();
Path appPath = Paths.get(SystemUtilities.getJarPath()).getParent();
// Handle null path, such as running from IDE
if(appPath != null) {
locs.add(appPath);
Expand Down
1 change: 1 addition & 0 deletions src/qz/installer/shortcut/WindowsShortcutCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private void createShortcut(String folderPath) {

/**
* Calculates .exe path from .jar
* fixme: overlaps SystemUtilities.getAppPath
*/
private static String getAppPath() {
return SystemUtilities.getJarPath().replaceAll(".jar$", ".exe");
Expand Down
2 changes: 1 addition & 1 deletion src/qz/printer/action/WebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static synchronized void initialize() throws IOException {
if (Constants.JAVA_VERSION.greaterThanOrEqualTo(Version.valueOf("11.0.0"))) {
// JavaFX native libs
if (SystemUtilities.isJar()) {
SystemUtilities.appendProperty("java.library.path", new File(SystemUtilities.detectJarPath()).getParent() + "/libs/");
SystemUtilities.appendProperty("java.library.path", new File(SystemUtilities.getJarPath()).getParent() + "/libs/");
} else if (hasConflictingLib()) {
// IDE helper for "no suitable pipeline found" errors
System.err.println("\n=== WARNING ===\nWrong javafx platform detected. Delete lib/javafx/<platform> to correct this.\n");
Expand Down
24 changes: 8 additions & 16 deletions src/qz/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,22 @@ public static Version getJavaVersion(String version) {

/**
* Determines the currently running Jar's absolute path on the local filesystem
* todo: make this return a sane directory for running via ide

This comment has been minimized.

Copy link
@tresf

tresf Apr 10, 2021

Contributor

Todo: skip this "sane directory" fallback behavior for Certificate Manager / qz-tray.properties

*
* @return A String value representing the absolute path to the currently running
* jar
*/
public static String detectJarPath() {
public static String getJarPath() {
if (jarPath != null) {
return jarPath;
}
try {
String jarPath = new File(SystemUtilities.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getCanonicalPath();
String path = new File(SystemUtilities.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getCanonicalPath();
// Fix characters that get URL encoded when calling getPath()
return URLDecoder.decode(jarPath, "UTF-8");
jarPath = URLDecoder.decode(path, "UTF-8");
} catch(IOException ex) {
log.error("Unable to determine Jar path", ex);
}
return null;
}

/**
* Returns the jar which we will create a shortcut for
*
* @return The path to the jar path which has been set
*/
public static String getJarPath() {
if (jarPath == null) {
jarPath = detectJarPath();
}
return jarPath;
}

Expand All @@ -189,7 +181,7 @@ public static String getJarPath() {
* @return
*/
public static Path detectAppPath() {
String jarPath = detectJarPath();
String jarPath = getJarPath();
if (jarPath != null) {
File jar = new File(jarPath);
if (jar.getPath().endsWith(".jar") && jar.exists()) {
Expand Down

0 comments on commit 48c1f4a

Please sign in to comment.