From 910176914ec7db23ab7852541ff2e5f6dcb888b2 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 31 Aug 2021 20:12:59 -0400 Subject: [PATCH 1/3] Add a message to the plugin window when SafeMode is active --- Dalamud/Dalamud.cs | 9 +++--- .../Internal/Windows/PluginInstallerWindow.cs | 8 +++++ Dalamud/Plugin/Internal/PluginManager.cs | 29 ++++++++++++++----- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 6e9acd0aa..f54356d9b 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -236,15 +236,14 @@ namespace Dalamud { Log.Information("[T3] START!"); + var pluginManager = Service.Set(); + Service.Set(); + if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false")) { try { - Service.Set(); - - var pluginManager = Service.Set(); - pluginManager.OnInstalledPluginsChanged += () => - Troubleshooting.LogTroubleshooting(); + pluginManager.OnInstalledPluginsChanged += Troubleshooting.LogTroubleshooting; Log.Information("[T3] PM OK!"); 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..7007dbc5f 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,12 @@ namespace Dalamud.Plugin.Internal if (!this.devPluginDirectory.Exists) this.devPluginDirectory.Create(); + if (this.SafeMode = 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")); @@ -112,6 +118,11 @@ namespace Dalamud.Plugin.Internal /// public bool ReposReady => this.Repos.All(repo => repo.State != PluginRepositoryState.InProgress); + /// + /// Gets a value indicating whether the plugin manager started in safe mode. + /// + public bool SafeMode { get; init; } + /// /// Gets a list of all IPC subscriptions. /// @@ -163,18 +174,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 +333,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) From 9697f0b7a0fcd717b0319b62f030c16cb327e1fb Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 31 Aug 2021 20:16:17 -0400 Subject: [PATCH 2/3] move DALAMUD_NOT_HAVE_PLUGINS into safeMode check --- Dalamud/Dalamud.cs | 25 +++++++++++------------- Dalamud/Plugin/Internal/PluginManager.cs | 3 ++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index f54356d9b..c966fc27a 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -239,24 +239,21 @@ namespace Dalamud var pluginManager = Service.Set(); Service.Set(); - if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false")) + try { - try - { - pluginManager.OnInstalledPluginsChanged += Troubleshooting.LogTroubleshooting; + 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/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 7007dbc5f..ebcd099d3 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -62,7 +62,8 @@ namespace Dalamud.Plugin.Internal if (!this.devPluginDirectory.Exists) this.devPluginDirectory.Create(); - if (this.SafeMode = configuration.PluginSafeMode) + var noPlugins = bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"); + if (this.SafeMode = noPlugins || configuration.PluginSafeMode) { configuration.PluginSafeMode = false; configuration.Save(); From 67bd5a50765092042840c52e29cad27545c6c8a5 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 31 Aug 2021 20:48:28 -0400 Subject: [PATCH 3/3] Remove obsolete class/prop --- Dalamud/Plugin/Internal/PluginManager.cs | 5 --- .../Plugin/Internal/Types/IpcSubscription.cs | 39 ------------------- 2 files changed, 44 deletions(-) delete mode 100644 Dalamud/Plugin/Internal/Types/IpcSubscription.cs diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index ebcd099d3..ae513ce85 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -124,11 +124,6 @@ namespace Dalamud.Plugin.Internal /// public bool SafeMode { get; init; } - /// - /// Gets a list of all IPC subscriptions. - /// - public List IpcSubscriptions { get; } = new(); - /// /// Gets the object used when initializing plugins. /// 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; } - } -}