Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
Update Platform class
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Mar 19, 2022
1 parent af6132f commit 1a99891
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
14 changes: 11 additions & 3 deletions src/main/java/io/github/eb4j/ebview/utils/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,31 @@ public static OsType getOsType() {
}

/**
* Returns true if running on Mac OS X
* Returns true if running on Windoows.
*/
public static boolean isWindows() {
OsType os = getOsType();
return os == OsType.WIN32 || os == OsType.WIN64;
}

/**
* Returns true if running on Mac OS X.
*/
public static boolean isMacOSX() {
OsType os = getOsType();
return os == OsType.MAC32 || os == OsType.MAC64;
}

/**
* Returns true if running on Linux
* Returns true if running on Linux.
*/
public static boolean isLinux() {
OsType os = getOsType();
return os == OsType.LINUX32 || os == OsType.LINUX64;
}

/**
* Returns true if the JVM (NOT the OS) is 64-bit
* Returns true if the JVM (NOT the OS) is 64-bit.
*/
public static boolean is64Bit() {
String osArch = System.getProperty("os.arch");
Expand Down
25 changes: 3 additions & 22 deletions src/main/java/io/github/eb4j/ebview/utils/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public final class Preferences {
* files.
*/
private static String configDir = null;

/** Private constructor, because this file is singleton */
private Preferences() {
}
Expand Down Expand Up @@ -178,48 +179,28 @@ public static String getConfigDir() {
}

// check for Windows versions
if (os == Platform.OsType.WIN32 || os == Platform.OsType.WIN64) {
if (Platform.isWindows()) {
String appData = null;

// We do not use %APPDATA%
// Trying first Vista/7, because "Application Data" exists also as virtual folder,
// so we would not be able to differentiate with 2000/XP otherwise
File appDataFile = new File(home, "AppData\\Roaming");
if (appDataFile.exists()) {
appData = appDataFile.getAbsolutePath();
} else {
// Trying to locate "Application Data" for 2000 and XP
// C:\Documents and Settings\<User>\Application Data
appDataFile = new File(home, "Application Data");
if (appDataFile.exists()) {
appData = appDataFile.getAbsolutePath();
}
}

if (!StringUtils.isEmpty(appData)) {
// if a valid application data dir has been found,
// append an OmegaT subdir to it
configDir = appData + WINDOWS_CONFIG_DIR;
} else {
// otherwise set the config dir to the user's home directory,
// usually
// C:\Documents and Settings\<User>\OmegaT
configDir = home + WINDOWS_CONFIG_DIR;
}
// Check for UNIX varieties
// Solaris is generally detected as SunOS
} else if (os == Platform.OsType.LINUX32 || os == Platform.OsType.LINUX64 || os == Platform.OsType.OTHER) {
// set the config dir to the user's home dir + "/.omegat/", so it's
// hidden
} else if (Platform.isLinux() || os == Platform.OsType.OTHER) {
configDir = home + UNIX_CONFIG_DIR;
// check for Mac OS X
} else if (Platform.isMacOSX()) {
// set the config dir to the user's home dir +
// "/Library/Preferences/OmegaT/"
configDir = home + OSX_CONFIG_DIR;
// other OSes / default
} else {
// use the user's home directory by default
configDir = home + File.separator;
}

Expand Down

0 comments on commit 1a99891

Please sign in to comment.