Example #1
0
        internal void EnableButton()
        {
            ModMenuEntry entry = modEntries[modIndex];

            if (gadgetIndex >= 0)
            {
                bool enabled = !entry.Gadgets[gadgetIndex].Gadget.Enabled;
                Gadgets.SetEnabled(entry.Gadgets[gadgetIndex], enabled);
            }
            else if (entry.Type == ModMenuEntryType.GADGET)
            {
                bool enabled = !GadgetMods.GetModByName(entry.Name).Enabled;
                GadgetMods.SetEnabled(entry.Name, enabled);
            }
            else
            {
                if (!File.Exists(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile()))
                {
                    File.Create(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile()).Dispose();
                }
                string   fileText  = File.ReadAllText(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile());
                string[] fileLines = File.ReadAllLines(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile());
                if (fileLines.Any(x => x.Equals(entry.Name)))
                {
                    File.WriteAllLines(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile(), fileLines.Where(x => !x.Equals(entry.Name)).ToArray());
                }
                else
                {
                    File.WriteAllText(GadgetCoreAPI.GetUMFAPI().GetDisabledModsFile(), fileText + Environment.NewLine + entry.Name);
                }
                if (modsToToggle.Contains(entry.Name))
                {
                    modsToToggle.Remove(entry.Name);
                }
                else
                {
                    modsToToggle.Add(entry.Name);
                }
            }
            Rebuild();
            UpdateRestartNeeded();
        }
Example #2
0
        /// <summary>
        /// Sets the Enabled status of the given mod. Note that this can be queried using GadgetMod.Enabled
        /// </summary>
        public static void SetEnabled(GadgetMod mod, bool enabled)
        {
            if (mod.Enabled == enabled)
            {
                return;
            }
            mod.Enabled = enabled;
            GadgetCoreConfig.enabledMods[mod.Name] = enabled;
            bool wasBatchLoading = GadgetLoader.BatchLoading;

            GadgetLoader.BatchLoading = true;
            if (!enabled)
            {
                foreach (GadgetInfo gadget in mod.LoadedGadgets)
                {
                    Gadgets.SetEnabled(gadget, false);
                }
            }
            GadgetLoader.BatchLoading = wasBatchLoading;
            GadgetCoreConfig.Update();
        }