private void SavePresetButton_Click(object sender, EventArgs e) { FilenameTextBox.Text = FilenameTextBox.Text.Replace(".lcpp", ""); if (FilenameTextBox.Text.Length == 0) { Console.WriteLine("File name is empty!\nPlease give a name to the file"); return; } if (PresetsTreeView.SelectedNode?.Tag is FileInfo fi) { if (MessageBox.Show("Will you overwrite the existing file?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { LCPP OutFile = new LCPP() { Name = PresetNameTextBox.Text, Creator = PresetCreatorTextBox.Text }; for (int i = 0; i < Cameras.Count; i++) { OutFile.Add(Cameras[i].Key); } OutFile.Save(fi.FullName, Properties.Settings.Default.IsCompressPresets); Console.WriteLine("Preset Saved!"); } } else if (PresetsTreeView.SelectedNode?.Tag is DirectoryInfo di) { if (di.GetFiles().Any(O => O.Name.Equals(FilenameTextBox.Text + ".lcpp"))) { if (MessageBox.Show("Will you overwrite the existing file?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } LCPP OutFile = new LCPP() { Name = PresetNameTextBox.Text, Creator = PresetCreatorTextBox.Text }; for (int i = 0; i < Cameras.Count; i++) { OutFile.Add(Cameras[i].Key); } OutFile.Save(Path.Combine(di.FullName, FilenameTextBox.Text + ".lcpp"), Properties.Settings.Default.IsCompressPresets); Console.WriteLine("Preset Saved!"); } GenerateTreeview(Program.PresetPath); Program.PresetSelectorNeedsReload = true; }
/// <summary> /// Creates a backup....I can't find where to put this to make it actually helpful... /// </summary> /// <param name="Cameras"><see cref="CameraEditorForm.Cameras"/></param> public static void CreateBackup(BCAM Cameras) { LCPP Backup = new LCPP(); for (int i = 0; i < Cameras.EntryCount; i++) { Backup.Add(Cameras[i]); } Backup.Creator = "LCP Backup Code"; string date = DateTime.Now.ToString("MMMM dd yyyy | h:m:s tt"); Backup.Name = "LCP Backup " + date; Backup.Save(Path.Combine(PresetPath, $"BACKUP-{date}.lcpp"), false); }