Exemple #1
0
        private void SaveToFile(IAsyncResult result)
        {
            device = StorageDevice.EndShowSelector(result);

            // Open a storage container.
            IAsyncResult r = device.BeginOpenContainer(containerName, null, null);
            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(r);
            result.AsyncWaitHandle.Close();

            // Delete old file and create new one.
            if (container.FileExists(fileName))
            {
                container.DeleteFile(fileName);
            }
            Stream fileStream = container.CreateFile(fileName);

            // Write data to file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            serializer.Serialize(fileStream, saveGameData);

            // Close file.
            fileStream.Close();
            container.Dispose();
        }
Exemple #2
0
        public void LoadSaveData(StorageDevice device)
        {
            result = device.BeginOpenContainer("Storage", null, null);
            result.AsyncWaitHandle.WaitOne();

            StorageContainer container = device.EndOpenContainer(result);

            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 file.
            Stream stream = container.OpenFile(filename, FileMode.Open);
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            loadedData = (SaveGameData)serializer.Deserialize(stream);
            //close file
            stream.Close();
            container.Dispose();
        }
        public GameData(StorageDevice device)
        {
            this.device = device;

            // initialize score
            saveGameData.levelCompleted = 0;
            saveGameData.currentlevel = 1;
            saveGameData.score = 0;
            saveGameData.levelData = new LevelData[GameConstants.LEVELS];
            for (int i = 0; i < GameConstants.LEVELS; i++)
            {
                saveGameData.levelData[i].currentlevelNum = i + 1;
                saveGameData.levelData[i].time = TimeSpan.Zero.ToString();
                saveGameData.levelData[i].levelParTime = TimeSpan.Zero.ToString();
                saveGameData.levelData[i].remainingHealth = GameConstants.HEALTH;
            }
            //
            GetDevice();
            GetContainer();
            if (!Load())
            {
                GetContainer();
                Save();
            }
        }
        public ProfileSelectionScreen(StorageDevice device)
            : base("Choose your active profile:")
        {
            IsPopup = true;
            mDevice = device;

            this.Buttons.Clear();

            var temp = Profile.LoadAll(mDevice);
            mDefault = mSelectedButton = temp.Key;

            if (temp.Key < 0)
            {
                mSelectedButton = 0;
            }

            mProfiles = temp.Value;

            for(int i = 0; i < mProfiles.Length; i++)
            {
                Button btn = new Button(mProfiles[i] != null ? mProfiles[i].Name : "-Empty-");
                btn.Pressed += ProfileSelectedButton;

                Buttons.Add(btn);
            }
        }
Exemple #5
0
        public void Initialize(ContentManager Content, GraphicsDevice Graphics)
        {
            StorageDeviceResult = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
            StorageDeviceResult.AsyncWaitHandle.WaitOne();
            StorageDevice = StorageDevice.EndShowSelector(StorageDeviceResult);
            StorageDeviceResult.AsyncWaitHandle.Close();
            OpenContainer();
            this.Content = Content;
            this.Graphics = Graphics;
            this.SpriteBatch = new SpriteBatch(Graphics);
            this.SpriteFont = Content.Load<SpriteFont>("DefaultFont");

            ScreenHeight = Graphics.Viewport.Height;
            ScreenWidth = Graphics.Viewport.Width;
            ScreenHeightHalf = ScreenHeight / 2;
            ScreenWidthHalf = ScreenWidth / 2;
            FullScreenRectangle = new Rectangle(0, 0, (int)ScreenWidth, (int)ScreenHeight);

            Random = new Random();
            PixelWhite = new Texture2D(Graphics, 1, 1);
            Color[] data = { Color.White };
            PixelWhite.SetData<Color>(data);
            int GardientSize = 1000;
            Gardient = new Texture2D(Graphics, GardientSize, GardientSize);
            data = new Color[GardientSize * GardientSize];
            for (int x = 0; x < GardientSize; x++)
            {
                for (int y = 0; y < GardientSize; y++)
                {
                    float c = 1.0f - ((float)(x * y)) / (GardientSize * GardientSize);
                    data[x + y * GardientSize] = new Color(c, c, c);
                }
            }
            Gardient.SetData<Color>(data);
        }
        void saveLevel(IAsyncResult result)
        {
            SaveLevelData data = new SaveLevelData();
            data.objectList = level.entityList;
            data.currentPosition = level.currentPosition;
            data.multiSelect = level.multiSelect;
            data.upTime = level.upTime;
            data.holdTime = level.holdTime;
            data.filename = level.levelName;

            device = StorageDevice.EndShowSelector(result);
            if (device != null && device.IsConnected)
            {
                IAsyncResult r = device.BeginOpenContainer("MyGamesStorage", null, null);
                result.AsyncWaitHandle.WaitOne();
                StorageContainer container = device.EndOpenContainer(r);
                if (container.FileExists(level.levelName + ".sav"))
                    container.DeleteFile(level.levelName + ".sav");
                Stream stream = container.CreateFile(level.levelName + ".sav");

                XmlSerializer serializer = new XmlSerializer(typeof(SaveLevelData));
                serializer.Serialize(stream, data);
                stream.Close();
                container.Dispose();
                result.AsyncWaitHandle.Close();
            }
        }
 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();
     }
 }
 public void ExecuteSave(int slot, Action callback = null)
 {
     _slot = slot;
     _saveCallback = callback;
     _storageDevice = null;
     StorageDevice.BeginShowSelector(PlayerIndex.One, Save, null);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageContainer"/> class.
        /// </summary>
        /// <param name='device'>The attached storage-device.</param>
        /// <param name='name'>The title's filename.</param>
        /// <param name='rootPath'>The path of the storage root folder</param>
        /// <param name='playerIndex'>
        /// The index of the player whose data is being saved, or null if data is for all
        /// players.
        /// </param>
        internal StorageContainer(
			StorageDevice device,
			string name,
			string rootPath,
			PlayerIndex? playerIndex
		)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("A title name has to be provided in parameter name.");
            }

            StorageDevice = device;
            DisplayName = name;

            // Generate the path of the game's savefolder
            storagePath = Path.Combine(
                rootPath,
                Path.GetFileNameWithoutExtension(
                    AppDomain.CurrentDomain.FriendlyName
                )
            );

            // Create the root folder for all titles, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }

            storagePath = Path.Combine(storagePath, name);

            // Create the sub-folder for this container/title's files, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }

            /* There are two types of subfolders within a StorageContainer.
             * The first is a PlayerX folder, X being a specified PlayerIndex.
             * The second is AllPlayers, when PlayerIndex is NOT specified.
             * Basically, you should NEVER expect to have ANY file in the root
             * game save folder.
             * -flibit
             */
            if (playerIndex.HasValue)
            {
                storagePath = Path.Combine(storagePath, "Player" + ((int) playerIndex.Value + 1).ToString());
            }
            else
            {
                storagePath = Path.Combine(storagePath, "AllPlayers");
            }

            // Create the player folder, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }
        }
		internal SaveOperationAsyncResult(StorageDevice device, string container, string file, FileAction action, FileMode mode)
		{
			this.storageDevice = device;
			this.containerName = container;
			this.fileName = file;
			this.fileAction = action;
			this.fileMode = mode;
		}
Exemple #11
0
 // Avaa leveli nimen mukaan
 public void loadLevel(string nimi)
 {
     device = StorageDevice.EndShowSelector(result);
     if (device != null && device.IsConnected)
     {
         DoLoadGame( device );
     }
 }
        /// <summary>
        /// This method gets the filenames from the universal storage file LbKTileData.sav
        /// </summary>
        /// <param name="device"></param>
        /// <param name="gamer"></param>
        /// <param name="fileNamesOnly"></param>
        public static void LoadGame(StorageDevice device, SignedInGamer gamer, bool fileNamesOnly)
        {
            // Open a storage container.
            // name of container is LbK Storage Device
            IAsyncResult result =
                device.BeginOpenContainer(gamer.Gamertag, 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 = "LbKTileData.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 file = container.OpenFile(filename, FileMode.Open);

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(file);

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

            // Dispose the container.
            container.Dispose();

            // Report the data to the console.
            if (fileNamesOnly)
            {
                fileNames = data.Names;
            }
            else
            {
                position = data.TilePosition;
                type = data.TileType;
                objectNumber = data.TileObjectNumber;
                count = data.TileCount;
                fileNames = data.Names;
            }

            GamePlayScreen.storageDevice = device;
            // load up game with respective device
        }
Exemple #13
0
 public StorageContainer(StorageDevice device, string name)
 {
     _device = device;
     _name = name;
     _path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+System.IO.Path.DirectorySeparatorChar+name;
     // Creathe the "device" if need
     if (!Directory.Exists(_path))
     {
         Directory.CreateDirectory(_path);
     }
 }
Exemple #14
0
 public void Update()
 {
     if (pendingDevice)
     {
         if (deviceResult.IsCompleted)
         {
             //device = Guide.EndShowStorageDeviceSelector(deviceResult);
             device = StorageDevice.EndShowSelector(deviceResult);
             pendingDevice = false;
             Read(STORE_SETTINGS);
         }
     }
 }
 public LevelNames()
 {
     device = null;
     if(check)
     {
         StorageDevice.BeginShowSelector(PlayerIndex.One, this.loadLevelName, null);
     }
     if(check == false)
     {
         filenames = new List<string>();
         StorageDevice.BeginShowSelector(PlayerIndex.One, this.saveLevelName, null);
     }
 }
 public SaveScore()
 {
     device = null;
        if (check) {
         StorageDevice.BeginShowSelector(PlayerIndex.One, this.loadLevelName, null);
        }
        if (check == false)
        {
         levelNames = new List<string>();
         timeScores = new List<int>();
         hitsScores = new List<int>();
         StorageDevice.BeginShowSelector(PlayerIndex.One, this.save, null);
        }
 }
Exemple #17
0
        internal static StorageContainer OpenContainer(StorageDevice storageDevice, string saveGameName)
        {
            IAsyncResult result = storageDevice.BeginOpenContainer(saveGameName, null, null);

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

            StorageContainer container = storageDevice.EndOpenContainer(result);

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

            return container;
        }
        /// <summary>
        /// This method loads a serialized data object
        /// from the StorageContainer for this game.
        /// </summary>
        /// <param name="device"></param>
        public static void LoadGame(StorageDevice device, SignedInGamer gamer)
        {
            // Open a storage container.
            // name of container is LbK Storage Device
            IAsyncResult result =
                device.BeginOpenContainer("LbK Storage Device", 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 = "LbKSavedItems.sav";

            // Check to see whether the save exists.
            if (!container.FileExists(filename))
            {
                // If not, dispose of the container and return.
                container.Dispose();
                nothingLoaded = true;
                return;
            }

            // Open the file.
            Stream file = container.OpenFile(filename, FileMode.Open);

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(file);

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

            // Dispose the container.
            container.Dispose();

            // Report the data to the console.
            playerName = data.PlayerName;
            level = data.Level;
            score = data.PlayerScore;
            position = new Vector2(data.playerPosition.X, data.playerPosition.Y);
            checkPoint = data.CheckPoint;

            GamePlayScreen.storageDevice = device;
            // load up game with respective device
        }
Exemple #19
0
        public void InitiateLoad(Game1 game, string filename)
        {
            this.filename = filename + ".sav";

            try
            {
                device = null;
                StorageDevice.BeginShowSelector(LoadFromDevice, null);
            }

            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #20
0
        public void SaveGame(SaveGameData saveGameData, string containerName, string fileName)
        {
            device = null;
            this.saveGameData = saveGameData;
            this.containerName = containerName;
            this.fileName = fileName;

            try
            {
                StorageDevice.BeginShowSelector(PlayerIndex.One, this.SaveToFile, null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
 public void InitiateLoad()
 {
     try
     {
     if (!Guide.IsVisible)
     {
         device = null;
         StorageDevice.BeginShowSelector(PlayerIndex.One, this.LoadFromDevice, null);
     }
     }
     catch (InvalidOperationException invalidOperationException)
     {
     //Logger.error(“InvalidOperationException”);
     StorageDevice.BeginShowSelector(PlayerIndex.One, this.LoadFromDevice, null);
     }
 }
Exemple #22
0
        public void loadGame(StorageDevice device)
        {
            Console.WriteLine("loading");
            IAsyncResult result = device.BeginOpenContainer("Container", null, null);
            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(result);
            result.AsyncWaitHandle.Close();

            string filename = "savegame.sav";

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

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

            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(stream);

            stream.Close();

            container.Dispose();

            game.getZoneFactory().loadZones(game.getContentHandler(), data.currentPlayerZone);
            game.getZoneFactory().setCurrentZoneFromNumber(data.currentPlayerZone);
            game.getPlayer().setZoneLevel(data.currentPlayerLevel);
            game.getPlayer().setGlobalLocation(data.playerPosition);
            game.getKeyHandler().getMovementHandler().updateDrawLocations(game.getPlayer(), game.getZoneFactory().getCurrentZone());
            game.getPlayer().getStats().setFireEnergy(data.fireEnergy);
            game.getPlayer().getStats().setCurrentFireEnergy(data.currentFireEnergy);
            game.getPlayer().getStats().setWaterEnergy(data.waterEnergy);
            game.getPlayer().getStats().setCurrentWaterEnergy(data.currentWaterEnergy);
            game.getPlayer().getStats().setNatureEnergy(data.natureEnergy);
            game.getPlayer().getStats().setCurrentNatureEnergy(data.currentNatureEnergy);

            Console.WriteLine("Zone number: " + data.currentPlayerZone);
            Console.WriteLine("Player level: " + data.currentPlayerLevel);
            Console.WriteLine("Position: " + data.playerPosition);

            loadRequested = false;
            Console.WriteLine("load completed");

            game.getGameState().setGameState();
            game.getKeyHandler().updateKeys(Keyboard.GetState());
        }
Exemple #23
0
        public TiltMain()
        {
            g = new globals();
            g.gravity = Direction.right;//what side is up. ->Don't start a room unless the direction matches that of the player.

            graphics = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth = 480,
                PreferredBackBufferHeight = 272
            };
            IAsyncResult r = Guide.BeginShowStorageDeviceSelector(null, null);
            while (!r.IsCompleted) { }
            storageDevice = Guide.EndShowStorageDeviceSelector(r);

            // Frame rate is 30 fps by default for Zune.
            TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);
        }
Exemple #24
0
 internal StorageContainer(StorageDevice device, string name, PlayerIndex? playerIndex)
 {
   if (string.IsNullOrEmpty(name))
     throw new ArgumentNullException("A title name has to be provided in parameter name.");
   this._device = device;
   this._name = name;
   this._playerIndex = playerIndex;
   this._storagePath = Path.Combine(Path.Combine(StorageDevice.StorageRoot, "SavedGames"), name);
   string str = string.Empty;
   if (playerIndex.HasValue)
     str = Path.Combine(this._storagePath, "Player" + (object) playerIndex.Value);
   if (!string.IsNullOrEmpty(str))
     this._storagePath = Path.Combine(this._storagePath, "Player" + (object) playerIndex.Value);
   if (Directory.Exists(this._storagePath))
     return;
   Directory.CreateDirectory(this._storagePath);
 }
Exemple #25
0
        void LoadFromDevice(IAsyncResult result)
        {
            device = StorageDevice.EndShowSelector(result);
            IAsyncResult r = device.BeginOpenContainer(ContainerName, null, null);
            result.AsyncWaitHandle.WaitOne();
            StorageContainer container = device.EndOpenContainer(r);
            result.AsyncWaitHandle.Close();
            if (container.FileExists(Filename))
            {
                Stream stream = container.OpenFile(Filename, FileMode.Open);
                XmlSerializer serializer = new XmlSerializer(typeof(SaveGame));
                SaveGame SaveData = (SaveGame)serializer.Deserialize(stream);
                stream.Close();
                container.Dispose();
                //Update the game based on the save game file

            }
            Replace();
        }
Exemple #26
0
        /// <summary>
        /// Delete the save game specified by the description.
        /// </summary>
        /// <param name="storageDevice">The chosen storage device.</param>
        /// <param name="saveGameDescription">The description of the save game.</param>
        public static void DeleteSaveGameResult(StorageDevice storageDevice, SaveGameDescription saveGameDescription)
        {
            if (saveGameDescription == null)
                throw new ArgumentNullException("saveGameDescription");

            if (storageDevice == null)
                throw new ArgumentNullException("storageDevice");

            if (!storageDevice.IsConnected)
                throw new InvalidOperationException("Cannot connect to storage device.");

            // open the container
            using (StorageContainer storageContainer = OpenContainer(storageDevice))
            {
                storageContainer.DeleteFile(saveGameDescription.FileName);
                storageContainer.DeleteFile("SaveGameDescription" +
                    Path.GetFileNameWithoutExtension(saveGameDescription.FileName).Substring(8) + ".xml");
            }
        }
        /// <summary>
        /// Loads the save when StorageDevice is ready.
        /// </summary>
        /// <param name="result">gives the StorageDevice to use</param>
        void LoadFromDevice(IAsyncResult result)
        {
            _device = StorageDevice.EndShowSelector(result);
            var r = _device.BeginOpenContainer(containerName, null, null);
            result.AsyncWaitHandle.WaitOne();
            var container = _device.EndOpenContainer(r);
            result.AsyncWaitHandle.Close();
            if (!container.FileExists(filename)) return;

            var stream = container.OpenFile(filename, FileMode.Open);
            var bfm = new BinaryFormatter();
            var saveData = (SaveData)bfm.Deserialize(stream);
            stream.Close();
            container.Dispose();

            //Update the game based on the save game file
            // Hero
            _inGame.Hero.gold = saveData.HeroData.gold;
            _inGame.Hero.Position = saveData.HeroData.Position;
            _inGame.Hero.CurrentMana = saveData.HeroData.CurrentMana;
            _inGame.Hero.CurrentHitPoints = saveData.HeroData.CurrentHitPoints;
            _inGame.Hero.MaxHitPoints = saveData.HeroData.MaxHitPoints;
            _inGame.Hero.MaxMana = saveData.HeroData.MaxMana;
            _inGame.Hero.exp = saveData.HeroData.exp;
            _inGame.Hero.level = saveData.HeroData.level;
            _inGame.Hero.tnl = saveData.HeroData.tnl;

            // mapGrid
            _inGame.mapGrid._tiles = saveData.mapgrid;
            _inGame.mapGrid.Initialize();

            // liveGrid
            _inGame._game.Components.Remove(_inGame.liveGrid);
            _inGame.liveGrid = new LiveGrid(_inGame._game, ref _inGame.mapGrid);
            _inGame._game.Components.Add(_inGame.liveGrid);

            // monsters
            UnserializeMonsters(saveData.MonstersData);

            // missiles
            UnserializeMissiles(saveData.MissilesData);
        }
Exemple #28
0
        public Storage()
        {
            PlayersLoaded = new ArrayList();
            result = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, null, null);
            Device = Guide.EndShowStorageDeviceSelector(result);

            // Open a storage container.
            StorageContainer container = Device.OpenContainer("Savegames");

            // Add the container path to our file name.
            string filename = Path.Combine(container.Path, "savegame.sav");

            // Create a new file.
            if (!File.Exists(filename))
            {
                FileStream file = File.Create(filename);
                file.Close();
            }
            // Dispose the container, to commit the data.
            container.Dispose();
        }
        void save(IAsyncResult result)
        {
            device = StorageDevice.EndShowSelector(result);
            if (device != null && device.IsConnected)
            {
                SaveLevelNames data = new SaveLevelNames();
                data.levelName = levelNames;
                data.timeScore = timeScores;
                data.hitsScore = hitsScores;

                IAsyncResult r = device.BeginOpenContainer("MyGamesStorage", null, null);
                StorageContainer container = device.EndOpenContainer(r);
                if (container.FileExists("ListofScores.sav"))
                    container.DeleteFile("ListofScores.sav");
                Stream stream = container.CreateFile("ListofScores.sav");
                XmlSerializer serializer = new XmlSerializer(typeof(SaveLevelNames));
                serializer.Serialize(stream, data);
                stream.Close();
                container.Dispose();
            }
        }
Exemple #30
0
        public void DoLoadGame(StorageDevice device)
        {
            // Open a storage container.
            IAsyncResult 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();

            string filename = "testlevel.txt";

            // 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);

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(testidata));
            testidata = (int)serializer.Deserialize(stream);

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

            // Dispose the container.
            container.Dispose();

            // Report the data to the console.
            Debug.WriteLine("Leveldata: " + testidata);
        }
        //
        // Summary:
        //     Ends the display of the storage selector user interface. Reference page contains
        //     links to related code samples.
        //
        // Parameters:
        //   result:
        //     The IAsyncResult returned from BeginShowSelector.
        public static StorageDevice EndShowSelector(IAsyncResult result)
        {
            StorageDevice returnValue = null;

            try {
                // Retrieve the delegate.
                AsyncResult asyncResult = (AsyncResult)result;

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

                // Call EndInvoke to retrieve the results.
                if (asyncResult.AsyncDelegate is ShowSelectorAsynchronousShow)
                {
                    returnValue = ((ShowSelectorAsynchronousShow)asyncResult.AsyncDelegate).EndInvoke(result);
                }
            } finally {
                // Close the wait handle.
                result.AsyncWaitHandle.Close();
            }

            return(returnValue);
        }
Exemple #32
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Microsoft.Xna.Framework.Storage.StorageContainer"/> class.
        /// </summary>
        /// <param name='device'>The attached storage-device.</param>
        /// <param name='name'> name.</param>
        /// <param name='playerIndex'>The player index of the player to save the data.</param>
        internal StorageContainer(StorageDevice device, string name, PlayerIndex?playerIndex)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("A title name has to be provided in parameter name.");
            }

            _device = device;
            _name   = name;

            // From the examples the root is based on MyDocuments folder
#if WINDOWS_STOREAPP
            var saved = "";
#elif LINUX || MONOMAC
            // We already have a SaveData folder on Mac/Linux.
            var saved = StorageDevice.StorageRoot;
#else
            var root  = StorageDevice.StorageRoot;
            var saved = Path.Combine(root, "SavedGames");
#endif
            _storagePath = Path.Combine(saved, name);

            var playerSave = string.Empty;
            if (playerIndex.HasValue)
            {
                playerSave = Path.Combine(_storagePath, "Player" + (int)playerIndex.Value);
            }

            if (!string.IsNullOrEmpty(playerSave))
            {
                _storagePath = Path.Combine(_storagePath, "Player" + (int)playerIndex);
            }

            // Create the "device" if need be
            CreateDirectoryAbsolute(_storagePath);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Microsoft.Xna.Framework.Storage.StorageContainer"/> class.
        /// </summary>
        /// <param name='_device'>
        /// _device.
        /// </param>
        /// <param name='_name'>
        /// _name.
        /// </param>
        /// <param name='playerIndex'>
        /// The player index of the player to save the data
        /// </param>
        internal StorageContainer(StorageDevice device, string name, PlayerIndex?playerIndex)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("A title name has to be provided in parameter name.");
            }

            _device      = device;
            _name        = name;
            _playerIndex = playerIndex;

            // From the examples the root is based on MyDocuments folder
            var root  = StorageDevice.StorageRoot;
            var saved = Path.Combine(root, "SavedGames");

            _storagePath = Path.Combine(saved, name);

            var playerSave = string.Empty;

            if (playerIndex.HasValue)
            {
                playerSave = Path.Combine(root, "Player" + (int)playerIndex.Value);
            }

            if (!string.IsNullOrEmpty(playerSave))
            {
                _storagePath = Path.Combine(root, "Player" + (int)playerIndex);
            }


            // Creathe the "device" if need be
            if (!Directory.Exists(_storagePath))
            {
                Directory.CreateDirectory(_storagePath);
            }
        }
Exemple #34
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageContainer"/> class.
        /// </summary>
        /// <param name='device'>The attached storage-device.</param>
        /// <param name='name'>The title's filename.</param>
        /// <param name='rootPath'>The path of the storage root folder</param>
        /// <param name='playerIndex'>
        /// The index of the player whose data is being saved, or null if data is for all
        /// players.
        /// </param>
        internal StorageContainer(
            StorageDevice device,
            string name,
            string rootPath,
            PlayerIndex?playerIndex
            )
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("A title name has to be provided in parameter name.");
            }

            StorageDevice = device;
            DisplayName   = name;

            /* There are two types of subfolders within a StorageContainer.
             * The first is a PlayerX folder, X being a specified PlayerIndex.
             * The second is AllPlayers, when PlayerIndex is NOT specified.
             * Basically, you should NEVER expect to have ANY file in the root
             * game save folder.
             * -flibit
             */
            storagePath = Path.Combine(
                rootPath,                               // Title folder (EXE name)...
                name,                                   // Container folder...
                playerIndex.HasValue ?                  // Player folder...
                ("Player" + ((int)playerIndex.Value + 1).ToString()) :
                "AllPlayers"
                );

            // Create the folders, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }
        }
Exemple #35
0
 public static IAsyncResult BeginShowSelector(PlayerIndex player, AsyncCallback callback, object state)
 {
     return(StorageDevice.BeginShowSelector(player, 0, 0, callback, state));
 }
Exemple #36
0
 public static IAsyncResult BeginShowSelector(AsyncCallback callback, object state)
 {
     return(StorageDevice.BeginShowSelector(0, 0, callback, state));
 }
Exemple #37
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StorageContainer"/> class.
        /// </summary>
        /// <param name='device'>The attached storage-device.</param>
        /// <param name='name'>The title's filename.</param>
        /// <param name='playerIndex'>
        /// The index of the player whose data is being saved, or null if data is for all
        /// players.
        /// </param>
        internal StorageContainer(
            StorageDevice device,
            string name,
            PlayerIndex?playerIndex
            )
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("A title name has to be provided in parameter name.");
            }

            StorageDevice = device;
            DisplayName   = name;

            string saved;

            if (Game.Instance.Platform.OSVersion.Equals("Windows"))
            {
                // The root on Windows is the "My Documents" folder
                saved = Path.Combine(StorageDevice.storageRoot, "SavedGames");
            }
            else if (Game.Instance.Platform.OSVersion.Equals("Mac OS X") ||
                     Game.Instance.Platform.OSVersion.Equals("Linux"))
            {
                // Unix-like systems are expected to have a dedicated userdata folder.
                saved = StorageDevice.storageRoot;
            }
            else
            {
                throw new Exception("StorageContainer: Platform.OSVersion not handled!");
            }
            storagePath = Path.Combine(
                saved,
                Path.GetFileNameWithoutExtension(
                    AppDomain.CurrentDomain.FriendlyName
                    )
                );

            // Create the root folder for all titles, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }

            storagePath = Path.Combine(storagePath, name);

            // Create the sub-folder for this container/title's files, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }

            /* There are two types of subfolders within a StorageContainer.
             * The first is a PlayerX folder, X being a specified PlayerIndex.
             * The second is AllPlayers, when PlayerIndex is NOT specified.
             * Basically, you should NEVER expect to have ANY file in the root
             * game save folder.
             * -flibit
             */
            if (playerIndex.HasValue)
            {
                storagePath = Path.Combine(storagePath, "Player" + ((int)playerIndex.Value + 1).ToString());
            }
            else
            {
                storagePath = Path.Combine(storagePath, "AllPlayers");
            }

            // Create the player folder, if needed.
            if (!Directory.Exists(storagePath))
            {
                Directory.CreateDirectory(storagePath);
            }
        }