diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 6e9acd0aa..c966fc27a 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -236,28 +236,24 @@ namespace Dalamud { Log.Information("[T3] START!"); - if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false")) + var pluginManager = Service.Set(); + Service.Set(); + + try { - try - { - Service.Set(); + pluginManager.OnInstalledPluginsChanged += Troubleshooting.LogTroubleshooting; - var pluginManager = Service.Set(); - pluginManager.OnInstalledPluginsChanged += () => - Troubleshooting.LogTroubleshooting(); + Log.Information("[T3] PM OK!"); - Log.Information("[T3] PM OK!"); + pluginManager.CleanupPlugins(); + Log.Information("[T3] PMC OK!"); - pluginManager.CleanupPlugins(); - Log.Information("[T3] PMC OK!"); - - pluginManager.LoadAllPlugins(); - Log.Information("[T3] PML OK!"); - } - catch (Exception ex) - { - Log.Error(ex, "Plugin load failed."); - } + pluginManager.LoadAllPlugins(); + Log.Information("[T3] PML OK!"); + } + catch (Exception ex) + { + Log.Error(ex, "Plugin load failed."); } Service.Set(); diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index 74a6afc51..076a47836 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -770,6 +770,12 @@ namespace Dalamud.Interface.Internal.Windows { var pluginManager = Service.Get(); + if (pluginManager.SafeMode) + { + ImGui.Text(Locs.TabBody_SafeMode); + return false; + } + var ready = pluginManager.PluginsReady && pluginManager.ReposReady; if (!ready) @@ -1873,6 +1879,8 @@ namespace Dalamud.Interface.Internal.Windows public static string TabBody_DownloadFailed => Loc.Localize("InstallerDownloadFailed", "Download failed."); + public static string TabBody_SafeMode => Loc.Localize("InstallerSafeMode", "Dalamud is running in Plugin Safe Mode, restart to activate plugins."); + #endregion #region Search text diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index db5b9a0ad..ae513ce85 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -21,7 +21,6 @@ using Dalamud.Plugin.Internal.Exceptions; using Dalamud.Plugin.Internal.Types; using Dalamud.Utility; using HarmonyLib; -using JetBrains.Annotations; using Newtonsoft.Json; namespace Dalamud.Plugin.Internal @@ -52,6 +51,7 @@ namespace Dalamud.Plugin.Internal public PluginManager() { var startInfo = Service.Get(); + var configuration = Service.Get(); this.pluginDirectory = new DirectoryInfo(startInfo.PluginDirectory); this.devPluginDirectory = new DirectoryInfo(startInfo.DefaultPluginDirectory); @@ -62,6 +62,13 @@ namespace Dalamud.Plugin.Internal if (!this.devPluginDirectory.Exists) this.devPluginDirectory.Create(); + var noPlugins = bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"); + if (this.SafeMode = noPlugins || configuration.PluginSafeMode) + { + configuration.PluginSafeMode = false; + configuration.Save(); + } + this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(startInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs")); var bannedPluginsJson = File.ReadAllText(Path.Combine(startInfo.AssetDirectory, "UIRes", "bannedplugin.json")); @@ -113,9 +120,9 @@ namespace Dalamud.Plugin.Internal public bool ReposReady => this.Repos.All(repo => repo.State != PluginRepositoryState.InProgress); /// - /// Gets a list of all IPC subscriptions. + /// Gets a value indicating whether the plugin manager started in safe mode. /// - public List IpcSubscriptions { get; } = new(); + public bool SafeMode { get; init; } /// /// Gets the object used when initializing plugins. @@ -163,18 +170,14 @@ namespace Dalamud.Plugin.Internal /// public void LoadAllPlugins() { - var configuration = Service.Get(); - - if (configuration.PluginSafeMode) + if (this.SafeMode) { Log.Information("PluginSafeMode was enabled, not loading any plugins."); - - configuration.PluginSafeMode = false; - configuration.Save(); - return; } + var configuration = Service.Get(); + var pluginDefs = new List(); var devPluginDefs = new List(); @@ -326,6 +329,12 @@ namespace Dalamud.Plugin.Internal /// public void ScanDevPlugins() { + if (this.SafeMode) + { + Log.Information("PluginSafeMode was enabled, not scanning any dev plugins."); + return; + } + var configuration = Service.Get(); if (!this.devPluginDirectory.Exists) diff --git a/Dalamud/Plugin/Internal/Types/IpcSubscription.cs b/Dalamud/Plugin/Internal/Types/IpcSubscription.cs deleted file mode 100644 index 3427a824a..000000000 --- a/Dalamud/Plugin/Internal/Types/IpcSubscription.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Dynamic; - -namespace Dalamud.Plugin.Internal.Types -{ - /// - /// This class represents an IPC subscription between two plugins. - /// - internal record IpcSubscription - { - /// - /// Initializes a new instance of the class. - /// - /// The source plugin name. - /// The name of the plugin being subscribed to. - /// The subscription action. - public IpcSubscription(string sourcePluginName, string subPluginName, Action subAction) - { - this.SourcePluginName = sourcePluginName; - this.SubPluginName = subPluginName; - this.SubAction = subAction; - } - - /// - /// Gets the name of the plugin requesting the subscription. - /// - public string SourcePluginName { get; } - - /// - /// Gets the name of the plugin being subscribed to. - /// - public string SubPluginName { get; } - - /// - /// Gets the subscription action. - /// - public Action SubAction { get; } - } -}