Beispiel #1
0
        public static PathDataLog LoadFromFile(string filename)
        {
            var pathData = new PathDataLog();

            try
            {
                Scribe.InitLoading(filename);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("PathData");
                pathData.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            return(pathData);
        }
        /// <summary>
        /// Read a save file
        /// </summary>
        /// <param name="filepath">The path to the savefile</param>
        private static void Read(string filepath)
        {
            Main.LogDebug("reading {0}", filepath);

            Scribe.SaveState();
            Scribe.InitLoadingMetaHeaderOnly(filepath);
            ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
            importList = ScribeMetaHeaderUtility.loadedModIdsList;
            Scribe.FinalizeLoading();
            Scribe.RestoreState();
        }
        private void DoImport(SaveFileInfo file)
        {
            try
            {
                // load stuff
                Scribe.InitLoading(_folder + "/" + file.FileInfo.Name);
                Manager.LoadSaveMode = Manager.Modes.ImportExport;
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("JobStack");
                _jobStackIO.ExposeData();
                Scribe.ExitNode();
                Scribe.FinalizeLoading();

                // resolve crossreferences
                // these are registered during the loading stage, and cleared afterwards
                // will most definitely give errors/warnings on crossgame imports
                CrossRefResolver.ResolveAllCrossReferences();

                // replace the old jobstack
                Manager.For(manager).NewJobStack(_jobStackIO);

                // remove invalid jobs
                var invalid = 0;
                foreach (ManagerJob job in Manager.For(manager).JobStack.FullStack())
                {
                    if (!job.IsValid)
                    {
                        invalid++;
                        job.Delete(false);
                    }
                }

                // provide some feedback on failed import(s)
                // if debug is enabled the screen will also pop up with reference errors.
                if (invalid > 0)
                {
                    Messages.Message("FM.InvalidJobsDeleted".Translate(invalid), MessageSound.SeriousAlert);
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading jobstack: " + e);
            }
            finally
            {
                // done?
                Scribe.mode          = LoadSaveMode.Inactive;
                Manager.LoadSaveMode = Manager.Modes.Normal;
                Messages.Message("FM.JobsImported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
        internal static Blueprint LoadFromXML(SaveFileInfo file)
        {
            // set up empty blueprint
            Blueprint blueprint = new Blueprint();

#if DEBUG
            Log.Message("Attempting to load from: " + file.FileInfo.FullName);
#endif

            // load stuff
            try
            {
                Scribe.InitLoading(BlueprintSaveLocation + "/" + file.FileInfo.Name);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
                Scribe.EnterNode("Blueprint");
                blueprint.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading blueprint: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            // if a def used in the blueprint doesn't exist, exposeData will throw an error,
            // which is fine. in addition, it'll set the field to null - which may result in problems down the road.
            // Make sure each item in the blueprint has a def set, if not - remove it.
            // This check itself will throw another error, which is also fine. User will have to resolve the issue manually.
            blueprint.contents = blueprint.contents.Where(item => item.BuildableDef != null).ToList();

            // return blueprint.
            return(blueprint);
        }
Beispiel #5
0
        public static void LoadHostData(MCMHost host)
        {
            var filePath = HostFilePath(host);

            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                // Open it for reading
                Scribe.InitLoading(filePath);
                if (Scribe.mode == LoadSaveMode.LoadingVars)
                {
                    // Version check
                    string version = "";
                    Scribe_Values.LookValue <string>(ref version, "ccl_version");

                    bool okToLoad = true;
                    var  result   = Version.Compare(version);
                    if (result == Version.VersionCompare.GreaterThanMax)
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format("Data for {0} is newer ({1}) than the version you are using ({2}).", host.Label, version, Version.Current.ToString()),
                            "Mod Configuration Menu");
                        okToLoad = false;
                    }
                    else if (result == Version.VersionCompare.Invalid)
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format("Data for {0} is corrupt and will be discarded", host.Label),
                            "Mod Configuration Menu");
                        okToLoad = false;
                    }

                    if (okToLoad)
                    {
                        // Call the worker scribe
                        var args = new object[]
                        {
                            host.Label,
                            host.worker
                        };
                        Scribe_Deep.LookDeep <MCMHost>(ref host, host.key, args);
                    }
                }
            }
            catch (Exception e)
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()),
                    "Mod Configuration Menu");
            }
            finally
            {
                // Finish
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }