Ejemplo n.º 1
0
        public static bool Prefix(ScribeSaver __instance, string filePath, string documentElementName)
        {
            if (!Enable)
            {
                return(true);
            }

            Loger.Log("ScribeSaver_InitSaving_Patch Start");
            var that = Traverse.Create(__instance);

            if (Scribe.mode != 0)
            {
                Log.Error("Called InitSaving() but current mode is " + Scribe.mode);
                Scribe.ForceStop();
            }
            if (that.Field("curPath").GetValue <string>() != null)
            {
                Log.Error("Current path is not null in InitSaving");
                that.Field("curPath").SetValue(null);
                that.Field("savedNodes").GetValue <HashSet <string> >().Clear();
                that.Field("nextListElementTemporaryId").SetValue(0);
            }
            try
            {
                Scribe.mode = LoadSaveMode.Saving;
                var saveStream = SaveData = new MemoryStream();
                //var saveStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None);
                File.WriteAllText(filePath, "Online save");
                that.Field("saveStream").SetValue(saveStream);

                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent      = true;
                xmlWriterSettings.IndentChars = "\t";
                var writer = XmlWriter.Create(saveStream, xmlWriterSettings);
                that.Field("writer").SetValue(writer);

                writer.WriteStartDocument();
                __instance.EnterNode(documentElementName);
            }
            catch (Exception ex)
            {
                Log.Error("Exception while init saving file: " + filePath + "\n" + ex);
                __instance.ForceStop();
                throw;
            }
            Loger.Log("ScribeSaver_InitSaving_Patch End");
            return(false);
        }
Ejemplo n.º 2
0
 public static void ForceStop()
 {
     mode = LoadSaveMode.Inactive;
     saver.ForceStop();
     loader.ForceStop();
 }