Example #1
0
        private bool SaveThreadRoutine(string filename)
        {
#if !DEBUG
            try
            {
#endif
            System.Threading.Thread.CurrentThread.Name = "Save";
            // Ensure we're using the invariant culture.
            System.Threading.Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            DirectoryInfo worldDirectory =
                Directory.CreateDirectory(DwarfGame.GetWorldDirectory() +
                                          Path.DirectorySeparatorChar + Overworld.Name);

            // This is a hack. Why does the overworld have this as a static field??
            Overworld.NativeFactions = this.Natives;
            NewOverworldFile file = new NewOverworldFile(Game.GraphicsDevice, Overworld.Map, Overworld.Name, SeaLevel);
            file.WriteFile(worldDirectory.FullName);

            try
            {
                file.SaveScreenshot(worldDirectory.FullName + Path.DirectorySeparatorChar + "screenshot.png");
            }
            catch (Exception exception)
            {
                Console.Error.WriteLine(exception.ToString());
            }

            gameFile = SaveGame.CreateFromWorld(this);
            var path = DwarfGame.GetSaveDirectory() + Path.DirectorySeparatorChar +
                       filename;
            SaveGame.DeleteOldestSave(path, GameSettings.Default.MaxSaves, "Autosave");
            gameFile.WriteFile(path);
            ComponentManager.CleanupSaveData();

            lock (ScreenshotLock)
            {
                Screenshots.Add(new Screenshot()
                {
                    FileName = DwarfGame.GetSaveDirectory() +
                               Path.DirectorySeparatorChar + filename + Path.DirectorySeparatorChar +
                               "screenshot.png",
                    Resolution = new Point(128, 128)
                });
            }
#if !DEBUG
        }

        catch (Exception exception)
        {
            Console.Error.Write(exception.ToString());
            Game.CaptureException(exception);
            throw new WaitStateException(exception.Message);
        }
#endif
            return(true);
        }
        private bool SaveThreadRoutine()
        {
#if !DEBUG
            try
            {
#endif
            Thread.CurrentThread.Name = "Save";
            // Ensure we're using the invariant culture.
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            var worldDirectory = Directory.CreateDirectory(DwarfGame.GetWorldDirectory() + Path.DirectorySeparatorChar + Overworld.Name);

            var file = new NewOverworldFile(Game.GraphicsDevice, Overworld);
            file.WriteFile(worldDirectory.FullName);

            var gameFile = SaveGame.CreateFromWorld(this);
            var path     = worldDirectory.FullName + Path.DirectorySeparatorChar + String.Format("{0}-{1}", (int)Overworld.InstanceSettings.Origin.X, (int)Overworld.InstanceSettings.Origin.Y);
            SaveGame.DeleteOldestSave(path, GameSettings.Current.MaxSaves, "Autosave");
            gameFile.WriteFile(path);
            ComponentManager.CleanupSaveData();

            lock (Renderer.ScreenshotLock)
            {
                Renderer.Screenshots.Add(new WorldRenderer.Screenshot()
                {
                    FileName   = path + Path.DirectorySeparatorChar + "screenshot.png",
                    Resolution = new Point(128, 128)
                });
            }

#if !DEBUG
        }

        catch (Exception exception)
        {
            Console.Error.Write(exception.ToString());
            Program.CaptureException(exception);
            throw new WaitStateException(exception.Message);
        }
#endif
            return(true);
        }