Collection of useful utilities for Java games and apps. A lot of interesting utilities that could maybe still find some use if you work with Java...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mightyutils/src/mightypork/utils/files/OsUtils.java

94 lines
1.6 KiB

package mightypork.utils.files;
import java.io.File;
public class OsUtils {
public static enum EnumOS
{
linux, macos, solaris, unknown, windows;
public boolean isLinux()
{
return this == linux || this == solaris;
}
public boolean isMac()
{
return this == macos;
}
public boolean isWindows()
{
return this == windows;
}
}
private static EnumOS cachedOs;
public static File getHomeWorkDir(String dirname)
{
final String userhome = System.getProperty("user.home", ".");
File file;
switch (getOs()) {
case linux:
case solaris:
file = new File(userhome, dirname + '/');
break;
case windows:
final String appdata = System.getenv("APPDATA");
if (appdata != null) {
file = new File(appdata, dirname + '/');
} else {
file = new File(userhome, dirname + '/');
}
break;
case macos:
file = new File(userhome, "Library/Application Support/" + dirname);
break;
default:
file = new File(userhome, dirname + "/");
break;
}
return file;
}
public static EnumOS getOs()
{
if (cachedOs != null) return cachedOs;
final String s = System.getProperty("os.name").toLowerCase();
if (s.contains("win")) {
cachedOs = EnumOS.windows;
} else if (s.contains("mac")) {
cachedOs = EnumOS.macos;
} else if (s.contains("linux") || s.contains("unix")) {
cachedOs = EnumOS.linux;
} else if (s.contains("solaris") || s.contains("sunos")) {
cachedOs = EnumOS.solaris;
} else {
cachedOs = EnumOS.unknown;
}
return cachedOs;
}
}