コード例 #1
0
        public static void SaveConfig()
        {
            ConfigNode cfgnode = new ConfigNode();
            ConfigNode KSPAVC  = cfgnode.AddNode("MINI-AVC");

            ConfigNode Interval = KSPAVC.AddNode("UPDATE_FREQUENCY");

            {
                Interval.AddValue("MinTimeBetweenAvcRuns", AvcInterval.ToString() + " //Timespan between AVC runs in hours (-1 = Disable MiniAVC, 0 = Run on each game start)");

                if (DateTime.Compare(DateTime.Now, NextRun) >= 0 && AvcInterval > 0)
                {
                    Interval.AddValue("AvcRunsNext", DateTime.Now.AddHours(AvcInterval).ToString());
                }
                else
                {
                    Interval.AddValue("AvcRunsNext", NextRun.ToString());
                }
            }
            cfgnode.Save(configPath);
            Logger.Log("Config saved!");
        }
コード例 #2
0
        public static void SaveCfg()
        {
            Logger.Log("SaveCfg");
            CfgUpdated = false;

            if (!File.Exists(AvcConfigFile) || !Directory.Exists(AvcConfigFilePath))
            {
                Directory.CreateDirectory(AvcConfigFilePath);
                var ConfigFileStream = File.Create(AvcConfigFile);
                ConfigFileStream.Close(); //avoid System.IO access violation
                //Some default values so this method can create a config file
                //modsIgnoreOverride.Add("Kopernicus"); //Unfortunately, the name of Kopernicus is actually "<b><color=#CA7B3C>Kopernicus</color></b>" which may irritates some users
                OverrideIsDisabledGlobal = true;
                ShowDefaultValues        = true;
                AvcInterval = 0;
                //UseKspSkin = true;
                CfgUpdated = true;
                //For some reason, if a config file is missing, it will just create an empty config.
                //By setting the bool CfgUpdated = true, this method will run again on destroy of the starter, which creates the empty config nodes within the file.
            }

            ConfigNode cfgnode = new ConfigNode();
            ConfigNode KSPAVC  = cfgnode.AddNode("KSP-AVC");

            //KSPAVC.AddValue("KSP_SKIN", UseKspSkin);
            KSPAVC.AddValue("OVERRIDE_PRIORITY", OverridePriority);
            KSPAVC.AddValue("SIMPLE_PRIORITY", SimplePriority);
            KSPAVC.AddValue("DISABLE_COMPATIBLE_VERSION_OVERRIDE", OverrideIsDisabledGlobal);
            KSPAVC.AddValue("SHOW_DEFAULT_VALUES", ShowDefaultValues);
#if STRICT
            KSPAVC.AddValue("STRICT_VERSION", StrictVersion);
#endif

            ConfigNode OverrideName = KSPAVC.AddNode("OVERRIDE_NAME");
            foreach (string ModName in OverrideCompatibilityByName)
            {
                OverrideName.AddValue("OverrideEnabled", ModName);
            }

            ConfigNode OverrideVersion = KSPAVC.AddNode("OVERRIDE_VERSION");
            foreach (KeyValuePair <string, CompatVersions> kvp in CompatibleVersions)
            {
                string temp = kvp.Key.Replace("-1", "*");
                for (int i = 0; i < kvp.Value.compatibleWithVersion.Count; i++)
                {
                    temp = temp + $", {kvp.Value.compatibleWithVersion[i]}";
                }
                OverrideVersion.AddValue("OverrideEnabled", temp);
            }

            ConfigNode OverrideIgnore = KSPAVC.AddNode("OVERRIDE_IGNORE");
            foreach (string ModName in modsIgnoreOverride)
            {
                OverrideIgnore.AddValue("IgnoreOverride", ModName);
            }

            ConfigNode Interval = KSPAVC.AddNode("INTERVAL");
            {
                Interval.AddValue("MinTimeBetweenAvcRuns", AvcInterval.ToString() + " //Timespan between AVC runs in hours");

                if (DateTime.Compare(DateTime.Now, NextRun) >= 0 && AvcInterval > 0)
                {
                    Interval.AddValue("AvcRunsNext", DateTime.Now.AddHours(AvcInterval).ToString());
                    CfgUpdated = true;
                }
                else
                {
                    Interval.AddValue("AvcRunsNext", NextRun.ToString());
                }
            }
            cfgnode.Save(AvcConfigFile);
        }