void SaveAs() { PromptDialog diag = new PromptDialog(); diag.Title = "Engineering Preset"; diag.Label = "Provide a name for this preset:"; if (diag.ShowDialog() == true) { string f = null; if (diag.Text.EndsWith(".dat", StringComparison.OrdinalIgnoreCase)) { f = diag.Text; } else { f = diag.Text + ".dat"; } if (IsAlreadyInLibrary(f)) { if (Locations.MessageBoxShow("File is already in library.\r\n\r\nOverwrite?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } } else { string file = System.IO.Path.Combine(LibraryPath, f); EngineeringHelper.WritePresetFile(file, PresetItems); CurrentFile = f; Library.Add(f); } } }
void LoadLibrary() { FileHelper.CreatePath(LibraryPath); List <string> files = new List <string>(); foreach (FileInfo f in new DirectoryInfo(LibraryPath).GetFiles()) { files.Add(f.Name); } if (files.Count == 0) { try { IList <Preset> collection = EngineeringHelper.LoadPresetFile(ArtemisTarget); EngineeringHelper.WritePresetFile(System.IO.Path.Combine(LibraryPath, "Artemis.dat"), collection); files.Add("Artemis.dat"); } catch (InvalidPresetFileException) { //Can be ignored--handling this issue is already part of elsewhere. } } Library = new ObservableCollection <string>(files); }
void Import() { OpenFileDialog diag = new OpenFileDialog(); diag.Filter = "Data files (*.dat)|*.dat|All Files (*.*)|*.*"; diag.DefaultExt = ".dat"; diag.Title = "Select file to import"; if (diag.ShowDialog() == true) { try { PresetItems = new ObservableCollection <Preset>(EngineeringHelper.LoadPresetFile(diag.FileName)); } catch (InvalidPresetFileException) { Locations.MessageBoxShow("Engineering preset file is invalid. Cannot import.", MessageBoxButton.OK, MessageBoxImage.Hand); } string file = new FileInfo(diag.FileName).Name; if (IsAlreadyInLibrary(file)) { PromptDialog diagP = new PromptDialog(); diagP.Title = "Engineering Preset"; diagP.Label = "The name already exists. Provide a new name for the imported preset:"; if (diagP.ShowDialog() == true) { string f = null; if (diagP.Text.EndsWith(".dat", StringComparison.OrdinalIgnoreCase)) { file = diagP.Text; } else { file = diagP.Text + ".dat"; } if (IsAlreadyInLibrary(f)) { if (Locations.MessageBoxShow("File is already in library.\r\n\r\nOverwrite?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } } f = System.IO.Path.Combine(LibraryPath, file); EngineeringHelper.WritePresetFile(f, PresetItems); } else { CurrentFile = null; return; } } Library.Add(file); CurrentFile = file; } }
private void Save_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(CurrentFile)) { SaveAs(); } else { string file = System.IO.Path.Combine(LibraryPath, CurrentFile); EngineeringHelper.WritePresetFile(file, PresetItems); } }
void Export() { SaveFileDialog diag = new SaveFileDialog(); diag.Filter = "Data files (*.dat)|*.dat|All Files (*.*)|*.*"; diag.DefaultExt = ".dat"; diag.Title = "Select file to export to"; if (diag.ShowDialog() == true) { EngineeringHelper.WritePresetFile(diag.FileName, PresetItems); } }
private void MakeActive_Click(object sender, RoutedEventArgs e) { EngineeringHelper.WritePresetFile(ArtemisTarget, PresetItems); }