Skip to content

Commit

Permalink
Resolve #250 #481
Browse files Browse the repository at this point in the history
Still needs to be tested on Linux, please feel free to report any issues found with the implementation
  • Loading branch information
Konloch committed Jan 10, 2024
1 parent 5c9af84 commit ceaad0d
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/main/java/the/bytecode/club/bytecodeviewer/Constants.java
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.PrintStream;

import org.objectweb.asm.Opcodes;
import the.bytecode.club.bytecodeviewer.resources.ResourceType;

Expand Down Expand Up @@ -68,8 +69,7 @@ public class Constants
public static final String fs = System.getProperty("file.separator");
public static final String nl = System.getProperty("line.separator");

//TODO check if $HOME/.local/share exists, if so reference from there instead - #250
public static final File BCVDir = new File(System.getProperty("user.home") + fs + ".Bytecode-Viewer");
public static final File BCVDir = resolveBCVRoot();
public static final File RT_JAR = new File(System.getProperty("java.home") + fs + "lib" + fs + "rt.jar");
public static final File JAVA_BINARY = new File(System.getProperty("java.home") + fs + "bin" + fs + "java.exe");
public static final File JAVA_BINARY_NIX = new File(System.getProperty("java.home") + fs + "bin" + fs + "java");
Expand All @@ -88,6 +88,30 @@ public class Constants
public static final PrintStream ERR = System.err;
public static final PrintStream OUT = System.out;

public static File resolveBCVRoot()
{
File defaultLocation = new File(System.getProperty("user.home") + fs + ".Bytecode-Viewer");

//if BCV was previously installed using the default directory, continue to use that
if(defaultLocation.exists())
return defaultLocation;

//handle XDG Base Directory - https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
if(isLinux())
{
File homeLocal = new File(System.getProperty("user.home") + fs + ".local");
if(homeLocal.exists())
return new File(homeLocal, "share" + fs + ".Bytecode-Viewer");

File homeConfig = new File(System.getProperty("user.home") + fs + ".config");
if(homeConfig.exists())
return new File(homeConfig, ".Bytecode-Viewer");
}

//return BCV default location
return defaultLocation;
}

/**
* Returns the BCV directory
*
Expand Down Expand Up @@ -126,6 +150,16 @@ private static boolean isWindows()
return System.getProperty("os.name").toLowerCase().contains("win");
}

/**
* Checks if the OS contains 'linux'
*
* @return true if the os.name property contains 'linux'
*/
private static boolean isLinux()
{
return System.getProperty("os.name").toLowerCase().contains("linux");
}

/**
* Detects developer mode or returns the current version
*/
Expand Down

0 comments on commit ceaad0d

Please sign in to comment.