Changeset 412 for branches/eraser6/Eraser/Program.cs
- Timestamp:
- 9/27/2008 9:00:44 AM (5 years ago)
- File:
-
- 1 edited
-
branches/eraser6/Eraser/Program.cs (modified) (3 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 }
Note: See TracChangeset
for help on using the changeset viewer.
