示例#1
0
        public static string GetLatestSaveFile()
        {
            DirectoryInfo saveDirectory = Directory.CreateDirectory(DwarfGame.GetSaveDirectory());

            DirectoryInfo newest = null;

            foreach (var dir in saveDirectory.EnumerateDirectories())
            {
                if (newest == null || newest.CreationTime < dir.CreationTime)
                {
                    var valid = false;
                    try
                    {
                        var saveGame = SaveGame.CreateFromDirectory(dir.FullName);
                        valid = Program.CompatibleVersions.Contains(saveGame.Metadata.Version);
                    }
                    catch (Exception e)
                    { }

                    if (valid)
                    {
                        newest = dir;
                    }
                }
            }

            return(newest == null ? null : newest.FullName);
        }
示例#2
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);
        }