Beispiel #1
0
        /// <summary>
        /// Creates a ModDef from a path to a mod.json
        /// </summary>
        public static ModDefEx CreateFromPath(string path)
        {
            var modDef = JsonConvert.DeserializeObject <ModDefEx>(File.ReadAllText(path));

            modDef.Directory  = Path.GetDirectoryName(path);
            modDef.LoadFail   = false;
            modDef.FailReason = string.Empty;
            string statepath = Path.Combine(Path.GetDirectoryName(path), ModTek.MOD_STATE_JSON_NAME);

            if (File.Exists(statepath))
            {
                try
                {
                    var stateDef = JsonConvert.DeserializeObject <ModState>(File.ReadAllText(statepath));
                    modDef.Enabled = stateDef.Enabled;
                }
                catch (Exception)
                {
                    ModState state = new ModState();
                    state.Enabled = modDef.Enabled;
                    state.SaveToPath(statepath);
                }
            }
            else
            {
                ModState state = new ModState();
                state.Enabled = modDef.Enabled;
                state.SaveToPath(statepath);
            }
            modDef.PendingEnable = modDef.Enabled;
            return(modDef);
        }
Beispiel #2
0
        public void SaveState()
        {
            string   modStatePath = Path.Combine(Directory, ModTek.MOD_STATE_JSON_NAME);
            ModState state        = new ModState();

            state.Enabled = this.Enabled;
            RuntimeLog.RLog.M.WL(2, "writing to FS:" + this.Name + "->" + state.Enabled);
            state.SaveToPath(modStatePath);
        }