Exemplo n.º 1
0
        protected void LoadFromDevice(StorageDevice device)
        {
            IAsyncResult result = device.BeginOpenContainer(containerName, null, null);

            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(result);

            result.AsyncWaitHandle.Close();

            string filename = gameName + ".sav";

            if (!container.FileExists(filename))
            {
                container.Dispose();
                return;
            }

            Stream stream = container.OpenFile(filename, FileMode.Open);

            if (stream.Length > 0)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(List <HighScoreDataItem>));
                highScores = (List <HighScoreDataItem>)serializer.Deserialize(stream);
            }

            stream.Close();
            container.Dispose();
        }
Exemplo n.º 2
0
    public static void Load()
    {
        IAsyncResult  result = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
        StorageDevice device = StorageDevice.EndShowSelector(result);

        result = device.BeginOpenContainer("StorageDemo", null, null);
        // Wait for the WaitHandle to become signaled.
        result.AsyncWaitHandle.WaitOne();

        StorageContainer container = device.EndOpenContainer(result);

        // Close the wait handle.
        result.AsyncWaitHandle.Close();
        // 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);
        XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
        SaveGameData  data       = (SaveGameData)serializer.Deserialize(stream);

        // Close the file.
        stream.Close();
        // Dispose the container.
        container.Dispose();
        LoadData(data);
    }
Exemplo n.º 3
0
        public void Load()
        {
            Core.res  = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
            Core.sDev = StorageDevice.EndShowSelector(Core.res);
            IAsyncResult result =
                Core.sDev.BeginOpenContainer("Phone", null, null);

            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = Core.sDev.EndOpenContainer(result);

            result.AsyncWaitHandle.Close();
            string filename = "phoneBookContacts.sav";

            if (!container.FileExists(filename))
            {
                container.Dispose();
                return;
            }
            Stream        stream       = container.OpenFile(filename, FileMode.Open);
            XmlSerializer serializer   = new XmlSerializer(typeof(ContactsList));
            ContactsList  contactsList = (ContactsList)serializer.Deserialize(stream);

            for (int i = 0; i < contactsList.name.Length; i++)
            {
                Contact c = new Contact(phone, contactsList.name[i], contactsList.number[i]);
                contacts.Add(c);
            }
            firstStart = contactsList.fStart;
            stream.Close();

            container.Dispose();
        }
Exemplo n.º 4
0
        private void Load(IAsyncResult result)
        {
            _storageDevice = StorageDevice.EndShowSelector(result);
            if (_storageDevice != null && _storageDevice.IsConnected)
            {
                _gameSettings = CreateNewSettings();
                IAsyncResult r = _storageDevice.BeginOpenContainer(StorageContainerName, null, null);
                result.AsyncWaitHandle.WaitOne();
                StorageContainer container = _storageDevice.EndOpenContainer(r);
                if (container.FileExists(Filename))
                {
                    Stream stream = container.OpenFile(Filename, FileMode.Open);
                    try
                    {
                        IFormatter formatter = new BinaryFormatter();
                        _gameSettings = (Settings)formatter.Deserialize(stream);
                        stream.Close();
                        container.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        stream.Close();
                        container.Dispose();
                        container.DeleteFile(Filename);
                    }
                }

                result.AsyncWaitHandle.Close();

                OnSettingsLoaded();
            }
        }
        private static void do_LoadGame()
        {
            saving = true;

            while (!deviceFound)
            {
                ;
            }

            try
            {
                if (result.IsCompleted)
                {
                    if (device != null && device.IsConnected)
                    {
                        try
                        {
                            IAsyncResult result2 = device.BeginOpenContainer("Contract: Void Justice", null, null);

                            result2.AsyncWaitHandle.WaitOne();

                            StorageContainer container = device.EndOpenContainer(result2);

                            result2.AsyncWaitHandle.Close();

                            // Check to see whether the save exists.
                            if (!container.FileExists(filename))
                            {
                                saving = false;

                                container.Dispose();
                                return;
                            }

                            Stream stream = container.OpenFile(filename, FileMode.Open);

                            XmlSerializer serializer = new XmlSerializer(typeof(List <HighScoresState.HighScoreValue>));

                            HighScoresState.highScores = (List <HighScoresState.HighScoreValue>)serializer.Deserialize(stream);

                            stream.Close();

                            container.Dispose();
                        }
                        catch (FileNotFoundException)
                        {
                            saving = false;
                            return;
                        }
                    }
                }
            }
            catch (Exception)
            {
                saving = false;
            }

            saving = false;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Dispose and go dormant, normally only at end of program.
 /// </summary>
 public static void Shutdown()
 {
     if (storageContainer != null)
     {
         storageContainer.Dispose();
     }
     storageContainer = null;
     storageDevice    = null;
     dirty            = false;
 }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Automatically creates or reconnects to locally saved data.
        /// </summary>
        /// <param name="Name">The name of the object (should be the same each time to access old data).</param>
        /// <returns>Whether or not you successfully connected to the save data.</returns>
        public bool bind(string Name)
        {
            _so  = null;
            name = Name;



            try
            {
                _savedata = new FlxSaveData();

                // Open a storage container.
                IAsyncResult result =
                    _device.BeginOpenContainer(Name, null, null);
                // Wait for the WaitHandle to become signaled.
                result.AsyncWaitHandle.WaitOne();

                _so = _device.EndOpenContainer(result);

                // Close the wait handle.
                result.AsyncWaitHandle.Close();

                // Check to see whether the save exists.
                if (!_so.FileExists(_savefile))
                {
                    // If not, dispose of the container and return new blank data.
                    _so.Dispose();
                    _savedata = new FlxSaveData();
                    return(true);
                }
                // Open the file.
                Stream stream = _so.OpenFile(_savefile, FileMode.Open);

                _savedata.deserialize(stream);

                // Close the file.
                stream.Close();
                // Dispose the container.
                _so.Dispose();
            }
            catch
            {
                FlxG.log("WARNING: There was a problem binding to\nthe shared object data from FlxSave.");
                name      = null;
                _so       = null;
                _savedata = null;
                return(false);
            }


            return(true);
        }
Exemplo n.º 9
0
        //public static PrimitiveBatch primitiveBatch = null;
        #endregion

        public static bool LoadOptions()
        {
            if ((null != Storage) && Storage.IsConnected)
            {
                // Open a storage container.
                IAsyncResult result =
                    evdEnGlobals.Storage.BeginOpenContainer(evdEnGlobals.GameName, null, null);

                // Wait for the WaitHandle to become signaled.
                result.AsyncWaitHandle.WaitOne();

                StorageContainer container = evdEnGlobals.Storage.EndOpenContainer(result);

                // Get the path of the save game.
                if (container.FileExists(OptionsFileName))
                {
                    // Open the file.
                    Stream stream = container.OpenFile(OptionsFileName, FileMode.Open, FileAccess.Read);

                    BinaryFormatter formatter = new BinaryFormatter();

                    try
                    {
                        evdEnGlobals.Options = (OptionsData)formatter.Deserialize(stream);
                    }
                    catch
                    {
                        stream.Close();
                        container.Dispose();
                        // better to show some diagnostics...
                        return(evdEnGlobals.SaveOptions());
                    }

                    stream.Close();
                    container.Dispose();

                    return(true);
                }
                else
                {
                    return(evdEnGlobals.SaveOptions());
                }
            }
            else if (null != Storage)
            {
                // Storage was disconnected
                return(false);
            }
            return(false);
        }
Exemplo n.º 10
0
        public void RequestSave(string fileName, SaveData data)
        {
            try
            {
                IAsyncResult device = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                device.AsyncWaitHandle.WaitOne();
                StorageDevice storageDevice = StorageDevice.EndShowSelector(device);

                if (storageDevice.IsConnected && storageDevice != null)
                {
                    IAsyncResult result = storageDevice.BeginOpenContainer("Save Game", null, null);
                    result.AsyncWaitHandle.WaitOne();
                    StorageContainer container = storageDevice.EndOpenContainer(result);
                    result.AsyncWaitHandle.Close();

                    if (container.FileExists(fileName))
                    {
                        container.DeleteFile(fileName);
                    }

                    Stream        stream     = container.CreateFile(fileName);
                    XmlSerializer serializer = new XmlSerializer(typeof(SaveData));
                    serializer.Serialize(stream, data);
                    stream.Close();
                    container.Dispose();
                }
                Console.WriteLine("Save complete!");
            }
            catch
            {
                Console.WriteLine("ERROR! SAVE FAILED!!!");
            }
        }
Exemplo n.º 11
0
        public void SavePreferenceData(PreferenceData preferenceData)
        {
            try
            {
                IAsyncResult device = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                device.AsyncWaitHandle.WaitOne();
                StorageDevice storageDevice = StorageDevice.EndShowSelector(device);

                if (storageDevice.IsConnected && storageDevice != null)
                {
                    IAsyncResult result = storageDevice.BeginOpenContainer("A Troll in the Hay Data", null, null);
                    result.AsyncWaitHandle.WaitOne();
                    StorageContainer container = storageDevice.EndOpenContainer(result);
                    result.AsyncWaitHandle.Close();

                    if (container.FileExists(""))//come edit the file name
                    {
                        container.DeleteFile("");
                    }

                    Stream        stream     = container.CreateFile("");
                    XmlSerializer serializer = new XmlSerializer(typeof(PreferenceData));
                    serializer.Serialize(stream, preferenceData);
                    stream.Close();
                    container.Dispose();
                }
                Console.WriteLine("Preference data save complete!");
            }
            catch
            {
                Console.WriteLine("ERROR! PREFERENCE SAVE FAILED!!!");
            }
        }
Exemplo n.º 12
0
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            #if WINDOWS
            (Manager.Game as Game1).WriteSave();
            #endif

            #if XBOX
            try
            {
                StorageContainer c = ScreenManager.GetContainer();

                if (c != null)
                {
                    StreamWriter writer = new StreamWriter(c.OpenFile("save.txt", FileMode.Open));

                    (Manager.Game as Game1).WriteTheSave(writer);

                    c.Dispose();
                }
            }
            catch
            {
            }
            #endif

            Manager.Game.Exit();
        }
        /// <summary>
        /// This method serializes the master save file into
        /// the StorageContainer for this game.
        /// By: Joseph Shaw
        /// </summary>
        /// <param name="device"></param>
        public static void SaveMasterFile(StorageDevice device, MasterSaveFile masterSaveFile)
        {
            // Open a storage container.
            IAsyncResult result = device.BeginOpenContainer("DungeonCrawler", null, null);

            // Wait for the WaitHandle to become signaled.
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);

            // Close the wait handle.
            result.AsyncWaitHandle.Close();

            // Check to see whether the save exists.
            if (container.FileExists(masterFileName))
            {
                // Delete it so that we can create one fresh.
                container.DeleteFile(masterFileName);
            }

            // Create the file.
            Stream stream = container.CreateFile(masterFileName);

            // Create the BinaryFormatter
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            // Convert the file to binary and save it
            binaryFormatter.Serialize(stream, masterSaveFile);

            // Close the file.
            stream.Close();

            // Dispose the container, to commit changes.
            container.Dispose();
        }
 private void Save(IAsyncResult result)
 {
     _storageDevice = StorageDevice.EndShowSelector(result);
     if (_storageDevice != null && _storageDevice.IsConnected)
     {
         var      filename = String.Format("save{0:00}.dat", _slot);
         var      player   = PlayerManager.Instance;
         GameSave save     = new GameSave()
         {
             Ammo            = player.Ammo,
             Lives           = player.Lives,
             Hearts          = player.Hearts,
             Coins           = player.Coins,
             StagesCompleted = player.StagesCompleted
         };
         IAsyncResult r = _storageDevice.BeginOpenContainer(_storageContainerName, null, null);
         result.AsyncWaitHandle.WaitOne();
         Thread.Sleep(1500);
         StorageContainer container = _storageDevice.EndOpenContainer(r);
         if (container.FileExists(filename))
         {
             container.DeleteFile(filename);
         }
         Stream     stream    = container.CreateFile(filename);
         IFormatter formatter = new BinaryFormatter();
         formatter.Serialize(stream, save);
         stream.Close();
         container.Dispose();
         result.AsyncWaitHandle.Close();
         if (_saveCallback != null)
         {
             _saveCallback();
         }
     }
 }
Exemplo n.º 15
0
        public void SaveOptions(bool bAutoArangeClues, bool bShowClueDescriptions, bool bShowClock, bool bShowPuzzleNumber, bool bRandomizeClues, float fSoundVol, float fMusicVol)
        {
            #if XBOX
            StorageContainer container = m_Storage.OpenContainer("Happiness");
            string           filename  = Path.Combine(container.Path, "Happiness.opt");
            #else
            string filename = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Happiness\\Happiness.opt";
            #endif

            try
            {
                BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.Create, FileAccess.Write));

                bw.Write(m_iOptionsVersion);
                bw.Write(bAutoArangeClues);
                bw.Write(bShowClueDescriptions);
                bw.Write(bShowClock);
                bw.Write(bShowPuzzleNumber);
                bw.Write(bRandomizeClues);
                bw.Write(fSoundVol);
                bw.Write(fMusicVol);
                bw.Close();
            }
            catch (Exception)
            {
            }

#if XBOX
            if (container != null)
            {
                container.Dispose();
            }
#endif
        }
Exemplo n.º 16
0
        /// <summary>
        /// Saves the entire session with all the relevant information per added frame. Should only be called after exiting the game.
        /// </summary>
        public void SaveSession()
        {
            IAsyncResult result = storageDevice.BeginOpenContainer("SPB", null, null); // Get the Storage Container

            // Wait for the WaitHandle to become signaled.
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = storageDevice.EndOpenContainer(result);

            // Close the wait handle.
            result.AsyncWaitHandle.Close();
            String fileName;

            do // Create a new XML file with a new, randomly chosen, name.
            {
                fileName = RandomString(10) + Extension;
            } while (container.FileExists(fileName));

            Stream stream = container.CreateFile(fileName);

            SessionData sessionData = new SessionData()
            {
                session = session
            };

            XmlSerializer serializer = new XmlSerializer(typeof(SessionData)); // Serialize the sessionData so it can be stored.

            serializer.Serialize(stream, sessionData);
            stream.Close();
            container.Dispose();
        }
Exemplo n.º 17
0
        //Creates folder on users computer where data will be saved
        private void DoSaveGame(StorageDevice a_device, Game a_game, string a_file)
        {
            try
            {
                // Open a storage container.
                IAsyncResult f_result = a_device.BeginOpenContainer("Cubes_are_acute", null, null);

                // Wait for the WaitHandle to become signaled.
                f_result.AsyncWaitHandle.WaitOne();

                StorageContainer container = a_device.EndOpenContainer(f_result);

                // Close the wait handle.
                f_result.AsyncWaitHandle.Close();

                //Path is Documents/SavedGames/Cubes_are_acute on C:
                string filename = a_file;

                String[] f_str = container.GetFileNames();

                if (filename == "Empty")
                {
                    filename = "Save" + (f_str.Length + 1);
                }
                else if (filename == "New Save")
                {
                    filename = "Save" + (f_str.Length + 1);
                }
                else
                {
                    filename = a_file;
                }

                // Check to see whether the save exists.
                if (container.FileExists(filename))
                {
                    // Delete it so that we can create one fresh.
                    container.DeleteFile(filename);
                }

                // Create the file.
                Stream stream = container.CreateFile(filename);

                // Convert the object to Binary data and put it in the stream.
                BinaryFormatter binFormatter = new BinaryFormatter();

                //serializes Game and writes it's data to savegame.sav
                binFormatter.Serialize(stream, a_game);

                // Close the file.
                stream.Close();

                // Dispose the container, to commit changes.
                container.Dispose();
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 18
0
        public void Write(StorageDevice device, string windowTitle, string filename)
        {
            if (device == null)
            {
                return;
            }

            // Open a storage container.StorageContainer container
#if XDK
            bool             isTransferredFromOtherPlayer;
            StorageContainer container = device.OpenContainer(windowTitle, false, out isTransferredFromOtherPlayer);
#else
            IAsyncResult result = device.BeginOpenContainer(windowTitle, null, null);

            // wait for the waithandle to become signaled
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);
#endif

            // Open the file, creating it if necessary.
            using (Stream stream = container.OpenFile(filename, FileMode.Create))
            {
                StreamWriter writer = new StreamWriter(stream);
                Write(writer);
                writer.Close();
            }

            // Dispose the container, to commit changes.
            container.Dispose();
        }
Exemplo n.º 19
0
        private void SaveCallback(IAsyncResult result)
        {
            StorageContainer container = StorageDevice.EndOpenContainer(result);

            SaveGameRequest saveGameRequest = (SaveGameRequest)result.AsyncState;

            // Overwrite existing save.
            if (container.FileExists(saveGameRequest.SaveName))
            {
                container.DeleteFile(saveGameRequest.SaveName);
            }

            // Create the file.
            Stream stream = container.CreateFile(saveGameRequest.SaveName);

            // Convert the object to XML data and put it in the stream.
            XmlSerializer serializer = new XmlSerializer(saveGameRequest.SaveType);

            serializer.Serialize(stream, saveGameRequest.SaveData);

            // Close the file.
            stream.Close();

            // Dispose the container, to commit changes.
            container.Dispose();
        }
Exemplo n.º 20
0
        public void Save()
        {
            Core.res  = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
            Core.sDev = StorageDevice.EndShowSelector(Core.res);
            IAsyncResult result =
                Core.sDev.BeginOpenContainer("Phone", null, null);

            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = Core.sDev.EndOpenContainer(result);

            result.AsyncWaitHandle.Close();

            string filename = "phoneBookContacts.sav";

            if (container.FileExists(filename))
            {
                container.DeleteFile(filename);
            }
            Stream        stream       = container.CreateFile(filename);
            XmlSerializer serializer   = new XmlSerializer(typeof(ContactsList));
            ContactsList  contactsList = new ContactsList();

            contactsList.name   = new string[contacts.Count];
            contactsList.number = new string[contacts.Count];
            for (int i = 0; i < contacts.Count; i++)
            {
                contactsList.name[i]   = contacts[i].name;
                contactsList.number[i] = contacts[i].number;
            }
            contactsList.fStart = firstStart;
            serializer.Serialize(stream, contactsList);
            stream.Close();

            container.Dispose();
        }
Exemplo n.º 21
0
        void SaveBookletData(string filename, StorageDevice storageDevice, Booklet booklet)
        {
            using (StorageContainer storageContainer = storageDevice.OpenContainer("Content"))
            {
                string filenamePath = Path.Combine(storageContainer.Path, filename);

                using (FileStream fileStream = File.Create(filenamePath))
                {
                    BinaryWriter myBw = new BinaryWriter(fileStream);
                    try
                    {
                        myBw.Write(booklet.ToByteArray());
                    }
                    catch (Exception e)
                    {
                        ;
                    }
                    finally
                    {
                        myBw.Flush();
                        myBw.Close();
                        fileStream.Close();
                        _operationPending = false;
                        storageContainer.Dispose();
                    }
                }
            }
        }
Exemplo n.º 22
0
        public void LoadSettings()
        {
            // Open a storage container.StorageContainer container =
            IAsyncResult result = device.BeginOpenContainer(Window.Title, null, null);

            // wait for the waithandle to become signaled
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);

            // Open the file, creating it if necessary.
            if (container.FileExists("settings.xml"))
            {
                using (Stream stream = container.OpenFile("settings.xml", FileMode.Open))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                    settings = (Settings)serializer.Deserialize(stream);
                    ApplySettings();
                }
            }
            else
            {
                settings.effectsVolume = DefaultEffectsVolume;
                settings.musicVolume   = DefaultMusicVolume;
                ApplySettings();
            }

            // Dispose the container, to commit changes.
            container.Dispose();
        }
Exemplo n.º 23
0
        protected override void UnloadContent()
        {
            texture = null;

            if (storageDevice != null)
            {
                //Save out our highscores to disk
                if (container != null)
                {
                    container.Dispose();
                    container = null;
                }
            }

            base.UnloadContent();
        }
Exemplo n.º 24
0
        public static void saveScores(int trackID, HighScoreType mode)
        {
            {
                System.Diagnostics.Debug.WriteLine(scoreDoc);


                StorageContainer container = null;

                while (container == null)
                {
                    IAsyncResult result = BeatShift.Storage.BeginOpenContainer(BeatShift.Title, null, null);
                    result.AsyncWaitHandle.WaitOne();
                    container = BeatShift.Storage.EndOpenContainer(result);
                    result.AsyncWaitHandle.Close();
                }



                Stream    scoreStream      = container.OpenFile("HighScore_" + trackID + "_" + ((int)mode) + ".xml", FileMode.Create, FileAccess.Write);
                XmlWriter optsStreamWriter = XmlWriter.Create(scoreStream);
                scoreDoc.WriteTo(optsStreamWriter);
                optsStreamWriter.Flush();
                scoreStream.Dispose();
                scoreStream.Close();
                container.Dispose();
            }
        }
Exemplo n.º 25
0
        //Returns the number of existing savefiles
        private String[] GetSaves(StorageDevice a_device)
        {
            try
            {
                IAsyncResult f_result = a_device.BeginOpenContainer("Cubes_are_acute", null, null);

                // Wait for the WaitHandle to become signaled.
                f_result.AsyncWaitHandle.WaitOne();

                StorageContainer container = a_device.EndOpenContainer(f_result);

                // Close the wait handle.
                f_result.AsyncWaitHandle.Close();

                string[] filename = container.GetFileNames();

                container.Dispose();

                return(filename);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 26
0
        private static void init(int trackID, HighScoreType mode)
        {
            StorageContainer container = null;
            Boolean          fileExists;

            while (container == null)
            {
                IAsyncResult result = BeatShift.Storage.BeginOpenContainer(BeatShift.Title, null, null);
                result.AsyncWaitHandle.WaitOne();
                container = BeatShift.Storage.EndOpenContainer(result);
                result.AsyncWaitHandle.Close();
            }

            Stream scoreStream;

            fileExists = container.FileExists("HighScore_" + trackID + "_" + ((int)mode) + ".xml");

            if (fileExists)
            {
                scoreStream = container.OpenFile("HighScore_" + trackID + "_" + ((int)mode) + ".xml", FileMode.Open, FileAccess.Read);
            }
            else
            {
                scoreStream = TitleContainer.OpenStream("HighScore_" + trackID + "_" + ((int)mode) + ".xml");
            }

            StreamReader scoreStreamReader = new StreamReader(scoreStream);

            scoreDoc = XDocument.Load(scoreStreamReader);

            scoreStream.Dispose();
            scoreStream.Close();
            container.Dispose();
        }
Exemplo n.º 27
0
        public static bool FileExists(string filename)
        {
            try
            {
                // Open a storage container.
                IAsyncResult result =
                    device.BeginOpenContainer("GreyInfection", null, null);

                // Wait for the WaitHandle to become signaled.
                result.AsyncWaitHandle.WaitOne();

                StorageContainer container = device.EndOpenContainer(result);

                // Close the wait handle.
                result.AsyncWaitHandle.Close();

                // Check to see whether the save exists.
                bool ret = container.FileExists(filename);

                container.Dispose();

                return(ret);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 28
0
        public static void SaveHighScores(HighScores360 data, string filename, StorageDevice storageDevice)
        {
            if (storageDevice.IsConnected)
            {
                IAsyncResult result = storageDevice.BeginOpenContainer("Highscores", null, null);

                result.AsyncWaitHandle.WaitOne();

                StorageContainer container = storageDevice.EndOpenContainer(result);

                result.AsyncWaitHandle.Close();

                if (container.FileExists(filename))
                {
                    container.DeleteFile(filename);
                }

                Stream stream = container.CreateFile(filename);
                try
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(HighScores360));
                    serializer.Serialize(stream, data);
                }
                finally
                {
                    stream.Close();
                }
                container.Dispose();
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Loads the high score from a text file.  The StorageDevice was selected during the loading screen.
        /// </summary>
        private void LoadHighscore()
        {
            StorageDevice device = (StorageDevice)ScreenManager.Game.Services.GetService(typeof(StorageDevice));

            if (device != null)
            {
                StorageContainer container = device.OpenContainer("AlienGame");
                if (File.Exists(Path.Combine(container.Path, "highscores.txt")))
                {
                    StreamReader reader = null;

                    try
                    {
                        reader    = new StreamReader(Path.Combine(container.Path, "highscores.txt"));
                        highScore = Int32.Parse(reader.ReadToEnd(), System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch (FormatException)
                    {
                        highScore = 10000;
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                            reader.Dispose();
                        }
                    }
                }

                container.Dispose();
            }
        }
Exemplo n.º 30
0
 private static void SaveToDevice(IAsyncResult result)
 {
     storageDevice = StorageDevice.EndShowSelector(result);
     if (storageDevice != null && storageDevice.IsConnected)
     {
         List <Player.PlayerData> playersDataToSave = new List <Player.PlayerData>();
         foreach (Player player in PlayerManager.playersList)
         {
             playersDataToSave.Add(player.getSaveData());
         }
         SaveData SaveData = new SaveData()
         {
             playersData = playersDataToSave
         };
         IAsyncResult r = storageDevice.BeginOpenContainer(storageName, null, null);
         result.AsyncWaitHandle.WaitOne();
         StorageContainer container = storageDevice.EndOpenContainer(r);
         if (container.FileExists(fileName))
         {
             container.DeleteFile(fileName);
         }
         Stream        stream     = container.CreateFile(fileName);
         XmlSerializer serializer = new XmlSerializer(typeof(SaveData));
         serializer.Serialize(stream, SaveData);
         stream.Close();
         container.Dispose();
         result.AsyncWaitHandle.Close();
     }
 }