Skip to content

Commit

Permalink
Add MacOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolocust committed Apr 21, 2024
1 parent 864001c commit 1d36fa5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/gzipper/java/application/model/OS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -56,4 +73,9 @@ public String getDefaultUserDirectory() {
public OS getOsInfo() {
return _operatingSystem;
}

@Override
public String toString() {
return _operatingSystem.toString();
}
}
8 changes: 2 additions & 6 deletions src/main/java/org/gzipper/java/presentation/GZipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1d36fa5

Please sign in to comment.