From 910176914ec7db23ab7852541ff2e5f6dcb888b2 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 31 Aug 2021 20:12:59 -0400 Subject: [PATCH] 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)