예제 #1
0
        /// <summary>
        /// Save the state of this game to disk.
        /// </summary>
        public void SaveState()
        {
            if (!this.initialized)
            {
                throw new InvalidOperationException("Storage not yet Added to the game.");
            }
            Directory.CreateDirectory(this.path);
            Storage.LastSaved = DateTime.Now;

            EntryList entries = new EntryList();

            foreach (Saved save in this.saves)
            {
                entries.Add(save);
            }

            if (File.Exists(this.statefile))
            {
                EntryList prev = RawRead();
                if (prev != null)
                {
                    entries = EntryList.Merge(prev, entries);
                }
            }
            Stream     f         = new GZipStream(new FileStream(this.statefile, FileMode.Create), CompressionLevel.Fastest);
            IFormatter formatter = this.CreateFormatter();

            formatter.Serialize(f, entries.Export());
            f.Close();
        }