create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / arch / SystemInfo.java
1 package net.sf.openrocket.arch;
2
3 import java.io.File;
4 import java.util.Locale;
5
6 import net.sf.openrocket.util.BugException;
7
8 public class SystemInfo {
9         
10         
11         /**
12          * Enumeration of supported operating systems.
13          * 
14          * @see <a href="http://lopica.sourceforge.net/os.html">JNLP os and arch Value Collection</a>
15          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
16          */
17         public enum Platform {
18                 WINDOWS,
19                 MAC_OS,
20                 UNIX;
21         }
22         
23         
24         /**
25          * Return the current operating system.
26          * 
27          * @return      the operating system of the current system.
28          */
29         public static Platform getPlatform() {
30                 String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
31                 
32                 if (os.indexOf("win") >= 0) {
33                         return Platform.WINDOWS;
34                 } else if (os.indexOf("mac") >= 0) {
35                         return Platform.MAC_OS;
36                 } else {
37                         /*
38                          * Assume UNIX otherwise, e.g. "Linux", "Solaris", "AIX" etc.
39                          */
40                         return Platform.UNIX;
41                 }
42         }
43         
44         
45         
46         
47         /**
48          * Return the application data directory of this user.  The location depends
49          * on the current platform.
50          * <p>
51          * The directory will not be created by this method.
52          * 
53          * @return      the application directory for OpenRocket
54          */
55         public static File getUserApplicationDirectory() {
56                 final String homeDir = System.getProperty("user.home");
57                 final File dir;
58                 
59                 switch (getPlatform()) {
60                 case WINDOWS:
61                         String appdata = System.getenv("APPDATA");
62                         if (appdata != null) {
63                                 dir = new File(appdata, "OpenRocket/");
64                         } else {
65                                 dir = new File(homeDir, "OpenRocket/");
66                         }
67                         break;
68                 
69                 case MAC_OS:
70                         dir = new File(homeDir, "Library/Application Support/OpenRocket/");
71                         break;
72                 
73                 case UNIX:
74                         dir = new File(homeDir, ".openrocket/");
75                         break;
76                 
77                 default:
78                         throw new BugException("Not implemented for platform " + getPlatform());
79                 }
80                 
81                 return dir;
82         }
83         
84 }