Changeset 412
- Timestamp:
- 9/27/2008 9:00:44 AM (5 years ago)
- Location:
- branches/eraser6
- Files:
-
- 6 edited
-
Eraser/Program.cs (modified) (3 diffs)
-
Eraser/Strings.NL.resx (modified) (1 diff)
-
Eraser/Strings.en.resx (modified) (1 diff)
-
Eraser/Strings.resx (modified) (1 diff)
-
Manager/Method.cs (modified) (1 diff)
-
Manager/Settings.cs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Eraser/Program.cs
r367 r412 99 99 { 100 100 public Settings() 101 { 102 Load(); 103 } 104 105 protected override void Load() 101 106 { 102 107 RegistryKey key = Application.UserAppDataRegistry; … … 140 145 } 141 146 142 //Load the plugin settings. 143 byte[] pluginSettings = (byte[])key.GetValue("PluginSettings", new byte[0]); 144 if (pluginSettings.Length != 0) 145 using (MemoryStream stream = new MemoryStream(pluginSettings)) 146 { 147 try 148 { 149 this.pluginSettings = (Dictionary<Guid, Dictionary<string, object>>) 150 new BinaryFormatter().Deserialize(stream); 151 } 152 catch (Exception) 153 { 154 key.DeleteValue("PluginSettings"); 155 MessageBox.Show(S._("Could not load plugin settings. All settings " + 156 "have been lost."), S._("Eraser"), MessageBoxButtons.OK, 157 MessageBoxIcon.Error); 158 } 159 } 147 base.Load(); 160 148 } 161 149 … … 179 167 using (MemoryStream stream = new MemoryStream()) 180 168 { 181 new BinaryFormatter().Serialize(stream, pluginSettings);182 key.SetValue("PluginSettings", stream.ToArray(), RegistryValueKind.Binary);183 }184 185 using (MemoryStream stream = new MemoryStream())186 {187 169 new BinaryFormatter().Serialize(stream, PlausibleDeniabilityFiles); 188 170 key.SetValue("PlausibleDeniabilityFiles", stream.ToArray(), RegistryValueKind.Binary); 189 171 } 190 172 } 173 174 protected override Dictionary<string, object> GetSettings(Guid guid) 175 { 176 //Open the registry key containing the settings 177 RegistryKey pluginsKey = Application.UserAppDataRegistry.OpenSubKey( 178 "Plugins\\" + guid.ToString(), true); 179 Dictionary<string, object> result = new Dictionary<string, object>(); 180 181 //Load every key/value pair into the dictionary 182 if (pluginsKey != null) 183 foreach (string key in pluginsKey.GetValueNames()) 184 { 185 byte[] currentSetting = (byte[])pluginsKey.GetValue(key, null); 186 if (currentSetting.Length != 0) 187 using (MemoryStream stream = new MemoryStream(currentSetting)) 188 { 189 try 190 { 191 result[key] = new BinaryFormatter().Deserialize(stream); 192 } 193 catch (Exception) 194 { 195 pluginsKey.DeleteValue(key); 196 MessageBox.Show(string.Format(S._("Could not load the setting {0} for plugin {1}." + 197 "The setting has been lost."), key, guid.ToString()), 198 S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error); 199 } 200 } 201 else 202 result[key] = null; 203 } 204 205 //We're done! 206 return result; 207 } 208 209 protected override void SetSettings(Guid guid, Dictionary<string, object> settings) 210 { 211 //Open the registry key containing the settings 212 RegistryKey pluginKey = Application.UserAppDataRegistry.OpenSubKey( 213 "Plugins\\" + guid.ToString(), true); 214 if (pluginKey == null) 215 pluginKey = Application.UserAppDataRegistry.CreateSubKey("Plugins\\" + guid.ToString()); 216 217 foreach (string key in settings.Keys) 218 { 219 using (MemoryStream stream = new MemoryStream()) 220 { 221 new BinaryFormatter().Serialize(stream, settings[key]); 222 pluginKey.SetValue(key, stream.ToArray(), RegistryValueKind.Binary); 223 } 224 } 225 } 191 226 } 192 227 } -
branches/eraser6/Eraser/Strings.NL.resx
r373 r412 136 136 <value>Kan geen taak lijst vinden. Alle taken zijn verdwenen.\n</value> 137 137 </data> 138 <data name="Could not load plugin settings. All settings havebeen lost." xml:space="preserve">139 <value> Kan geen plugin lijst vinden. Alle plugins zijn verdwenen.</value>138 <data name="Could not load the setting {0} for plugin {1}.The setting has been lost." xml:space="preserve"> 139 <value>(Untranslated)</value> 140 140 </data> 141 141 <data name="{0} out of {1}" xml:space="preserve"> -
branches/eraser6/Eraser/Strings.en.resx
r372 r412 136 136 <value>Could not load list of files used for plausible deniability.\n\nThe list of files have been lost.</value> 137 137 </data> 138 <data name="Could not load plugin settings. All settings havebeen lost." xml:space="preserve">139 <value> Could not load plugin settings. All settings have been lost.</value>138 <data name="Could not load the setting {0} for plugin {1}.The setting has been lost." xml:space="preserve"> 139 <value>(Untranslated)</value> 140 140 </data> 141 141 <data name="{0} out of {1}" xml:space="preserve"> -
branches/eraser6/Eraser/Strings.resx
r370 r412 136 136 <value>Could not load list of files used for plausible deniability.\n\nThe list of files have been lost.</value> 137 137 </data> 138 <data name="Could not load plugin settings. All settings havebeen lost." xml:space="preserve">139 <value>Could not load plugin settings. All settings havebeen lost.</value>138 <data name="Could not load the setting {0} for plugin {1}.The setting has been lost." xml:space="preserve"> 139 <value>Could not load the setting {0} for plugin {1}.The setting has been lost.</value> 140 140 </data> 141 141 <data name="{0} out of {1}" xml:space="preserve"> -
branches/eraser6/Manager/Method.cs
r348 r412 217 217 218 218 /// <summary> 219 /// T He default pass function which writes a constant repeatedly to the219 /// The default pass function which writes a constant repeatedly to the 220 220 /// stream. The Pass' OpaqueValue must be set. 221 221 /// </summary> -
branches/eraser6/Manager/Settings.cs
r348 r412 39 39 40 40 /// <summary> 41 /// Loads all settings from storage. 42 /// </summary> 43 /// <remarks>Notes to inheritors: Always call the base class Load.</remarks> 44 protected internal virtual void Load() 45 { 46 if (SettingsChanged != null) 47 SettingsChanged(); 48 } 49 50 /// <summary> 41 51 /// The language which all user interface elements should be presented in. 42 52 /// This is a GUID since languages are supplied through plugins. … … 199 209 lock (this) 200 210 plausibleDeniabilityFiles = value; 201 }202 }203 204 /// <summary>205 /// Retrieves the dictionary holding settings for the given plugin.206 /// </summary>207 /// <param name="plugin">The GUID of the plugin querying for settings</param>208 /// <returns>A dictionary holding settings for the plugin. This dictionary209 /// will be automatically saved when the program exits holding the settings210 /// permanenently. An empty dictionary will be returned if no settings211 /// currently exist.</returns>212 public Dictionary<string, object> GetSettings(Guid plugin)213 {214 lock (pluginSettings)215 {216 if (pluginSettings.ContainsKey(plugin))217 return pluginSettings[plugin];218 219 Dictionary<string, object> result = new Dictionary<string, object>();220 pluginSettings.Add(plugin, result);221 return result;222 211 } 223 212 } … … 237 226 238 227 /// <summary> 228 /// Gets the settings from the data source. 229 /// </summary> 230 /// <param name="guid">The GUID of the calling plugin</param> 231 /// <returns>The dictionary containing settings for the plugin</returns> 232 protected abstract Dictionary<string, object> GetSettings(Guid guid); 233 234 /// <summary> 239 235 /// Sets the settings for the calling plugin. 240 236 /// </summary> … … 242 238 public void SetSettings(Dictionary<string, object> settings) 243 239 { 244 pluginSettings[new Guid(((GuidAttribute)Assembly.GetCallingAssembly(). 245 GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value)] 246 = settings; 247 } 240 SetSettings(new Guid(((GuidAttribute)Assembly.GetCallingAssembly(). 241 GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value), settings); 242 SettingsChanged(); 243 } 244 245 /// <summary> 246 /// Saves the settings from the plugin into the data source. 247 /// </summary> 248 /// <param name="guid"></param> 249 /// <param name="settings"></param> 250 protected abstract void SetSettings(Guid guid, Dictionary<string, object> settings); 251 252 /// <summary> 253 /// The prototype of functions which will handle a SettingsChanged Event. 254 /// </summary> 255 public delegate void OnSettingsChangedEvent(); 256 257 /// <summary> 258 /// The event handler handling a change in settings. 259 /// </summary> 260 public event OnSettingsChangedEvent SettingsChanged; 248 261 249 262 private string uiLanguage; … … 256 269 private bool plausibleDeniability = true; 257 270 private List<string> plausibleDeniabilityFiles = new List<string>(); 258 259 protected Dictionary<Guid, Dictionary<string, object>> pluginSettings =260 new Dictionary<Guid, Dictionary<string, object>>();261 271 } 262 272 }
Note: See TracChangeset
for help on using the changeset viewer.
