Ignore:
Timestamp:
11/14/2008 8:20:48 AM (4 years ago)
Author:
lowjoel
Message:

Part one to fixing #32: replace the Dictionary object with the Settings object for plugin settings; The old Settings class is now the SettingsManager? class.
Also, since we are now using a generic Object, I've implemented a few helper class (XXSettings) classes to allow for the concrete setting + type to be retrieved.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Manager/Settings.cs

    r429 r561  
    2828namespace Eraser.Manager 
    2929{ 
     30    public abstract class SettingsManager 
     31    { 
     32        /// <summary> 
     33        /// Saves all the settings to persistent storage. 
     34        /// </summary> 
     35        public abstract void Save(); 
     36 
     37        /// <summary> 
     38        /// Gets the dictionary holding settings for the calling assembly. 
     39        /// </summary> 
     40        public Settings ModuleSettings 
     41        { 
     42            get 
     43            { 
     44                return GetSettings(new Guid(((GuidAttribute)Assembly.GetCallingAssembly(). 
     45                    GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value)); 
     46            } 
     47        } 
     48 
     49        /// <summary> 
     50        /// Gets the settings from the data source. 
     51        /// </summary> 
     52        /// <param name="guid">The GUID of the calling plugin</param> 
     53        /// <returns>The Settings object which will act as the data store.</returns> 
     54        protected abstract Settings GetSettings(Guid guid); 
     55    } 
     56 
    3057    /// <summary> 
    31     /// Settings class. Holds the defaults for the manager's operations. 
     58    /// Settings class. Represents settings to a given client. 
    3259    /// </summary> 
    3360    public abstract class Settings 
    3461    { 
    3562        /// <summary> 
    36         /// Saves all the settings to any persistent storage. 
    37         /// </summary> 
    38         protected internal abstract void Save(); 
    39  
    40         /// <summary> 
    41         /// Loads all settings from storage. 
    42         /// </summary> 
    43         protected internal abstract void Load(); 
     63        /// Gets the setting 
     64        /// </summary> 
     65        /// <param name="setting">The name of the setting.</param> 
     66        /// <returns>The object stored in the settings database, or null if undefined.</returns> 
     67        public abstract object this[string setting] 
     68        { 
     69            get; 
     70            set; 
     71        } 
    4472 
    4573        /// <summary> 
     
    5987                    uiLanguage = value; 
    6088            } 
     89        } 
     90 
     91        private string uiLanguage; 
     92    } 
     93 
     94    /// <summary> 
     95    /// Handles the settings related to the Eraser Manager. 
     96    /// </summary> 
     97    public class ManagerSettings 
     98    { 
     99        /// <summary> 
     100        /// Constructor. 
     101        /// </summary> 
     102        /// <param name="settings">The Settings object which is the data store for 
     103        /// this object.</param> 
     104        public ManagerSettings() 
     105        { 
     106            settings = ManagerLibrary.Instance.SettingsManager.ModuleSettings; 
    61107        } 
    62108 
     
    70116            get 
    71117            { 
    72                 lock (this) 
    73                     return defaultFileErasureMethod; 
    74             } 
    75             set 
    76             { 
    77                 lock (this) 
    78                     defaultFileErasureMethod = value; 
     118                return settings["DefaultFileErasureMethod"] == null ? Guid.Empty : 
     119                    (Guid)settings["DefaultFileErasureMethod"]; 
     120            } 
     121            set 
     122            { 
     123                settings["DefaultFileErasureMethod"] = value; 
    79124            } 
    80125        } 
     
    89134            get 
    90135            { 
    91                 lock (this) 
    92                     return defaultUnusedSpaceErasureMethod; 
    93             } 
    94             set 
    95             { 
    96                 lock (this) 
    97                     defaultUnusedSpaceErasureMethod = value; 
     136                return settings["DefaultUnusedSpaceErasureMethod"] == null ? Guid.Empty : 
     137                    (Guid)settings["DefaultUnusedSpaceErasureMethod"]; 
     138            } 
     139            set 
     140            { 
     141                settings["DefaultUnusedSpaceErasureMethod"] = value; 
    98142            } 
    99143        } 
     
    107151            get 
    108152            { 
    109                 lock (this) 
    110                     return activePRNG; 
    111             } 
    112             set 
    113             { 
    114                 lock (this) 
    115                     activePRNG = value; 
     153                return settings["ActivePRNG"] == null ? Guid.Empty : 
     154                    (Guid)settings["ActivePRNG"]; 
     155            } 
     156            set 
     157            { 
     158                settings["ActivePRNG"] = value; 
    116159            } 
    117160        } 
     
    125168            get 
    126169            { 
    127                 lock (this) 
    128                     return eraseLockedFilesOnRestart; 
    129             } 
    130             set 
    131             { 
    132                 lock (this) 
    133                     eraseLockedFilesOnRestart = value; 
     170                return settings["EraseLockedFilesOnRestart"] == null ? true : 
     171                    (bool)settings["EraseLockedFilesOnRestart"]; 
     172            } 
     173            set 
     174            { 
     175                settings["EraseLockedFilesOnRestart"] = value; 
    134176            } 
    135177        } 
     
    143185            get 
    144186            { 
    145                 lock (this) 
    146                     return confirmEraseOnRestart; 
    147             } 
    148             set 
    149             { 
    150                 lock (this) 
    151                     confirmEraseOnRestart = value; 
     187                return settings["ConfirmEraseOnRestart"] == null ? 
     188                    true : (bool)settings["ConfirmEraseOnRestart"]; 
     189            } 
     190            set 
     191            { 
     192                settings["ConfirmEraseOnRestart"] = value; 
    152193            } 
    153194        } 
     
    160201            get 
    161202            { 
    162                 lock (this) 
    163                     return executeMissedTasksImmediately; 
    164             } 
    165             set 
    166             { 
    167                 lock (this) 
    168                     executeMissedTasksImmediately = value; 
     203                return settings["ExecuteMissedTasksImmediately"] == null ? 
     204                    true : (bool)settings["ExecuteMissedTasksImmediately"]; 
     205            } 
     206            set 
     207            { 
     208                settings["ExecuteMissedTasksImmediately"] = value; 
    169209            } 
    170210        } 
     
    180220            get 
    181221            { 
    182                 lock (this) 
    183                     return plausibleDeniability; 
    184             } 
    185             set 
    186             { 
    187                 lock (this) 
    188                     plausibleDeniability = value; 
     222                return settings["PlausibleDeniability"] == null ? false : 
     223                    (bool)settings["PlausibleDeniability"]; 
     224            } 
     225            set 
     226            { 
     227                settings["PlausibleDeniability"] = value; 
    189228            } 
    190229        } 
     
    197236            get 
    198237            { 
    199                 lock (this) 
    200                     return plausibleDeniabilityFiles; 
    201             } 
    202             set 
    203             { 
    204                 lock (this) 
    205                     plausibleDeniabilityFiles = value; 
    206             } 
    207         } 
    208  
    209         /// <summary> 
    210         /// Gets the dictionary holding settings for the calling assembly. 
    211         /// </summary> 
    212         public Dictionary<string, object> PluginSettings 
    213         { 
    214             get 
    215             { 
    216                 return GetSettings(new Guid(((GuidAttribute)Assembly.GetCallingAssembly(). 
    217                     GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value)); 
    218             } 
    219         } 
    220  
    221         /// <summary> 
    222         /// Gets the settings from the data source. 
    223         /// </summary> 
    224         /// <param name="guid">The GUID of the calling plugin</param> 
    225         /// <returns>The dictionary containing settings for the plugin</returns> 
    226         protected abstract Dictionary<string, object> GetSettings(Guid guid); 
    227  
    228         /// <summary> 
    229         /// Sets the settings for the calling plugin. 
    230         /// </summary> 
    231         /// <param name="settings">The settings of the plugin</param> 
    232         public void SetSettings(Dictionary<string, object> settings) 
    233         { 
    234             SetSettings(new Guid(((GuidAttribute)Assembly.GetCallingAssembly(). 
    235                 GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value), settings); 
    236         } 
    237  
    238         /// <summary> 
    239         /// Saves the settings from the plugin into the data source. 
    240         /// </summary> 
    241         /// <param name="guid"></param> 
    242         /// <param name="settings"></param> 
    243         protected abstract void SetSettings(Guid guid, Dictionary<string, object> settings); 
    244  
    245         private string uiLanguage; 
    246         private Guid defaultFileErasureMethod = Guid.Empty; 
    247         private Guid defaultUnusedSpaceErasureMethod = Guid.Empty; 
    248         private Guid activePRNG = Guid.Empty; 
    249         private bool eraseLockedFilesOnRestart = true; 
    250         private bool confirmEraseOnRestart = true; 
    251         private bool executeMissedTasksImmediately = true; 
    252         private bool plausibleDeniability = true; 
    253         private List<string> plausibleDeniabilityFiles = new List<string>(); 
     238                return settings["PlausibleDeniabilityFiles"] == null ? 
     239                    new List<string>() : 
     240                    (List<string>)settings["PlausibleDeniabilityFiles"]; 
     241            } 
     242            set 
     243            { 
     244                settings["PlausibleDeniabilityFiles"] = value; 
     245            } 
     246        } 
     247 
     248        /// <summary> 
     249        /// The Settings object which is the data store of this object. 
     250        /// </summary> 
     251        private Settings settings; 
    254252    } 
    255253} 
Note: See TracChangeset for help on using the changeset viewer.