Created
January 28, 2013 18:46
-
-
Save moomoohk/4657992 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OSUtils | |
{ | |
private static String cachedUserHome; | |
public static enum OS | |
{ | |
WINDOWS, UNIX, MACOSX, OTHER, | |
} | |
static | |
{ | |
cachedUserHome = System.getProperty("user.home"); | |
} | |
/** | |
* Used to get the dynamic storage location based off OS | |
* | |
* @return string containing dynamic storage location | |
*/ | |
public static String getDynamicStorageLocation() | |
{ | |
switch (getCurrentOS()) | |
{ | |
case WINDOWS: | |
return System.getenv("APPDATA") + "/MyGame/"; | |
case MACOSX: | |
return cachedUserHome + "/Library/Application Support/MyGame/"; | |
case UNIX: | |
return cachedUserHome + "/.MyGame/"; | |
default: | |
return getDefInstallPath() + "/temp/"; | |
} | |
} | |
/** | |
* Used to get the current operating system | |
* | |
* @return OS enum representing current operating system | |
*/ | |
public static OS getCurrentOS() | |
{ | |
String osString = System.getProperty("os.name").toLowerCase(); | |
if (osString.contains("win")) | |
{ | |
return OS.WINDOWS; | |
} | |
else | |
if (osString.contains("nix") || osString.contains("nux")) | |
{ | |
return OS.UNIX; | |
} | |
else | |
if (osString.contains("mac")) | |
{ | |
return OS.MACOSX; | |
} | |
else | |
{ | |
return OS.OTHER; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment