Преглед изворни кода

Improved Config handling a bit

git-svn-id: http://svn.dmdirc.com/trunk@33 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith пре 17 година
родитељ
комит
5a8507242e
2 измењених фајлова са 51 додато и 9 уклоњено
  1. 49
    9
      src/dmdirc/Config.java
  2. 2
    0
      src/dmdirc/Main.java

+ 49
- 9
src/dmdirc/Config.java Прегледај датотеку

@@ -4,17 +4,17 @@
4 4
  * Permission is hereby granted, free of charge, to any person obtaining a copy
5 5
  * of this software and associated documentation files (the "Software"), to deal
6 6
  * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 8
  * copies of the Software, and to permit persons to whom the Software is
9 9
  * furnished to do so, subject to the following conditions:
10 10
  *
11
- * The above copyright notice and this permission notice shall be included in 
11
+ * The above copyright notice and this permission notice shall be included in
12 12
  * all copies or substantial portions of the Software.
13 13
  *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 18
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
@@ -22,21 +22,26 @@
22 22
 
23 23
 package dmdirc;
24 24
 
25
+import java.io.File;
26
+import java.util.Properties;
27
+
25 28
 /**
26 29
  * Reads/writes the application's config file
27 30
  * @author chris
28 31
  */
29 32
 public class Config {
30 33
     
34
+    private static Properties properties;
35
+    
31 36
     /** Creates a new instance of Config */
32
-    public Config() {
37
+    private Config() {
33 38
     }
34 39
     
35 40
     /**
36 41
      * Returns the full path to the application's config file
37 42
      * @return config file
38 43
      */
39
-    private static String getConfigFile () {
44
+    private static String getConfigFile() {
40 45
         return getConfigDir()+"dmdirc.xml";
41 46
     }
42 47
     
@@ -44,9 +49,44 @@ public class Config {
44 49
      * Returns the application's config directory
45 50
      * @return configuration directory
46 51
      */
47
-    private static String getConfigDir () {
52
+    private static String getConfigDir() {
48 53
         String fs = System.getProperty("file.seperator");
49 54
         return System.getProperty("user.home")+fs+".DMDirc"+fs;
50 55
     }
51 56
     
57
+    private static Properties getDefaults() {
58
+        Properties defaults = new Properties();
59
+        
60
+        defaults.setProperty("general.commandchar","/");
61
+        defaults.setProperty("ui.maximisewindows","true");
62
+        
63
+        return defaults;
64
+    }
65
+    
66
+    public static boolean hasOption(String domain, String option) {
67
+        assert(properties != null);
68
+        
69
+        return (properties.getProperty(domain+"."+option) != null);
70
+    }
71
+    
72
+    public static String getOption(String domain, String option) {
73
+        assert(properties != null);
74
+        
75
+        return properties.getProperty(domain+"."+option);
76
+    }
77
+    
78
+    /**
79
+     * Loads the config file from disc, if it exists
80
+     */
81
+    public static void initialise() {
82
+        File dir = new File(getConfigFile());
83
+        dir.mkdirs();
84
+        
85
+        properties = new Properties(getDefaults());
86
+        
87
+        if (dir.exists()) {
88
+            // read file
89
+        }
90
+    }
91
+    
52 92
 }

+ 2
- 0
src/dmdirc/Main.java Прегледај датотеку

@@ -56,6 +56,8 @@ public class Main {
56 56
             ex.printStackTrace();
57 57
         }
58 58
         
59
+        Config.initialise();
60
+        
59 61
         MainFrame frame = MainFrame.getMainFrame();
60 62
     }
61 63
     

Loading…
Откажи
Сачувај