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