checks for last update
[jalview.git] / src / jalview / bin / Cache.java
1 /********************\r
2  * 2004 Jalview Reengineered\r
3  * Barton Group\r
4  * Dundee University\r
5  *\r
6  * AM Waterhouse\r
7  *******************/\r
8 \r
9 \r
10 package jalview.bin;\r
11 import java.util.*;\r
12 import java.io.*;\r
13 \r
14 import java.util.jar.*;\r
15 public class Cache\r
16 {\r
17   public static String  VERSION = "ß test";\r
18   public static String  BUILD_DATE = "1-1-2005";\r
19 \r
20   public static Properties applicationProperties;\r
21   // Current properties include:\r
22   //\r
23   // LAST_DIRECTORY   , use this to cache record of where the user looked to find a file\r
24   // UNIPROT_CACHE\r
25   // USER_DEFINED_COLOUR - file describing last user set colours\r
26   // FONT_NAME\r
27   // FONT_STYLE\r
28   // FONT_SIZE\r
29 \r
30 \r
31   public static void loadProperties()\r
32   {\r
33     // get last build time.\r
34     try{\r
35           long date = 0;\r
36 \r
37           String localFile = Cache.class.getProtectionDomain().getCodeSource().getLocation().toString();\r
38           localFile = localFile.concat("!/");\r
39           String tmpString = "jar:";\r
40           String localJarFileString = tmpString.concat(localFile);\r
41           java.net.URL localJarFileURL = new java.net.URL(localJarFileString);\r
42           java.net.JarURLConnection localJarFile = (java.net.JarURLConnection)localJarFileURL.openConnection();\r
43 \r
44           date = localJarFile.getLastModified();\r
45 \r
46           if(date==0)\r
47           {\r
48             // this is called for unpackaged class files.\r
49             // not entirely accurate as it only tells you when Cache.class was last compiled\r
50             java.net.URL url = Cache.class.getResource("/jalview/bin/Cache.class");\r
51             java.io.File f = new java.io.File(url.getFile());\r
52             date = f.lastModified();\r
53           }\r
54 \r
55           BUILD_DATE = new Date( date ).toString();\r
56 \r
57 \r
58     }catch(Exception ex){ex.printStackTrace();}\r
59 \r
60 \r
61     applicationProperties = new Properties();\r
62 \r
63     try\r
64     {\r
65       FileInputStream in = new FileInputStream(System.getProperty("user.home") +\r
66                                                "/.jalview_properties");\r
67       applicationProperties = new Properties();\r
68       applicationProperties.load(in);\r
69       in.close();\r
70     }\r
71     catch (Exception ex)\r
72     { }\r
73   }\r
74 \r
75   public static String getProperty(String key)\r
76   {\r
77     return  applicationProperties.getProperty(key);\r
78   }\r
79 \r
80   public static String setProperty(String key, String obj)\r
81   {\r
82     try\r
83     {\r
84       FileOutputStream out = new FileOutputStream(System.getProperty(\r
85           "user.home") + "/.jalview_properties");\r
86 \r
87       applicationProperties.setProperty(key, obj);\r
88 \r
89       applicationProperties.store(out, "---JalviewX Properties File---");\r
90       out.close();\r
91     }\r
92     catch (Exception ex)\r
93     {}\r
94 \r
95     return obj;\r
96 \r
97   }\r
98 \r
99 \r
100 \r
101 \r
102 \r
103 }\r