Beispiel #1
0
 public static void Save(string path, string documentElementName, Action saveAction)
 {
     try
     {
         SafeSaver.CleanSafeSaverFiles(path);
         if (!File.Exists(SafeSaver.GetFileFullPath(path)))
         {
             SafeSaver.DoSave(SafeSaver.GetFileFullPath(path), documentElementName, saveAction);
         }
         else
         {
             SafeSaver.DoSave(SafeSaver.GetNewFileFullPath(path), documentElementName, saveAction);
             try
             {
                 SafeSaver.SafeMove(SafeSaver.GetFileFullPath(path), SafeSaver.GetOldFileFullPath(path));
             }
             catch (Exception ex)
             {
                 Log.Warning("Could not move file from \"" + SafeSaver.GetFileFullPath(path) + "\" to \"" + SafeSaver.GetOldFileFullPath(path) + "\": " + ex);
                 throw;
             }
             try
             {
                 SafeSaver.SafeMove(SafeSaver.GetNewFileFullPath(path), SafeSaver.GetFileFullPath(path));
             }
             catch (Exception ex2)
             {
                 Log.Warning("Could not move file from \"" + SafeSaver.GetNewFileFullPath(path) + "\" to \"" + SafeSaver.GetFileFullPath(path) + "\": " + ex2);
                 SafeSaver.RemoveFileIfExists(SafeSaver.GetFileFullPath(path), false);
                 SafeSaver.RemoveFileIfExists(SafeSaver.GetNewFileFullPath(path), false);
                 try
                 {
                     SafeSaver.SafeMove(SafeSaver.GetOldFileFullPath(path), SafeSaver.GetFileFullPath(path));
                 }
                 catch (Exception ex3)
                 {
                     Log.Warning("Could not move file from \"" + SafeSaver.GetOldFileFullPath(path) + "\" back to \"" + SafeSaver.GetFileFullPath(path) + "\": " + ex3);
                 }
                 throw;
             }
             SafeSaver.RemoveFileIfExists(SafeSaver.GetOldFileFullPath(path), true);
         }
     }
     catch (Exception ex4)
     {
         GenUI.ErrorDialog("ProblemSavingFile".Translate(SafeSaver.GetFileFullPath(path), ex4.ToString()));
         throw;
     }
 }
 public static void SaveScenario(Scenario scen, string absFilePath)
 {
     try
     {
         scen.fileName = Path.GetFileNameWithoutExtension(absFilePath);
         SafeSaver.Save(absFilePath, "savedscenario", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Scribe_Deep.Look <Scenario>(ref scen, "scenario", new object[0]);
         }, false);
     }
     catch (Exception ex)
     {
         Log.Error("Exception while saving world: " + ex.ToString(), false);
     }
 }
Beispiel #3
0
 private static void DoSave(string fullPath, string documentElementName, Action saveAction)
 {
     try
     {
         Scribe.saver.InitSaving(fullPath, documentElementName);
         saveAction();
         Scribe.saver.FinalizeSaving();
     }
     catch (Exception ex)
     {
         Log.Warning("An exception was thrown during saving to \"" + fullPath + "\": " + ex);
         Scribe.saver.ForceStop();
         SafeSaver.RemoveFileIfExists(fullPath, false);
         throw;
     }
 }
Beispiel #4
0
 public static void SaveGame(string fileName)
 {
     try
     {
         SafeSaver.Save(GenFilePaths.FilePathForSavedGame(fileName), "savegame", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Game target = Current.Game;
             Scribe_Deep.Look(ref target, "game");
         }, Find.GameInfo.permadeathMode);
         lastSaveTick = Find.TickManager.TicksGame;
     }
     catch (Exception arg)
     {
         Log.Error("Exception while saving game: " + arg);
     }
 }
 public static void SaveGame(string fileName)
 {
     try
     {
         string path = GenFilePaths.FilePathForSavedGame(fileName);
         SafeSaver.Save(path, "savegame", delegate
         {
             ScribeMetaHeaderUtility.WriteMetaHeader();
             Game game = Current.Game;
             Scribe_Deep.Look <Game>(ref game, "game", new object[0]);
         }, Find.GameInfo.permadeathMode);
         GameDataSaveLoader.lastSaveTick = Find.TickManager.TicksGame;
     }
     catch (Exception arg)
     {
         Log.Error("Exception while saving game: " + arg, false);
     }
 }
Beispiel #6
0
 private static void CleanSafeSaverFiles(string path)
 {
     SafeSaver.RemoveFileIfExists(SafeSaver.GetOldFileFullPath(path), true);
     SafeSaver.RemoveFileIfExists(SafeSaver.GetNewFileFullPath(path), true);
 }