public FormMenu() { InitializeComponent(); lblScores.Hide(); back.Hide(); high = BinaryDeserializeScores(); }
private static void BinarySerializeScores(Highscores HS) { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); using (FileStream str = File.Open(path + "\\HighScoresCharInvaders.hs", FileMode.OpenOrCreate)) { File.SetAttributes(path + "\\HighScoresCharInvaders.hs", File.GetAttributes(path + "\\HighScoresCharInvaders.hs") | FileAttributes.Hidden); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(str, HS); } }
private static void BinarySerializeScores(Highscores HS) { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); using (FileStream str = File.Open(path + "\\HighScoresCharInvaders.hs", FileMode.OpenOrCreate)) { File.SetAttributes(path + "\\HighScoresCharInvaders.hs", File.GetAttributes(path + "\\HighScoresCharInvaders.hs") | FileAttributes.Hidden); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(str, HS); } }
private static Highscores BinaryDeserializeScores() { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); Highscores HS = null; try { using (FileStream str = File.OpenRead(path + "\\HighScoresCharInvaders.hs")) { BinaryFormatter bf = new BinaryFormatter(); HS = (Highscores)bf.Deserialize(str); } //File.Delete(path + "\\HighScoresCharInvaders.hs"); return(HS); } catch (FileNotFoundException) { return(new Highscores()); } }