From 1d36fa5b61c797ed0a6392b2c06f97b2b89b1fe7 Mon Sep 17 00:00:00 2001 From: Matthias Fussenegger Date: Sun, 21 Apr 2024 11:37:36 +0200 Subject: [PATCH] Add MacOS support --- .../gzipper/java/application/model/OS.java | 2 +- .../application/model/OperatingSystem.java | 22 +++++++++++++++++++ .../gzipper/java/presentation/GZipper.java | 8 ++----- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gzipper/java/application/model/OS.java b/src/main/java/org/gzipper/java/application/model/OS.java index 087dbb2..6e68552 100644 --- a/src/main/java/org/gzipper/java/application/model/OS.java +++ b/src/main/java/org/gzipper/java/application/model/OS.java @@ -25,7 +25,7 @@ */ public enum OS { - UNIX("Unix", 3), WINDOWS("Windows", 11); + UNIX("Unix", 3), WINDOWS("Windows", 11), MAC("MacOS", 7); /** * The name of the operating system. diff --git a/src/main/java/org/gzipper/java/application/model/OperatingSystem.java b/src/main/java/org/gzipper/java/application/model/OperatingSystem.java index be2f5d7..bec1a46 100644 --- a/src/main/java/org/gzipper/java/application/model/OperatingSystem.java +++ b/src/main/java/org/gzipper/java/application/model/OperatingSystem.java @@ -39,6 +39,23 @@ public OperatingSystem(OS operatingSystem) { _operatingSystem = operatingSystem; } + /** + * Creates a new instance of {@link OperatingSystem} by parsing the specified name of an operating system. + * + * @param osName the name of the operating system. + * @return a new instance of {@link OperatingSystem}. + */ + public static OperatingSystem create(String osName) { + osName = osName.toLowerCase(); + if (osName.contains("windows")) { + return new OperatingSystem(OS.WINDOWS); + } else if (osName.contains("mac")) { + return new OperatingSystem(OS.MAC); + } else { + return new OperatingSystem(OS.UNIX); + } + } + /** * Returns the default user directory of the system. * @@ -56,4 +73,9 @@ public String getDefaultUserDirectory() { public OS getOsInfo() { return _operatingSystem; } + + @Override + public String toString() { + return _operatingSystem.toString(); + } } diff --git a/src/main/java/org/gzipper/java/presentation/GZipper.java b/src/main/java/org/gzipper/java/presentation/GZipper.java index 5e1e5d5..55fd6fd 100644 --- a/src/main/java/org/gzipper/java/presentation/GZipper.java +++ b/src/main/java/org/gzipper/java/presentation/GZipper.java @@ -67,12 +67,8 @@ private void initApplication() { } } - // determine operating system and initialize settings class - OperatingSystem os = System.getProperty("os.name") - .toLowerCase().startsWith("windows") - ? new OperatingSystem(OS.WINDOWS) - : new OperatingSystem(OS.UNIX); - + var os = OperatingSystem.create(System.getProperty("os.name")); + Log.i("Determined operating system: " + os, false); Settings.getInstance().init(settings, os); }