public void LoadXmlConfig(out StagUser stagUser) { if (CheckConfigIntegrity()) { XmlSerializer cvars = new XmlSerializer(typeof(ConfigVariables)); XmlReader reader = XmlReader.Create(ConfigFileName); // Just whatever the exception is, the xml file is damaged, user will be asked to remove it. try { ConfigVariables = (ConfigVariables)cvars.Deserialize(reader); } catch (Exception e) { MessageBox.Show("Your Config.xml is damaged.\nRemove it."); throw; } stagUser = new StagUser(ConfigVariables.ConfigStagUser.UserName, ConfigVariables.ConfigStagUser.GetPassword(ConfigVariables.ConfigStagUser.HashedPassword), ConfigVariables.ConfigStagUser.OsId); } else { stagUser = null; MessageBox.Show("Your Config.xml is damaged.\nRemove it."); App.Current.Dispatcher.Invoke(() => { Application.Current.Shutdown(); Environment.Exit(0); }); } }
public void CreateAndSaveDefaultXmlConfig(StagUser stagUser, bool append = false) { XmlSerializer x = new XmlSerializer(typeof(ConfigVariables)); TextWriter writer = new StreamWriter(ConfigFileName, false); ConfigVariables = new ConfigVariables(); ConfigVariables.ConfigStagUser = new ConfigStagUser(stagUser.UserName, stagUser.Password, stagUser.StagOsId); x.Serialize(writer, ConfigVariables); writer.Close(); }