/// <summary> /// Save the top five players that are holded in the scoreboard instance to file. /// </summary> /// <param name="memento">Instance of scoreboard that holds information about the top five players.</param> public void SaveRecordsToFile(ScoreboardMemento memento) { string encodedFile = Encoder.GetEncodedFile(memento); // Display file so it can be written in and hide it again File.SetAttributes(FilePath, File.GetAttributes(FilePath) & ~FileAttributes.Hidden); File.WriteAllText(FilePath, encodedFile); File.SetAttributes(FilePath, File.GetAttributes(FilePath) | FileAttributes.Hidden); }
internal static string GetEncodedFile(ScoreboardMemento memento) { string[] lines = memento.TopFiveRecords .Select(p => p.PlayerName + "=" + p.Score) .ToArray(); string[] encodedLines = new string[lines.Length]; for (int i = 0; i < lines.Length; i++) { encodedLines[i] = Base64Encode(lines[i]); } string encodedFile = Base64Encode(string.Join(Environment.NewLine, encodedLines)); return(encodedFile); }
internal static string GetEncodedFile(ScoreboardMemento memento) { string[] lines = memento.TopFiveRecords .Select(p => p.PlayerName + "=" + p.Score) .ToArray(); string[] encodedLines = new string[lines.Length]; for (int i = 0; i < lines.Length; i++) { encodedLines[i] = Base64Encode(lines[i]); } string encodedFile = Base64Encode(string.Join(Environment.NewLine, encodedLines)); return encodedFile; }