Skip to content

Instantly share code, notes, and snippets.

@moomoohk
Created January 28, 2013 18:46
Show Gist options
  • Save moomoohk/4657992 to your computer and use it in GitHub Desktop.
Save moomoohk/4657992 to your computer and use it in GitHub Desktop.
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