public static void SaveConfig(Dictionary <string, Config> configs) { if (configs == null) { throw new ArgumentNullException("configs"); } if (!Directory.Exists(Model.SETTINGS_PATH)) { Directory.CreateDirectory(Model.SETTINGS_PATH); } using (MemoryStream ms = new MemoryStream()) { BIN_FORMATTER.Serialize(ms, configs); byte[] data = RijndaelSample.Encrypt(ms.ToArray()); File.WriteAllBytes(CONFIG_FULL_FILE_NAME, data); } }
public static Dictionary <string, Config> LoadConfig() { if (!File.Exists(CONFIG_FULL_FILE_NAME)) { return(new Dictionary <string, Config>()); } Dictionary <string, Config> configs; try { byte[] data = File.ReadAllBytes(CONFIG_FULL_FILE_NAME); using (MemoryStream ms = new MemoryStream(RijndaelSample.Decrypt(data))) { configs = (Dictionary <string, Config>)BIN_FORMATTER.Deserialize(ms); } } catch (Exception e) { throw new FileLoadException(@"Can't read config file", e); } return(configs); }