/// <summary>
        /// Deletes the save file in the given save slot.
        /// </summary>
        /// <param name="saveSlot"></param>
        public void Delete(SaveSlot saveSlot)
        {
            StorageContainer container = SmileyUtil.GetStorageContainer();

            container.DeleteFile(saveSlot.GetDescription());

            Saves[saveSlot] = new SaveFile(saveSlot.GetDescription())
            {
                IsEmpty = true
            };
        }
        /// <summary>
        /// Saves the current configuration data.
        /// </summary>
        public void SaveConfig()
        {
            StorageContainer container = SmileyUtil.GetStorageContainer();

            container.DeleteFile(ConfigFile);
            using (Stream stream = container.OpenFile(ConfigFile, FileMode.Create))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SmileyConfig));
                serializer.Serialize(stream, _config);
            }
        }
        /// <summary>
        /// Loads the save file with the given file name, or returns an empty save
        /// if the file doens't exist.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private SaveFile LoadFile(string fileName)
        {
            SaveFile file = new SaveFile(fileName);

            StorageContainer container = SmileyUtil.GetStorageContainer();

            if (!container.FileExists(fileName))
            {
                file.IsEmpty = true;
                return(file);
            }

            //Select the specified save file
            using (BitStream input = new BitStream(container, fileName, BitStreamMode.Read))
            {
                file.TimePlayed = TimeSpan.FromTicks(input.ReadBits(64));

                //Load abilties
                foreach (Ability ability in Enum.GetValues(typeof(Ability)))
                {
                    file.HasAbility[ability] = input.ReadBit();
                }

                //Load keys
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        file.NumKeys[i, j] = input.ReadByte();
                    }
                }

                //Load gems
                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    foreach (Gem gem in Enum.GetValues(typeof(Gem)))
                    {
                        file.NumGems[level][gem] = input.ReadByte();
                    }
                }

                //Load money
                file.Money = input.ReadByte();

                //Load upgrades
                foreach (Upgrade upgrade in Enum.GetValues(typeof(Upgrade)))
                {
                    file.NumUpgrades[upgrade] = input.ReadByte();
                }

                //Load which bosses have been slain
                foreach (Boss boss in Enum.GetValues(typeof(Boss)))
                {
                    file.HasKilledBoss[boss] = input.ReadBit();
                }

                //Load player zone and location
                file.Level       = (Level)input.ReadByte();
                file.PlayerGridX = input.ReadByte();
                file.PlayerGridY = input.ReadByte();

                //Health and mana
                file.PlayerHealth = (float)(input.ReadByte() / 4);
                file.PlayerMana   = (float)(input.ReadByte());

                //Load changed shit
                int numChanges = input.ReadBits(16);
                for (int i = 0; i < numChanges; i++)
                {
                    file.ChangeTile((Level)input.ReadByte(), input.ReadByte(), input.ReadByte());
                }

                //Load Stats
                file.NumTongueLicks   = input.ReadByte();
                file.NumEnemiesKilled = input.ReadByte();
                file.PixelsTraversed  = input.ReadBits(24);

                //Tutorial Man
                file.AdviceManEncounterCompleted = input.ReadBit();

                for (int i = 0; i < 3; i++)
                {
                    SMH.GUI.SetAbilityInSlot((Ability)input.ReadBits(5), i);
                }

                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    file.HasVisitedLevel[level] = input.ReadBit();
                }

                file.Difficulty = (Difficulty)input.ReadByte();

                //Exploration data
                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    for (int j = 0; j < 256; j++)
                    {
                        for (int k = 0; k < 256; k++)
                        {
                            file.Explored[level][j, k] = input.ReadBit();
                        }
                    }
                }
            }

            file.TimeFileLoaded = DateTime.Now.TimeOfDay;

            return(file);
        }
        private void SaveFile(SaveFile file)
        {
            using (BitStream output = new BitStream(SmileyUtil.GetStorageContainer(), file.Name, BitStreamMode.Write))
            {
                output.WriteBits(file.TimePlayed.Ticks, 64);

                //Save abilties
                foreach (Ability ability in Enum.GetValues(typeof(Ability)))
                {
                    output.WriteBit(file.HasAbility[ability]);
                }

                //Save keys
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        output.WriteByte(file.NumKeys[i, j]);
                    }
                }

                //Save gems
                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    foreach (Gem gem in Enum.GetValues(typeof(Gem)))
                    {
                        output.WriteByte(file.NumGems[level][gem]);
                    }
                }

                //Save money
                output.WriteByte(file.Money);

                //Save upgrades
                foreach (Upgrade upgrade in Enum.GetValues(typeof(Upgrade)))
                {
                    output.WriteByte(file.NumUpgrades[upgrade]);
                }

                //Save which bosses have been slain
                foreach (Boss boss in Enum.GetValues(typeof(Boss)))
                {
                    output.WriteBit(file.HasKilledBoss[boss]);
                }

                //Save player zone and location
                output.WriteByte((int)file.Level);
                output.WriteByte(file.PlayerGridX);
                output.WriteByte(file.PlayerGridY);

                //Health and mana
                output.WriteByte((int)file.PlayerHealth * 4);
                output.WriteByte((int)file.PlayerMana);

                //Load changed shit
                file.SaveChanges(output);

                //Load Stats
                output.WriteByte(file.NumTongueLicks);
                output.WriteByte(file.NumEnemiesKilled);
                output.WriteBits(file.PixelsTraversed, 24);

                //Tutorial Man
                output.WriteBit(file.AdviceManEncounterCompleted);

                for (int i = 0; i < 3; i++)
                {
                    output.WriteBits((int)SMH.GUI.GetAbilityInSlot(i), 5);
                }

                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    output.WriteBit(file.HasVisitedLevel[level]);
                }

                output.WriteByte((int)file.Difficulty);

                //Exploration data
                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    for (int j = 0; j < 256; j++)
                    {
                        for (int k = 0; k < 256; k++)
                        {
                            output.WriteBit(file.Explored[level][j, k]);
                        }
                    }
                }

                file.TimePlayed.Add(DateTime.Now.TimeOfDay.Subtract(file.TimeFileLoaded));
                output.WriteBits(file.TimePlayed.Ticks, 64);
            }
        }