コード例 #1
0
        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);
            }
        }
コード例 #2
0
 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();
         }
     }
 }
コード例 #3
0
 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);
     }
 }