Merge pull request #522 from daemitus/safeMode

This commit is contained in:
goaaats 2021-09-01 15:58:08 +02:00 committed by GitHub
commit 2ef5a9706d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 67 deletions

View file

@ -236,28 +236,24 @@ namespace Dalamud
{
Log.Information("[T3] START!");
if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
var pluginManager = Service<PluginManager>.Set();
Service<CallGate>.Set();
try
{
try
{
Service<CallGate>.Set();
pluginManager.OnInstalledPluginsChanged += Troubleshooting.LogTroubleshooting;
var pluginManager = Service<PluginManager>.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<DalamudInterface>.Set();

View file

@ -770,6 +770,12 @@ namespace Dalamud.Interface.Internal.Windows
{
var pluginManager = Service<PluginManager>.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

View file

@ -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<DalamudStartInfo>.Get();
var configuration = Service<DalamudConfiguration>.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);
/// <summary>
/// Gets a list of all IPC subscriptions.
/// Gets a value indicating whether the plugin manager started in safe mode.
/// </summary>
public List<IpcSubscription> IpcSubscriptions { get; } = new();
public bool SafeMode { get; init; }
/// <summary>
/// Gets the <see cref="PluginConfigurations"/> object used when initializing plugins.
@ -163,18 +170,14 @@ namespace Dalamud.Plugin.Internal
/// </summary>
public void LoadAllPlugins()
{
var configuration = Service<DalamudConfiguration>.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<DalamudConfiguration>.Get();
var pluginDefs = new List<PluginDef>();
var devPluginDefs = new List<PluginDef>();
@ -326,6 +329,12 @@ namespace Dalamud.Plugin.Internal
/// </summary>
public void ScanDevPlugins()
{
if (this.SafeMode)
{
Log.Information("PluginSafeMode was enabled, not scanning any dev plugins.");
return;
}
var configuration = Service<DalamudConfiguration>.Get();
if (!this.devPluginDirectory.Exists)

View file

@ -1,39 +0,0 @@
using System;
using System.Dynamic;
namespace Dalamud.Plugin.Internal.Types
{
/// <summary>
/// This class represents an IPC subscription between two plugins.
/// </summary>
internal record IpcSubscription
{
/// <summary>
/// Initializes a new instance of the <see cref="IpcSubscription"/> class.
/// </summary>
/// <param name="sourcePluginName">The source plugin name.</param>
/// <param name="subPluginName">The name of the plugin being subscribed to.</param>
/// <param name="subAction">The subscription action.</param>
public IpcSubscription(string sourcePluginName, string subPluginName, Action<ExpandoObject> subAction)
{
this.SourcePluginName = sourcePluginName;
this.SubPluginName = subPluginName;
this.SubAction = subAction;
}
/// <summary>
/// Gets the name of the plugin requesting the subscription.
/// </summary>
public string SourcePluginName { get; }
/// <summary>
/// Gets the name of the plugin being subscribed to.
/// </summary>
public string SubPluginName { get; }
/// <summary>
/// Gets the subscription action.
/// </summary>
public Action<ExpandoObject> SubAction { get; }
}
}