comparison mde/resource/paths.d @ 24:32eff0e01c05

Only locally-changed options are stored in user-config now. Log levels revised. Options sub-classes are handled more generically and can be added without changing the Options class. Options changed at run-time are tracked, and on exit merged with user options and saved. Revised log levels as set out in policies.txt and as used in code. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 27 Mar 2008 16:15:21 +0000
parents 56a42ec95024
children 611f7b9063c6
comparison
equal deleted inserted replaced
23:47478557428d 24:32eff0e01c05
47 * Values: HIGH_LOW, LOW_HIGH, HIGH_ONLY. */ 47 * Values: HIGH_LOW, LOW_HIGH, HIGH_ONLY. */
48 enum PRIORITY : byte { HIGH_LOW, LOW_HIGH, HIGH_ONLY } 48 enum PRIORITY : byte { HIGH_LOW, LOW_HIGH, HIGH_ONLY }
49 49
50 /** This struct has one instance for each "directory". 50 /** This struct has one instance for each "directory".
51 * 51 *
52 * It is the only item within this module that you should need to interact with. */ 52 * It is the only item within this module that you should need to interact with.
53 *
54 * In the case of confDir, the user path is guaranteed to exist (as highest priority path). */
53 struct mdeDirectory 55 struct mdeDirectory
54 { 56 {
55 /** Creates an MT reader for each file. 57 /** Creates an MT reader for each file.
56 * 58 *
57 * Params: 59 * Params:
112 try { 114 try {
113 fp.create; 115 fp.create;
114 paths[pathsLen++] = fp.toString~'/'; 116 paths[pathsLen++] = fp.toString~'/';
115 return true; 117 return true;
116 } catch (Exception e) { 118 } catch (Exception e) {
117 logger.warn ("Creating path "~path~" failed:"); 119 logger.error ("Creating path "~path~" failed:");
118 logger.warn (e.msg); 120 logger.error (e.msg);
119 } 121 }
120 } 122 }
121 return false; 123 return false;
122 } 124 }
123 125
140 const DATA = "/data"; 142 const DATA = "/data";
141 const CONF = "/conf"; 143 const CONF = "/conf";
142 144
143 version (linux) { 145 version (linux) {
144 void resolvePaths () { 146 void resolvePaths () {
145 logger.trace ("1");
146 // Home directory: 147 // Home directory:
147 char[] HOME = fromStringz (getenv (toStringz ("HOME"))); 148 char[] HOME = fromStringz (getenv (toStringz ("HOME")));
148 149
149 logger.trace ("3");
150 // Base paths: 150 // Base paths:
151 // Static data (must exist): 151 // Static data (must exist):
152 PathView staticPath = findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data"); 152 PathView staticPath = findPath (false, "/usr/share/games/mde", "/usr/local/share/games/mde", "data");
153 // Config (can just use defaults if necessary, so long as we can save afterwards): 153 // Config (can just use defaults if necessary, so long as we can save afterwards):
154 PathView userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde"); 154 PathView userPath = findPath (true, HOME~"/.config/mde", HOME~"/.mde");
155 155
156 logger.trace ("5");
157 // Static data paths: 156 // Static data paths:
158 dataDir.addPath (staticPath.toString); // we know this is valid anyway 157 dataDir.addPath (staticPath.toString); // we know this is valid anyway
159 dataDir.tryPath (userPath.toString ~ DATA); 158 dataDir.tryPath (userPath.toString ~ DATA);
160 if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!"); 159 if (!dataDir.pathsLen) throw new mdeException ("Fatal: no data path found!");
161 160
162 logger.trace ("7");
163 // Configuration paths: 161 // Configuration paths:
164 confDir.tryPath (staticPath.toString ~ CONF); 162 confDir.tryPath (staticPath.toString ~ CONF);
165 bool sysConf = confDir.tryPath ("/etc/mde"); 163 confDir.tryPath ("/etc/mde");
166 confDir.tryPath (userPath.toString ~ CONF, !sysConf); 164 confDir.tryPath (userPath.toString ~ CONF, true);
167 if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!"); 165 if (!confDir.pathsLen) throw new mdeException ("Fatal: no conf path found!");
168 166
169 logger.trace ("9");
170 // Logging path: 167 // Logging path:
171 logDir = userPath.toString; 168 logDir = userPath.toString;
172 } 169 }
173 } else version (Windows) { 170 } else version (Windows) {
174 void resolvePaths () { 171 void resolvePaths () {