private void BtnSave_Click(object sender, RoutedEventArgs e) { ConfigReader.Configuration.ArduinoPath = FfsArduino.SelectedPath; ConfigReader.Configuration.EaglePath = FfsEagle.SelectedPath; ConfigReader.Configuration.LibreOfficePath = FfsLibreOffice.SelectedPath; ConfigReader.Configuration.LtSpicePath = FfsLtSpice.SelectedPath; ConfigReader.Configuration.ProcessingPath = FfsProcessing.SelectedPath; if (!Folders.IsDirectoryWritable(Folders.Application)) { var response = MessageBox.Show("Application folder is not writeable.\r\nWould you like to save the config to another location?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (response == MessageBoxResult.Yes) { System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog(); sfd.Filter = "Launcher config|launcher.xml"; sfd.FileName = "launcher.xml"; if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { LauncherConfig.Save(ConfigReader.Configuration, sfd.FileName); MessageBox.Show("Configuration saved. Copy it to the application folder to aply changes.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } } else { LauncherConfig.Save(ConfigReader.Configuration, Path.Combine(Folders.Application, "launchers.xml")); MessageBox.Show("Configuration saved.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } }
static ConfigReader() { if (Configuration == null) { if (File.Exists(Path.Combine(Folders.Application, "launchers.xml"))) { Configuration = LauncherConfig.Load(Path.Combine(Folders.Application, "launchers.xml")); } else { Configuration = new LauncherConfig(); } } }
public static void Save(LauncherConfig cf, string path) { try { XmlSerializer xs = new XmlSerializer(typeof(LauncherConfig)); using (var file = File.Create(path)) { xs.Serialize(file, cf); } } catch (Exception ex) { WpfHelpers.ExceptionDialog(ex); } }