예제 #1
0
 public static bool TryLoadScenario(string absPath, ScenarioCategory category, out Scenario scen)
 {
     scen = null;
     try
     {
         Scribe.loader.InitLoading(absPath);
         try
         {
             ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Scenario, true);
             Scribe_Deep.Look <Scenario>(ref scen, "scenario", new object[0]);
             Scribe.loader.FinalizeLoading();
         }
         catch
         {
             Scribe.ForceStop();
             throw;
         }
         scen.fileName = Path.GetFileNameWithoutExtension(new FileInfo(absPath).Name);
         scen.Category = category;
     }
     catch (Exception ex)
     {
         Log.Error("Exception loading scenario: " + ex.ToString(), false);
         scen = null;
         Scribe.ForceStop();
     }
     return(scen != null);
 }
예제 #2
0
 public void InitLoading(string filePath)
 {
     if (Scribe.mode != 0)
     {
         Log.Error("Called InitLoading() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     if (curParent != null)
     {
         Log.Error("Current parent is not null in InitLoading");
         curParent = null;
     }
     if (curPathRelToParent != null)
     {
         Log.Error("Current path relative to parent is not null in InitLoading");
         curPathRelToParent = null;
     }
     try
     {
         using (StreamReader input = new StreamReader(filePath))
         {
             using XmlTextReader reader = new XmlTextReader(input);
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.Load(reader);
             curXmlParent = xmlDocument.DocumentElement;
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error("Exception while init loading file: " + filePath + "\n" + ex);
         ForceStop();
         throw;
     }
 }
예제 #3
0
 public void InitLoadingMetaHeaderOnly(string filePath)
 {
     if (Scribe.mode != 0)
     {
         Log.Error("Called InitLoadingMetaHeaderOnly() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     try
     {
         using (StreamReader input = new StreamReader(filePath))
         {
             using XmlTextReader xmlTextReader = new XmlTextReader(input);
             if (!ScribeMetaHeaderUtility.ReadToMetaElement(xmlTextReader))
             {
                 return;
             }
             using XmlReader reader = xmlTextReader.ReadSubtree();
             XmlDocument xmlDocument = new XmlDocument();
             xmlDocument.Load(reader);
             XmlElement xmlElement = xmlDocument.CreateElement("root");
             xmlElement.AppendChild(xmlDocument.DocumentElement);
             curXmlParent = xmlElement;
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error("Exception while init loading meta header: " + filePath + "\n" + ex);
         ForceStop();
         throw;
     }
 }
예제 #4
0
 public void InitSaving(string filePath, string documentElementName)
 {
     if (Scribe.mode != 0)
     {
         Log.Error("Called InitSaving() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     if (curPath != null)
     {
         Log.Error("Current path is not null in InitSaving");
         curPath = null;
         savedNodes.Clear();
         nextListElementTemporaryId = 0;
     }
     try
     {
         Scribe.mode = LoadSaveMode.Saving;
         saveStream  = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
         XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
         xmlWriterSettings.Indent      = true;
         xmlWriterSettings.IndentChars = "\t";
         writer = XmlWriter.Create(saveStream, xmlWriterSettings);
         writer.WriteStartDocument();
         EnterNode(documentElementName);
     }
     catch (Exception ex)
     {
         Log.Error("Exception while init saving file: " + filePath + "\n" + ex);
         ForceStop();
         throw;
     }
 }
        public static void LoadGameFromSaveFile(string fileName)
        {
            string str = GenText.ToCommaList(from mod in LoadedModManager.RunningMods
                                             select mod.ToString(), true);

            Log.Message("Loading game from file " + fileName + " with mods " + str);
            DeepProfiler.Start("Loading game from file " + fileName);
            Current.Game = new Game();
            DeepProfiler.Start("InitLoading (read file)");
            Scribe.loader.InitLoading(GenFilePaths.FilePathForSavedGame(fileName));
            DeepProfiler.End();
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
            if (Scribe.EnterNode("game"))
            {
                Current.Game = new Game();
                Current.Game.LoadGame();
                PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
                DeepProfiler.End();
            }
            else
            {
                Log.Error("Could not find game XML node.");
                Scribe.ForceStop();
            }
        }
예제 #6
0
 public void InitSaving(string filePath, string documentElementName)
 {
     if (Scribe.mode != LoadSaveMode.Inactive)
     {
         Log.Error("Called InitSaving() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     try
     {
         Scribe.mode     = LoadSaveMode.Saving;
         this.saveStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
         XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
         xmlWriterSettings.Indent      = true;
         xmlWriterSettings.IndentChars = "\t";
         this.writer = XmlWriter.Create(this.saveStream, xmlWriterSettings);
         this.writer.WriteStartDocument();
         this.EnterNode(documentElementName);
     }
     catch (Exception ex)
     {
         Log.Error(string.Concat(new object[]
         {
             "Exception while init saving file: ",
             filePath,
             "\n",
             ex
         }));
         this.ForceStop();
         throw;
     }
 }
예제 #7
0
        public static void LoadGameFromSaveFileNow(string fileName)
        {
            string str = (from mod in LoadedModManager.RunningMods
                          select mod.ToString()).ToCommaList();

            Log.Message("Loading game from file " + fileName + " with mods " + str);
            DeepProfiler.Start("Loading game from file " + fileName);
            Current.Game = new Game();
            DeepProfiler.Start("InitLoading (read file)");
            Scribe.loader.InitLoading(GenFilePaths.FilePathForSavedGame(fileName));
            DeepProfiler.End();
            try
            {
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, logVersionConflictWarning: true);
                if (!Scribe.EnterNode("game"))
                {
                    Log.Error("Could not find game XML node.");
                    Scribe.ForceStop();
                    return;
                }
                Current.Game = new Game();
                Current.Game.LoadGame();
            }
            catch (Exception)
            {
                Scribe.ForceStop();
                throw;
            }
            PermadeathModeUtility.CheckUpdatePermadeathModeUniqueNameOnGameLoad(fileName);
            DeepProfiler.End();
        }
예제 #8
0
        public static void ErrorWhileLoadingGame(Exception e)
        {
            string text = "ErrorWhileLoadingMap".Translate();

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out string loadedModsSummary, out string runningModsSummary))
            {
                text += "\n\n" + "ModsMismatchWarningText".Translate(loadedModsSummary, runningModsSummary);
            }
            DelayedErrorWindowRequest.Add(text, "ErrorWhileLoadingMapTitle".Translate());
            Scribe.ForceStop();
            GenScene.GoToMainMenu();
        }
예제 #9
0
        public static void ErrorWhileLoadingGame(Exception e)
        {
            string text  = "ErrorWhileLoadingMap".Translate();
            string text2 = default(string);
            string text3 = default(string);

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out text2, out text3))
            {
                text = text + "\n\n" + "ModsMismatchWarningText".Translate(text2, text3);
            }
            DelayedErrorWindowRequest.Add(text, "ErrorWhileLoadingMapTitle".Translate());
            Scribe.ForceStop();
            GenScene.GoToMainMenu();
        }
예제 #10
0
 public static void CheckVersionAndLoad(string path, ScribeMetaHeaderUtility.ScribeHeaderMode mode, Action loadAct)
 {
     try
     {
         Scribe.loader.InitLoadingMetaHeaderOnly(path);
         ScribeMetaHeaderUtility.LoadGameDataHeader(mode, logVersionConflictWarning: false);
         Scribe.loader.FinalizeLoading();
     }
     catch (Exception ex)
     {
         Log.Warning("Exception loading " + path + ": " + ex);
         Scribe.ForceStop();
     }
     if (!ScribeMetaHeaderUtility.TryCreateDialogsForVersionMismatchWarnings(loadAct))
     {
         loadAct();
     }
 }
예제 #11
0
 public void InitLoading(string filePath)
 {
     if (Scribe.mode != LoadSaveMode.Inactive)
     {
         Log.Error("Called InitLoading() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     if (this.curParent != null)
     {
         Log.Error("Current parent is not null in InitLoading");
         this.curParent = null;
     }
     if (this.curPathRelToParent != null)
     {
         Log.Error("Current path relative to parent is not null in InitLoading");
         this.curPathRelToParent = null;
     }
     try
     {
         using (StreamReader streamReader = new StreamReader(filePath))
         {
             using (XmlTextReader xmlTextReader = new XmlTextReader(streamReader))
             {
                 XmlDocument xmlDocument = new XmlDocument();
                 xmlDocument.Load(xmlTextReader);
                 this.curXmlParent = xmlDocument.DocumentElement;
             }
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error(string.Concat(new object[]
         {
             "Exception while init loading file: ",
             filePath,
             "\n",
             ex
         }));
         this.ForceStop();
         throw;
     }
 }
예제 #12
0
 public void InitLoadingMetaHeaderOnly(string filePath)
 {
     if (Scribe.mode != LoadSaveMode.Inactive)
     {
         Log.Error("Called InitLoadingMetaHeaderOnly() but current mode is " + Scribe.mode);
         Scribe.ForceStop();
     }
     try
     {
         using (StreamReader streamReader = new StreamReader(filePath))
         {
             using (XmlTextReader xmlTextReader = new XmlTextReader(streamReader))
             {
                 if (!ScribeMetaHeaderUtility.ReadToMetaElement(xmlTextReader))
                 {
                     return;
                 }
                 using (XmlReader xmlReader = xmlTextReader.ReadSubtree())
                 {
                     XmlDocument xmlDocument = new XmlDocument();
                     xmlDocument.Load(xmlReader);
                     XmlElement xmlElement = xmlDocument.CreateElement("root");
                     xmlElement.AppendChild(xmlDocument.DocumentElement);
                     this.curXmlParent = xmlElement;
                 }
             }
         }
         Scribe.mode = LoadSaveMode.LoadingVars;
     }
     catch (Exception ex)
     {
         Log.Error(string.Concat(new object[]
         {
             "Exception while init loading meta header: ",
             filePath,
             "\n",
             ex
         }));
         this.ForceStop();
         throw;
     }
 }
예제 #13
0
 public static void CheckVersionAndLoad(string path, ScribeMetaHeaderUtility.ScribeHeaderMode mode, Action loadAct)
 {
     try
     {
         Scribe.loader.InitLoadingMetaHeaderOnly(path);
         ScribeMetaHeaderUtility.LoadGameDataHeader(mode, false);
         Scribe.loader.FinalizeLoading();
     }
     catch (Exception ex)
     {
         Log.Warning(string.Concat(new object[]
         {
             "Exception loading ",
             path,
             ": ",
             ex
         }), false);
         Scribe.ForceStop();
     }
     if (!ScribeMetaHeaderUtility.TryCreateDialogsForVersionMismatchWarnings(loadAct))
     {
         loadAct();
     }
 }
예제 #14
0
 public static void ErrorWhileGeneratingMap(Exception e)
 {
     DelayedErrorWindowRequest.Add("ErrorWhileGeneratingMap".Translate(), "ErrorWhileGeneratingMapTitle".Translate());
     Scribe.ForceStop();
     GenScene.GoToMainMenu();
 }