comparison mde/lookup/Options.d @ 86:79d816b3e2d2

New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries. This (and the previous) commit are the result of several quite significant changes to mde. All the unittests run, but it hasn't had a huge amount of testing so don't be surprised if bugs show up.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 12 Sep 2008 17:36:14 +0100
parents 56c0ddd90193
children 97e6dce08037
comparison
equal deleted inserted replaced
85:56c0ddd90193 86:79d816b3e2d2
134 void addOptionsClass (Options c, char[] i) 134 void addOptionsClass (Options c, char[] i)
135 in { // Trap a couple of potential coding errors: 135 in { // Trap a couple of potential coding errors:
136 assert (c !is null); // Instance must be created before calling addOptionsClass 136 assert (c !is null); // Instance must be created before calling addOptionsClass
137 assert (((cast(ID) i) in subClasses) is null); // Don't allow a silent replacement 137 assert (((cast(ID) i) in subClasses) is null); // Don't allow a silent replacement
138 } body { 138 } body {
139 debug logger.trace ("Adding Options subClass: "~i);
140 subClasses[cast(ID) i] = c; 139 subClasses[cast(ID) i] = c;
141 } 140 }
142 141
143 // Track all sections for saving/loading/other generic handling. 142 // Track all sections for saving/loading/other generic handling.
144 Options[ID] subClasses; 143 Options[ID] subClasses;
167 logger.warn ("If warning persists, delete the offending file."); // FIXME - delete the bad file somehow 166 logger.warn ("If warning persists, delete the offending file."); // FIXME - delete the bad file somehow
168 } 167 }
169 } 168 }
170 void save () { 169 void save () {
171 if (!changed) return; // no changes to save 170 if (!changed) return; // no changes to save
172 // Types: 171 debug logger.trace ("Saving options...");
173 // interface IDataSection {...} 172
174 // class Options {...}
175 // alias char[] ID;
176 // IDataSection[ID] ds.sec;
177 // Options[ID] subClasses;
178 DataSet ds = new DataSet(); 173 DataSet ds = new DataSet();
179 foreach (id, subOpts; subClasses) { 174 foreach (id, subOpts; subClasses)
180 ds.sec[id] = subOpts.optionChanges; 175 ds.sec[id] = subOpts.optionChanges;
181 debug logger.trace ("Saving options section: "~id);
182 }
183 foreach (i,s; ds.sec)
184 debug logger.trace ("sec ID length: {}", i.length);
185 debug logger.trace ("0");
186 176
187 // Read locally-stored options 177 // Read locally-stored options
188 try { 178 try {
189 IReader reader; 179 IReader reader;
190 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds); 180 reader = confDir.makeMTReader (fileName, PRIORITY.HIGH_ONLY, ds);
191 reader.dataSecCreator = delegate IDataSection(ID id) { 181 reader.dataSecCreator = delegate IDataSection(ID id) {
192 debug logger.trace ("New section to save ignored: "~id); 182 debug logger.warn ("New section appearing in options.mtt during save (ignored & overwritten): "~id);
193 return null; // All recognised sections are already in the dataset. 183 return null; // All recognised sections are already in the dataset.
194 }; 184 };
195 reader.read; 185 reader.read;
196 } catch (NoFileException) { 186 } catch (NoFileException) {
197 // No user file exists; not an error. 187 // No user file exists; not an error.
199 // Log a message and continue, overwriting the file: 189 // Log a message and continue, overwriting the file:
200 logger.error ("Loading options aborted: " ~ e.msg); 190 logger.error ("Loading options aborted: " ~ e.msg);
201 } 191 }
202 192
203 try { 193 try {
204 debug logger.trace ("1");
205 IWriter writer; 194 IWriter writer;
206 foreach (i,s; ds.sec) 195 writer = confDir.makeMTWriter (fileName, ds);
207 debug logger.trace ("sec ID length: {}", i.length); 196 writer.write();
208 debug logger.trace ("2");
209 writer = confDir.makeMTWriter (fileName, ds); // FIXME - sometimes SIGSEGV
210 debug logger.trace ("3");
211 writer.write(); // FIXME - this is causing hang at exit!
212 debug logger.trace ("4");
213 } catch (Exception e) { 197 } catch (Exception e) {
214 logger.error ("Saving options aborted: "~e.msg); 198 logger.error ("Saving options aborted: "~e.msg);
215 } 199 }
216 } 200 }
217 201