public static void SaveSettings() { Console.Clear(); FileInfo[] settingsFiles = Program.SettingsDirectory.GetFiles("*.json"); if (settingsFiles.Length > 0) { int counterA = 0; foreach (var setting in settingsFiles) { counterA++; Console.WriteLine(counterA + ". Override " + setting.Name); } Console.WriteLine(counterA + 1 + ". New settings"); Console.WriteLine(counterA + 2 + ". Return to main menu"); Console.WriteLine("How do you wish to save your settings? "); if (Int32.TryParse(Console.ReadLine(), out var value)) { if (value == counterA + 1) { Console.WriteLine("Write the name of the new settings"); var name = Console.ReadLine(); JsonObjectFileSaveLoad.WriteToJsonFile(name, Settings.Instance); Console.WriteLine("Successfully saved the settings with name \"" + name + "\""); Console.WriteLine("Press any key to return to main menu"); Console.ReadKey(); } else if (value == counterA + 2) { return; } else { var fileName = Path.GetFileNameWithoutExtension(settingsFiles[value - 1].Name); JsonObjectFileSaveLoad.WriteToJsonFile(fileName, Settings.Instance); Console.WriteLine("Overwritten " + fileName); Console.WriteLine("Press any key to return to main menu"); Console.ReadKey(); } } else { Console.WriteLine("Invalid value"); Console.WriteLine("Press any key to return to main menu"); Console.ReadKey(); } } else { Console.WriteLine("No settings currently exist"); Console.WriteLine("Write the name of the new settings"); var name = Console.ReadLine(); JsonObjectFileSaveLoad.WriteToJsonFile(name, Settings.Instance); Console.WriteLine("Successfully saved the settings with name \"" + name + "\""); Console.WriteLine("Press any key to return to main menu"); Console.ReadKey(); } }
/// <summary> /// Saves the setting file to disk /// </summary> /// <returns></returns> public bool Save() { try { JsonObjectFileSaveLoad.WriteToJsonFile(Path.Combine(Environment.CurrentDirectory, @"AppSettings.json"), this); return(true); } catch (Exception) { return(false); } }
private void buttonSaveData_Click(object sender, EventArgs e) { try { JsonObjectFileSaveLoad.WriteToJsonFile(Path.Combine(AppContext.BaseDirectory, "AllDependencies.json"), mappedAchievements); LogInfo("[+] Saved all dependency data to file"); } catch (Exception ex) { LogInfo("[-] Error while saving data " + ex.GetType().ToString()); } }