Exemplo n.º 1
0
 public static void Save()
 {
     try
     {
         Dictionary <string, KeyBindingData> dictionary = new Dictionary <string, KeyBindingData>();
         foreach (KeyValuePair <KeyBindingDef, KeyBindingData> current in KeyPrefs.data.keyPrefs)
         {
             dictionary[current.Key.defName] = current.Value;
         }
         foreach (KeyValuePair <string, KeyBindingData> current2 in KeyPrefs.unresolvedBindings)
         {
             try
             {
                 dictionary.Add(current2.Key, current2.Value);
             }
             catch (ArgumentException)
             {
             }
         }
         XDocument xDocument = new XDocument();
         XElement  content   = DirectXmlSaver.XElementFromObject(dictionary, typeof(KeyPrefsData));
         xDocument.Add(content);
         xDocument.Save(GenFilePaths.KeyPrefsFilePath);
     }
     catch (Exception ex)
     {
         GenUI.ErrorDialog("ProblemSavingFile".Translate(new object[]
         {
             GenFilePaths.KeyPrefsFilePath,
             ex.ToString()
         }));
         Log.Error("Exception saving keyprefs: " + ex, false);
     }
 }
Exemplo n.º 2
0
 public static void SaveDataObject(object obj, string filePath)
 {
     try
     {
         XDocument xDocument = new XDocument();
         XElement  content   = DirectXmlSaver.XElementFromObject(obj, obj.GetType());
         xDocument.Add(content);
         xDocument.Save(filePath);
     }
     catch (Exception ex)
     {
         Log.Error(string.Concat(new object[]
         {
             "Exception saving data object ",
             obj.ToStringSafe <object>(),
             ": ",
             ex
         }), false);
         GenUI.ErrorDialog("ProblemSavingFile".Translate(new object[]
         {
             filePath,
             ex.ToString()
         }));
     }
 }
Exemplo n.º 3
0
 public static void Save(string path, string documentElementName, Action saveAction, bool leaveOldFile = false)
 {
     try
     {
         CleanSafeSaverFiles(path);
         if (!File.Exists(GetFileFullPath(path)))
         {
             DoSave(GetFileFullPath(path), documentElementName, saveAction);
         }
         else
         {
             DoSave(GetNewFileFullPath(path), documentElementName, saveAction);
             try
             {
                 SafeMove(GetFileFullPath(path), GetOldFileFullPath(path));
             }
             catch (Exception ex)
             {
                 Log.Warning("Could not move file from \"" + GetFileFullPath(path) + "\" to \"" + GetOldFileFullPath(path) + "\": " + ex);
                 throw;
             }
             try
             {
                 SafeMove(GetNewFileFullPath(path), GetFileFullPath(path));
             }
             catch (Exception ex2)
             {
                 Log.Warning("Could not move file from \"" + GetNewFileFullPath(path) + "\" to \"" + GetFileFullPath(path) + "\": " + ex2);
                 RemoveFileIfExists(GetFileFullPath(path), rethrow: false);
                 RemoveFileIfExists(GetNewFileFullPath(path), rethrow: false);
                 try
                 {
                     SafeMove(GetOldFileFullPath(path), GetFileFullPath(path));
                 }
                 catch (Exception ex3)
                 {
                     Log.Warning("Could not move file from \"" + GetOldFileFullPath(path) + "\" back to \"" + GetFileFullPath(path) + "\": " + ex3);
                 }
                 throw;
             }
             if (!leaveOldFile)
             {
                 RemoveFileIfExists(GetOldFileFullPath(path), rethrow: true);
             }
         }
     }
     catch (Exception ex4)
     {
         GenUI.ErrorDialog("ProblemSavingFile".Translate(GetFileFullPath(path), ex4.ToString()));
         throw;
     }
 }
Exemplo n.º 4
0
 public static void Save()
 {
     try
     {
         XDocument xDocument = new XDocument();
         XElement  content   = DirectXmlSaver.XElementFromObject(Prefs.data, typeof(PrefsData));
         xDocument.Add(content);
         xDocument.Save(GenFilePaths.PrefsFilePath);
     }
     catch (Exception ex)
     {
         GenUI.ErrorDialog("ProblemSavingFile".Translate(GenFilePaths.PrefsFilePath, ex.ToString()));
         Log.Error("Exception saving prefs: " + ex, false);
     }
 }
Exemplo n.º 5
0
 public static void SaveDataObject(object obj, string filePath)
 {
     try
     {
         XDocument xDocument = new XDocument();
         XElement  content   = XElementFromObject(obj, obj.GetType());
         xDocument.Add(content);
         xDocument.Save(filePath);
     }
     catch (Exception ex)
     {
         Log.Error("Exception saving data object " + obj.ToStringSafe() + ": " + ex);
         GenUI.ErrorDialog("ProblemSavingFile".Translate(filePath, ex.ToString()));
     }
 }
Exemplo n.º 6
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(string.Concat(new object[]
                 {
                     "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(string.Concat(new object[]
                 {
                     "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(string.Concat(new object[]
                     {
                         "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(new object[]
         {
             SafeSaver.GetFileFullPath(path),
             ex4.ToString()
         }));
         throw;
     }
 }