Better-defined root directory.

- If running from a JAR, the root directory will be the same directory as the JAR (not where it was launched).
- Otherwise, use the current working directory.
- XDG unaffected.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2016-12-22 19:54:05 -05:00
parent 25efbd3023
commit 81c8a61bb8
2 changed files with 14 additions and 2 deletions

View File

@ -169,8 +169,11 @@ public class Options {
* @return the XDG base directory, or the working directory if unavailable
*/
private static File getXDGBaseDir(String env, String fallback) {
File workingDir = Utils.isJarRunning() ?
Utils.getRunningDirectory().getParentFile() : Utils.getWorkingDirectory();
if (!USE_XDG)
return new File("./");
return workingDir;
String OS = System.getProperty("os.name").toLowerCase();
if (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0) {
@ -186,7 +189,7 @@ public class Options {
ErrorHandler.error(String.format("Failed to create configuration folder at '%s/opsu'.", rootPath), null, false);
return dir;
} else
return new File("./");
return workingDir;
}
/**

View File

@ -41,6 +41,7 @@ import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
@ -541,6 +542,14 @@ public class Utils {
}
}
/**
* Returns the current working directory.
* @return the directory
*/
public static File getWorkingDirectory() {
return Paths.get(".").toAbsolutePath().normalize().toFile();
}
/**
* Parses the integer string argument as a boolean:
* {@code 1} is {@code true}, and all other values are {@code false}.