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

Commit

Permalink
Add Platform class to detect OSes
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 17, 2022
1 parent 5e617a3 commit 050ecc4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/main/java/io/github/eb4j/ebview/utils/Platform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* EBViewer, a dictionary viewer application.
* Copyright (C) 2022 Hiroshi Miura.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package io.github.eb4j.ebview.utils;

public final class Platform {
public enum OsType {
// os.arch=amd64, os.name=Linux, os.version=3.0.0-12-generic
LINUX64,
// os.arch=i386, os.name=Linux, os.version=3.0.0-12-generic
LINUX32,
// os.arch=x86_64, os.name=Mac OS X, os.version=10.6.8
MAC64,
// os.arch=i386, os.name=Mac OS X, os.version=10.6.8
MAC32,
// os.arch=amd64, os.name=Windows 7, os.version=6.1
WIN64,
// os.arch=x86, os.name=Windows 7, os.version=6.1
WIN32,
// unknown system
OTHER
}

private static OsType osType = OsType.OTHER;

static {
String osName = System.getProperty("os.name");
if (osName != null && System.getProperty("os.arch") != null) {
boolean is64 = is64Bit();
if (osName.startsWith("Linux")) {
osType = is64 ? OsType.LINUX64 : OsType.LINUX32;
} else if (osName.contains("OS X")) {
osType = is64 ? OsType.MAC64 : OsType.MAC32;
} else if (osName.startsWith("Windows")) {
osType = is64 ? OsType.WIN64 : OsType.WIN32;
}
}
}

private Platform() {
}

public static OsType getOsType() {
return osType;
}

/**
* 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
*/
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
*/
public static boolean is64Bit() {
String osArch = System.getProperty("os.arch");
if (osArch != null) {
return osArch.contains("64");
}
return false;
}
}
26 changes: 26 additions & 0 deletions src/main/resources/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,29 @@ ABOUT_COPYRIGHT=Copyright (C) 2016-2021 Hiroshi Miura\n\
GNU General Public License for more details. \n\n\
You should have received a copy of the GNU General Public License \n\
along with this program. If not, see <http://www.gnu.org/licenses/>.
PASSWORD_DIALOG_TITLE=Enter password
PASSWORD_ERROR_EMPTY=Empty password not allowed
PASSWORD_SET_MESSAGE=Please set password
PASSWORD_INPUT_LABEL=Password
PASSWORD_CONFIRM_LABEL=Password(Confirm)
PASSWORD_DO_NOT_SET_BUTTON=Do not set
BUTTON_OK=Ok
BUTTON_CANCEL=Cancel
PASSWORD_ENTER_MESSAGE=Enter password
PASSWORD_TRY_AGAIN_MESSAGE=Try password again
PREFS_OXFORD_DESC=Please set appId and appKey of Oxford dictionaries API.
PREFS_OXFORD_APPID_LABEL=AppID
PREFS_OXFORD_APPKEY_LABEL=AppKey
PREFS_TITLE_SECURE_STORE=Secure Store
PREFS_SECURE_STORE_DESCRIPTION=OmegaT encrypts sensitive passwords and API keys with a master password.
PREFS_SECURE_STORE_MASTER_PASSWORD_LABEL=Master Password:
PREFS_SECURE_STORAGE_RESET_BUTTON=&Reset Master Password
PREFS_SECURE_STORAGE_MASTER_PASSWORD_SET_STORED=Set & Stored
PREFS_SECURE_STORAGE_MASTER_PASSWORD_SET=Set
PREFS_SECURE_STORAGE_MASTER_PASSWORD_NOT_SET=Not Set
PREFS_SECURE_STORAGE_RESET_MASTER_PASSWORD_TITLE=Reset Master Password
PREFS_SECURE_STORAGE_RESET_MASTER_PASSWORD_MESSAGE=Are you sure you want to reset the master password? All preferences protected by the master password will be reset.
MENU_APP=Application
MENU_APP_PREFERENCE=Preference
MENU_APP_QUIT_TRAY=Quit to tray
MENU_APP_EXIT=Exit application

0 comments on commit 050ecc4

Please sign in to comment.