private static void DoLoadGame(StorageDevice device) { // Open a storage container. IAsyncResult result = device.BeginOpenContainer("Storage", null, null); // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne(); StorageContainer container = device.EndOpenContainer(result); // Close the wait handle. result.AsyncWaitHandle.Close(); string filename = "savegame.sav"; // Check to see whether the save exists. if (!container.FileExists(filename)) { // If not, dispose of the container and return. container.Dispose(); return; } // Open the file. Stream stream = container.OpenFile(filename, FileMode.Open); HighScores = new List <int>(); #if WINDEMO // Read the data from the file. XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData)); SaveGameData data = (SaveGameData)serializer.Deserialize(stream); #else using (StreamReader sr = new StreamReader(stream)) { System.Console.WriteLine("Loading..."); String input; displayText = ""; while ((input = sr.ReadLine()) != null) { System.Console.WriteLine(input); HighScores.Add(Int32.Parse(input)); } sr.Close(); } #endif // Close the file. stream.Close(); // Dispose the container. container.Dispose(); }
private static void DoLoadGame(StorageDevice device) { // Open a storage container. IAsyncResult result = device.BeginOpenContainer("Storage", null, null); // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne(); StorageContainer container = device.EndOpenContainer(result); // Close the wait handle. result.AsyncWaitHandle.Close(); string filename = "savegame.sav"; // Check to see whether the save exists. if (!container.FileExists(filename)) { // If not, dispose of the container and return. container.Dispose(); return; } // Open the file. Stream stream = container.OpenFile(filename, FileMode.Open); HighScores = new List<int>(); #if WINDEMO // Read the data from the file. XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData)); SaveGameData data = (SaveGameData)serializer.Deserialize(stream); #else using (StreamReader sr = new StreamReader(stream)) { System.Console.WriteLine("Loading..."); String input; displayText = ""; while ((input = sr.ReadLine()) != null) { System.Console.WriteLine(input); HighScores.Add(Int32.Parse(input)); } sr.Close(); } #endif // Close the file. stream.Close(); // Dispose the container. container.Dispose(); }