public static void addSaveFile() { try { Console.WriteLine("\nWelcome, please create a save file."); Console.Write("\nPlease choose your name: "); string SFname = Console.ReadLine(); StreamWriter sw = new StreamWriter($"{AppDomain.CurrentDomain.BaseDirectory}characters\\{SFname}.json"); Console.Write("Please chose your password: "******"\nSave File Loaded:"); Console.WriteLine("Name: " + objcharacter.Name); Console.WriteLine("Level: " + objcharacter.Level); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
public static void loadSaveFile() { Console.WriteLine("\nWelcome, please choose a Save File:"); Console.WriteLine(" "); string path = ($"{AppDomain.CurrentDomain.BaseDirectory}characters"); DirectoryInfo dr = new DirectoryInfo(path); FileInfo[] mFile = dr.GetFiles(); foreach (FileInfo fiTemp in mFile) { Console.WriteLine(Path.GetFileNameWithoutExtension(fiTemp.Name)); } Console.WriteLine(" "); string SFname = Console.ReadLine(); try { var Character = new Character(); var directory = new DirectoryInfo($"{AppDomain.CurrentDomain.BaseDirectory}characters"); var JsonFile = directory.GetFiles($"{SFname}.json"); using StreamReader fi = File.OpenText(JsonFile[0].FullName); Character = JsonConvert.DeserializeObject <Character>(fi.ReadToEnd()); Console.Write("\nPlease Enter Your Password: "******"Wrong Password!" + d.Message); } } catch (Exception sfname) { Console.WriteLine("Exception: " + sfname.Message); } }