|
@@ -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
|
}
|