コード例 #1
0
        public static NaniteSettings Load()
        {
            bool updatedFile = MyAPIGateway.Utilities.FileExistsInWorldStorage(SettingsFile, typeof(NaniteSettings));

            // We can't just ignore & delete the file at the old location because what if someone has modified it and expects the settings to be the same under multiple saves?

            if (MyAPIGateway.Utilities.FileExistsInLocalStorage("settings.xml", typeof(NaniteSettings)) || updatedFile)
            {
                try
                {
                    Logging.Instance.WriteLine("Loading Settings");
                    NaniteSettings settings;
                    using (var reader = updatedFile ? MyAPIGateway.Utilities.ReadFileInWorldStorage(SettingsFile, typeof(NaniteSettings)) : MyAPIGateway.Utilities.ReadFileInLocalStorage("settings.xml", typeof(NaniteSettings)))
                        settings = MyAPIGateway.Utilities.SerializeFromXML <NaniteSettings>(reader.ReadToEnd());

                    try
                    {
                        UpdateSettings(settings);
                        Save(settings);
                    }
                    catch { }

                    return(settings);
                }
                catch (Exception ex)
                {
                    Logging.Instance.WriteLine(string.Format("Error loading settings file.  Using defaults. ({0})", ex.ToString()));
                }
            }

            NaniteSettings result = new NaniteSettings();

            Save(result);
            return(result);
        }
コード例 #2
0
        public static NaniteSettings Load()
        {
            if (MyAPIGateway.Utilities.FileExistsInWorldStorage(SettingsFile, typeof(NaniteSettings)))
            {
                try
                {
                    Logging.Instance.WriteLine("Loading Settings");
                    NaniteSettings settings;
                    using (var reader = MyAPIGateway.Utilities.ReadFileInWorldStorage(SettingsFile, typeof(NaniteSettings)))
                        settings = MyAPIGateway.Utilities.SerializeFromXML <NaniteSettings>(reader.ReadToEnd());
                    try
                    {
                        UpdateSettings(settings);
                        Save(settings);
                    }
                    catch { }

                    return(settings);
                }
                catch (Exception ex)
                {
                    Logging.Instance.WriteLine(string.Format("Error loading settings file.  Using defaults. ({0})", ex.ToString()));
                }
            }

            NaniteSettings result = new NaniteSettings();

            Save(result);
            return(result);
        }
コード例 #3
0
 public static void Save(NaniteSettings settings)
 {
     using (var writer = MyAPIGateway.Utilities.WriteFileInLocalStorage("settings.xml", typeof(NaniteSettings)))
     {
         writer.Write(MyAPIGateway.Utilities.SerializeToXML <NaniteSettings>(settings));
     }
 }
コード例 #4
0
        private static void UpdateSettings(NaniteSettings settings)
        {
            //var originalVersion = settings.Version;

            //TODO config migration

            //if (settings.Version != originalVersion)
            //    SendNotification();
        }
コード例 #5
0
 public static void Save(NaniteSettings settings)
 {
     using (var writer = MyAPIGateway.Utilities.WriteFileInWorldStorage(SettingsFile, typeof(NaniteSettings)))
         writer.Write(MyAPIGateway.Utilities.SerializeToXML <NaniteSettings>(settings));
 }
コード例 #6
0
        private static void UpdateSettings(NaniteSettings settings)
        {
            var originalVersion = settings.Version;

            if (settings.Version == "1.0")
            {
                Logging.Instance.WriteLine(string.Format("Updating Settings 1.0 -> 1.1"));

                if (settings.ConstructionMaxStreams == 6)
                {
                    settings.ConstructionMaxStreams = 15;
                }
                if (settings.DeconstructionMaxStreams == 6)
                {
                    settings.DeconstructionMaxStreams = 15;
                }
                if (settings.CleanupMaxStreams == 6)
                {
                    settings.CleanupMaxStreams = 15;
                }
                if (settings.ProjectionMaxStreams == 6)
                {
                    settings.ProjectionMaxStreams = 15;
                }

                settings.Version = "1.1";
            }

            if (settings.Version == "1.1")
            {
                if (settings.ConstructionNanitesNoUpgrade == 0)
                {
                    settings.ConstructionNanitesNoUpgrade = 1;
                }

                if (settings.DeconstructionNanitesNoUpgrade == 0)
                {
                    settings.DeconstructionNanitesNoUpgrade = 1;
                }

                if (settings.ProjectionNanitesNoUpgrade == 0)
                {
                    settings.ProjectionNanitesNoUpgrade = 1;
                }

                if (settings.CleanupNanitesNoUpgrade == 0)
                {
                    settings.CleanupNanitesNoUpgrade = 1;
                }

                settings.Version = "1.2";
            }

            if (settings.Version == "1.2") // Just notify user we've updated
            {
                settings.Version = "1.3";
            }

            if (settings.Version == "1.3")
            {
                settings.Version = "1.4";
            }

            if (settings.Version == "1.4")
            {
                settings.Version = "1.5";
            }

            if (settings.Version == "1.5")
            {
                settings.Version = "1.6";
            }

            if (settings.Version == "1.6")
            {
                settings.Version = "1.7";
            }

            if (settings.Version == "1.7")
            {
                MyAPIUtilities utils = (MyAPIUtilities)MyAPIGateway.Utilities;

                // Clean out useless variables in Sandbox.sbc save file.
                utils.Variables.Remove("terminalsettings.xml");
                utils.Variables.Remove("assemblersettings.xml");
                utils.Variables.Remove("NaniteControlFactory.HammerTerminalSettings");
                utils.Variables.Remove("NaniteControlFactory.BeaconTerminalSettings");

                settings.Version = "1.8";
            }

            if (settings.Version == "1.8")
            {
                settings.Version = "1.9";
            }

            if (settings.Version != originalVersion)
            {
                SendNotification();
            }
        }
コード例 #7
0
        private static void UpdateSettings(NaniteSettings settings)
        {
            var originalVersion = settings.Version;

            if (settings.Version == "1.0")
            {
                Logging.Instance.WriteLine(string.Format("Updating Settings 1.0 -> 1.1"));

                if (settings.ConstructionMaxStreams == 6)
                {
                    settings.ConstructionMaxStreams = 15;
                }
                if (settings.DeconstructionMaxStreams == 6)
                {
                    settings.DeconstructionMaxStreams = 15;
                }
                if (settings.CleanupMaxStreams == 6)
                {
                    settings.CleanupMaxStreams = 15;
                }
                if (settings.ProjectionMaxStreams == 6)
                {
                    settings.ProjectionMaxStreams = 15;
                }

                settings.Version = "1.1";
            }

            if (settings.Version == "1.1")
            {
                if (settings.ConstructionNanitesNoUpgrade == 0)
                {
                    settings.ConstructionNanitesNoUpgrade = 1;
                }

                if (settings.DeconstructionNanitesNoUpgrade == 0)
                {
                    settings.DeconstructionNanitesNoUpgrade = 1;
                }

                if (settings.ProjectionNanitesNoUpgrade == 0)
                {
                    settings.ProjectionNanitesNoUpgrade = 1;
                }

                if (settings.CleanupNanitesNoUpgrade == 0)
                {
                    settings.CleanupNanitesNoUpgrade = 1;
                }

                settings.Version = "1.2";
            }

            if (settings.Version == "1.2") // Just notify user we've updated
            {
                settings.Version = "1.3";
            }

            if (settings.Version == "1.3")
            {
                settings.Version = "1.4";
            }

            if (settings.Version == "1.4")
            {
                settings.Version = "1.5";
            }

            if (settings.Version == "1.5")
            {
                settings.Version = "1.6";
            }

            if (settings.Version == "1.6")
            {
                settings.Version = "1.7";
            }

            if (settings.Version != originalVersion)
            {
                SendNotification();
            }
        }