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