Example #1
0
 public static void OnPluginDisabled(bool byUser)
 {
     PluginDisabled?.Invoke(byUser);
 }
Example #2
0
        /// <summary>
        /// Disables a plugin, and all dependents.
        /// </summary>
        /// <param name="plugin">the plugin to disable</param>
        /// <returns>whether or not it needs a restart to enable</returns>
        public static bool DisablePlugin(PluginInfo plugin)
        {
            if (plugin == null)
            {
                return(false);
            }

            if (plugin.Metadata.IsBare)
            {
                Logger.loader.Warn($"Trying to disable bare manifest");
                return(false);
            }

            if (IsDisabled(plugin.Metadata))
            {
                return(false);
            }

            var needsRestart = false;

            Logger.loader.Info($"Disabling {plugin.Metadata.Name}");

            var dependents = BSMetas.Where(m => m.Metadata.Dependencies.Contains(plugin.Metadata)).ToList();

            needsRestart = dependents.Aggregate(needsRestart, (b, p) => DisablePlugin(p) || b);

            DisabledConfig.Ref.Value.DisabledModIds.Add(plugin.Metadata.Id ?? plugin.Metadata.Name);
            DisabledConfig.Provider.Store(DisabledConfig.Ref.Value);

            if (!needsRestart && plugin.Plugin is IDisablablePlugin disable)
            {
                try
                {
                    disable.OnDisable();
                }
                catch (Exception e)
                {
                    Logger.loader.Error($"Error occurred trying to disable {plugin.Metadata.Name}");
                    Logger.loader.Error(e);
                }

                if (needsRestart)
                {
                    Logger.loader.Warn($"Disablable plugin has non-disablable dependents; some things may not work properly");
                }
            }
            else
            {
                needsRestart = true;
            }

            runtimeDisabled.Add(plugin);
            _bsPlugins.Remove(plugin);

            try
            {
                PluginDisabled?.Invoke(plugin.Metadata, needsRestart);
            }
            catch (Exception e)
            {
                Logger.loader.Error($"Error occurred invoking disable event for {plugin.Metadata.Name}");
                Logger.loader.Error(e);
            }

            return(needsRestart);
        }
Example #3
0
 protected virtual void OnPluginDisabled(PluginEventArgs e)
 {
     PluginDisabled?.Invoke(this, e);
 }
Example #4
0
 /// <summary>
 ///     Triggers the PluginDisabled event
 /// </summary>
 protected virtual void OnPluginDisabled()
 {
     PluginDisabled?.Invoke(this, EventArgs.Empty);
 }