Changeset 1984
- Timestamp:
- 4/28/2010 8:59:54 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/eraser/Eraser.Manager/Settings.cs (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Manager/Settings.cs
r1802 r1984 63 63 { 64 64 /// <summary> 65 /// Gets the setting 65 /// Gets the setting for the given name, coercing the object stored in the backend 66 /// to the given type <typeparamref name="T"/>. 67 /// </summary> 68 /// <typeparam name="T">The type of the setting that is currently stored in the 69 /// backend.</typeparam> 70 /// <param name="name">The name of the setting that is used to uniquely refer 71 /// to the value.</param> 72 /// <param name="defaultValue">The default to return if the no data is assocated 73 /// with the given setting.</param> 74 /// <returns>The value stored in the backend, or null if none exists.</returns> 75 public abstract T GetValue<T>(string name, T defaultValue); 76 77 /// <summary> 78 /// Overload for <see cref="GetValue"/> which returns a default for the given type. 79 /// </summary> 80 /// <typeparam name="T">The type of the setting that is currently stored in the 81 /// backend.</typeparam> 82 /// <param name="name">The name of the setting that is used to uniquely refer 83 /// to the value.</param> 84 /// <param name="defaultValue">The default to return if the no data is assocated 85 /// with the given setting.</param> 86 /// <returns>The value stored in the backend, or null if none exists.</returns> 87 public T GetValue<T>(string name) 88 { 89 return GetValue<T>(name, default(T)); 90 } 91 92 /// <summary> 93 /// Sets the setting with the given name. 94 /// </summary> 95 /// <param name="name">The name of the setting.</param> 96 /// <param name="value">The value to store in the backend. This may be serialised.</param> 97 public abstract void SetValue(string name, object value); 98 99 /// <summary> 100 /// Gets or sets the given setting, without type hinting. This will not attempt to coerce 101 /// a type from an old version of the assembly to its current type. 66 102 /// </summary> 67 103 /// <param name="setting">The name of the setting.</param> 68 104 /// <returns>The object stored in the settings database, or null if undefined.</returns> 69 public abstract object this[string setting] 70 { 71 get; 72 set; 105 [Obsolete("Use the GetValue<T> and SetValue functions instead")] 106 public object this[string setting] 107 { 108 get 109 { 110 return GetValue<object>(setting); 111 } 112 set 113 { 114 SetValue(setting, value); 115 } 73 116 } 74 117 } … … 191 234 //and use the method which was declared by us to be the highest 192 235 //priority default 193 if (settings["DefaultFileErasureMethod"] == null)194 {195 Guidresult = FindHighestPriorityDefault(typeof(ErasureMethod),236 Guid result = settings.GetValue<Guid>("DefaultFileErasureMethod"); 237 if (result == Guid.Empty) 238 result = FindHighestPriorityDefault(typeof(ErasureMethod), 196 239 typeof(DefaultFileErasureAttribute)); 197 return result == Guid.Empty ? new Guid("{1407FC4E-FEFF-4375-B4FB-D7EFBB7E9922}") : 198 result; 199 } 200 else 201 return (Guid)settings["DefaultFileErasureMethod"]; 240 if (result == Guid.Empty) 241 result = new Guid("{1407FC4E-FEFF-4375-B4FB-D7EFBB7E9922}"); 242 243 return result; 202 244 } 203 245 set 204 246 { 205 settings ["DefaultFileErasureMethod"] = value;247 settings.SetValue("DefaultFileErasureMethod", value); 206 248 } 207 249 } … … 216 258 get 217 259 { 218 if (settings["DefaultUnusedSpaceErasureMethod"] == null)219 {220 Guidresult = FindHighestPriorityDefault(typeof(UnusedSpaceErasureMethod),260 Guid result = settings.GetValue<Guid>("DefaultUnusedSpaceErasureMethod"); 261 if (result == Guid.Empty) 262 result = FindHighestPriorityDefault(typeof(UnusedSpaceErasureMethod), 221 263 typeof(DefaultUnusedSpaceErasureAttribute)); 222 return result == Guid.Empty ? new Guid("{BF8BA267-231A-4085-9BF9-204DE65A6641}") : 223 result; 224 } 225 else 226 return (Guid)settings["DefaultUnusedSpaceErasureMethod"]; 264 if (result == Guid.Empty) 265 result = new Guid("{BF8BA267-231A-4085-9BF9-204DE65A6641}"); 266 return result; 227 267 } 228 268 set 229 269 { 230 settings ["DefaultUnusedSpaceErasureMethod"] = value;270 settings.SetValue("DefaultUnusedSpaceErasureMethod", value); 231 271 } 232 272 } … … 240 280 get 241 281 { 242 if (settings["ActivePRNG"] == null) 243 { 244 Guid result = FindHighestPriorityDefault(typeof(Prng), 245 typeof(DefaultPrngAttribute)); 246 return result == Guid.Empty ? new Guid("{6BF35B8E-F37F-476e-B6B2-9994A92C3B0C}") : 247 result; 248 } 249 else 250 return (Guid)settings["ActivePRNG"]; 282 Guid result = settings.GetValue<Guid>("ActivePRNG"); 283 if (result == Guid.Empty) 284 result = FindHighestPriorityDefault(typeof(Prng), typeof(DefaultPrngAttribute)); 285 if (result == Guid.Empty) 286 result = new Guid("{6BF35B8E-F37F-476e-B6B2-9994A92C3B0C}"); 287 return result; 251 288 } 252 289 set 253 290 { 254 settings ["ActivePRNG"] = value;291 settings.SetValue("ActivePRNG", value); 255 292 } 256 293 } … … 264 301 get 265 302 { 266 return settings["ForceUnlockLockedFiles"] == null ? true : 267 Convert.ToBoolean(settings["ForceUnlockLockedFiles"], 268 CultureInfo.InvariantCulture); 303 return settings.GetValue("ForceUnlockLockedFiles", true); 269 304 } 270 305 set 271 306 { 272 settings ["ForceUnlockLockedFiles"] = value;307 settings.SetValue("ForceUnlockLockedFiles", value); 273 308 } 274 309 } … … 281 316 get 282 317 { 283 return settings["ExecuteMissedTasksImmediately"] == null ? 284 true : Convert.ToBoolean(settings["ExecuteMissedTasksImmediately"], 285 CultureInfo.InvariantCulture); 318 return settings.GetValue("ExecuteMissedTasksImmediately", true); 286 319 } 287 320 set 288 321 { 289 settings ["ExecuteMissedTasksImmediately"] = value;322 settings.SetValue("ExecuteMissedTasksImmediately", value); 290 323 } 291 324 } … … 301 334 get 302 335 { 303 return settings["PlausibleDeniability"] == null ? false : 304 Convert.ToBoolean(settings["PlausibleDeniability"], 305 CultureInfo.InvariantCulture); 336 return settings.GetValue("PlausibleDeniability", false); 306 337 } 307 338 set 308 339 { 309 settings ["PlausibleDeniability"] = value;340 settings.SetValue("PlausibleDeniability", value); 310 341 } 311 342 } … … 464 495 Settings = settings; 465 496 SettingName = settingName; 466 List = (List<T>)settings[settingName];497 List = settings.GetValue<List<T>>(settingName); 467 498 if (List == null) 468 499 List = new List<T>(); … … 574 605 private void Save() 575 606 { 576 Settings [SettingName] = List;607 Settings.SetValue(SettingName, List); 577 608 } 578 609 … … 604 635 Settings = settings; 605 636 SettingName = settingName; 606 Dictionary = (Dictionary<TKey, TValue>)settings[settingName];637 Dictionary = settings.GetValue<Dictionary<TKey, TValue>>(settingName); 607 638 if (Dictionary == null) 608 639 Dictionary = new Dictionary<TKey, TValue>(); … … 735 766 private void Save() 736 767 { 737 Settings [SettingName] = Dictionary;768 Settings.SetValue(SettingName, Dictionary); 738 769 } 739 770
Note: See TracChangeset
for help on using the changeset viewer.
