All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.electric.util.ClientOS Maven / Gradle / Ivy

The newest version!
package com.sun.electric.util;

public class ClientOS {
	/**
	 * OS is a typesafe enum class that describes the current operating system.
	 */
	public enum OS
	{
		/** Describes Windows. */							WINDOWS("Windows"),
		/** Describes UNIX/Linux. */						UNIX("UNIX"),
		/** Describes Macintosh. */							MACINTOSH("Macintosh");
	
		private String name;
	
		private OS(String name) { this.name = name; }
	
		/**
		 * Returns a printable version of this OS.
		 * @return a printable version of this OS.
		 */
		public String toString() { return name; }
	}
	
	/** The current operating system. */					public static final OS os = OSInitialize();

	// return OS prefix
	public static String getOSPrefix()
	{
		String osPrefix = "";
		if (os == OS.WINDOWS) osPrefix = "Win"; else
			if (os == OS.MACINTOSH) osPrefix = "Mac"; else
				if (os == OS.UNIX) osPrefix = "Linux";
		return osPrefix;
	}
	
	public static String userDir()
	{
		return ClientOS.isOSMac() ? System.getProperty("user.home") : System.getProperty("user.dir");
	}
	
	private static OS OSInitialize()
	{
	    try{
	        String osName = System.getProperty("os.name").toLowerCase();
	        if (osName.startsWith("windows"))
	        {
	            return OS.WINDOWS;
	
	        } else if (osName.startsWith("linux") ||
	                osName.startsWith("solaris") || osName.startsWith("sunos"))
	        {
	            return OS.UNIX;
	        } else if (osName.startsWith("mac"))
	        {
	            return OS.MACINTOSH;
	        }
	    } catch(Exception e)
	    {
	        e.printStackTrace();
	    }
	    System.out.println("No OS detected");
	    return null;
	}

	public static boolean isOSWindows() { return os == OS.WINDOWS; }

	public static boolean isOSMac() { return os == OS.MACINTOSH; }

	public static boolean isOSLinux() { return os == OS.UNIX; }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy