public void ImportSettings() { try { if(File.Exists(@ImportExportFile)) { MemoryStream stream = new MemoryStream(); using(FileStream file = File.OpenRead(@ImportExportFile)) { Decompress(file, stream); } stream.Position = 0; Serializer.PrepareSerializer<MasterSettings>(); sMasterSettings = Serializer.Deserialize<MasterSettings>(stream); // XmlSerializer XSerializer = new XmlSerializer(typeof(MasterSettings)); // sMasterSettings = (MasterSettings)XSerializer.Deserialize(stream); OperationsLog("Imported settings file from transfer file."); SaveMasterSettingsFile(); tGeneralSettings = Serializer.DeepClone(sMasterSettings.GeneralSettings); tSearchListHolder = Serializer.DeepClone(sMasterSettings.SearchListHolder); InventoryAccess.Stage(); } else { OperationsLog("No transfer settings file exists."); } }catch(Exception ex){LogError(ex);} }
public void ReadMasterSettingsFile() { try { if(File.Exists(MasterSettingsFile)) { OperationsLog("Found Master Settings File."); try { using (FileStream file = File.OpenRead(MasterSettingsFile)) { Serializer.PrepareSerializer<MasterSettings>(); sMasterSettings = Serializer.Deserialize<MasterSettings>(file); } }catch(Exception ex){LogError(ex);} } else if(File.Exists(BackupMasterSettingsFile)) { try { OperationsLog("Restored Settings File From Backup."); using (FileStream file = File.OpenRead(BackupMasterSettingsFile)) { Serializer.PrepareSerializer<MasterSettings>(); sMasterSettings = Serializer.Deserialize<MasterSettings>(file); } }catch(Exception ex){LogError(ex);} } else { OperationsLog("Created New Settings File."); sMasterSettings = new MasterSettings(); FillMasterSettingsFile(); SaveMasterSettingsFile(); } } catch(Exception ex){LogError(ex);} { if(File.Exists(BackupMasterSettingsFile)) { using (FileStream file = File.OpenRead(BackupMasterSettingsFile)) { Serializer.PrepareSerializer<MasterSettings>(); sMasterSettings = Serializer.Deserialize<MasterSettings>(file); } } else { sMasterSettings = new MasterSettings(); FillMasterSettingsFile(); SaveMasterSettingsFile(); } } try { using (Stream stream = new MemoryStream()) { Serializer.PrepareSerializer<MasterSettings>(); Serializer.Serialize(stream, sMasterSettings); OperationsLog("Master settings protosize = " + stream.Length); } OperationsLog("GearLocker Version: " + typeof(NotificationIcon).Assembly.GetName().Version.ToString()); tGeneralSettings = Serializer.DeepClone(sMasterSettings.GeneralSettings); tSearchListHolder = Serializer.DeepClone(sMasterSettings.SearchListHolder); }catch(Exception ex){LogError(ex);} }