From 1a99891fd10fd3fa75e2f2b27ee44fa451f0f5f0 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Sat, 19 Mar 2022 12:18:14 +0900 Subject: [PATCH] Update Platform class Signed-off-by: Hiroshi Miura --- .../io/github/eb4j/ebview/utils/Platform.java | 14 ++++++++--- .../github/eb4j/ebview/utils/Preferences.java | 25 +++---------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/github/eb4j/ebview/utils/Platform.java b/src/main/java/io/github/eb4j/ebview/utils/Platform.java index 6384110..4fa2ab2 100644 --- a/src/main/java/io/github/eb4j/ebview/utils/Platform.java +++ b/src/main/java/io/github/eb4j/ebview/utils/Platform.java @@ -61,7 +61,15 @@ 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(); @@ -69,7 +77,7 @@ public static boolean isMacOSX() { } /** - * Returns true if running on Linux + * Returns true if running on Linux. */ public static boolean isLinux() { OsType os = getOsType(); @@ -77,7 +85,7 @@ public static boolean isLinux() { } /** - * 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"); diff --git a/src/main/java/io/github/eb4j/ebview/utils/Preferences.java b/src/main/java/io/github/eb4j/ebview/utils/Preferences.java index 5064cdf..8890ca8 100644 --- a/src/main/java/io/github/eb4j/ebview/utils/Preferences.java +++ b/src/main/java/io/github/eb4j/ebview/utils/Preferences.java @@ -61,6 +61,7 @@ public final class Preferences { * files. */ private static String configDir = null; + /** Private constructor, because this file is singleton */ private Preferences() { } @@ -178,18 +179,12 @@ 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\\Application Data appDataFile = new File(home, "Application Data"); if (appDataFile.exists()) { appData = appDataFile.getAbsolutePath(); @@ -197,29 +192,15 @@ public static String getConfigDir() { } 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\\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; }