mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 20:33:40 +01:00
feat: refactor safe mode, add "no third party" mode for testing
This commit is contained in:
parent
f501534739
commit
fc5d8a8c86
5 changed files with 81 additions and 25 deletions
|
|
@ -68,7 +68,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
if (!this.devPluginDirectory.Exists)
|
||||
this.devPluginDirectory.Create();
|
||||
|
||||
this.SafeMode = EnvironmentConfiguration.DalamudNoPlugins || this.configuration.PluginSafeMode;
|
||||
this.SafeMode = EnvironmentConfiguration.DalamudNoPlugins || this.configuration.PluginSafeMode || this.startInfo.NoLoadPlugins;
|
||||
if (this.SafeMode)
|
||||
{
|
||||
this.configuration.PluginSafeMode = false;
|
||||
|
|
@ -281,12 +281,6 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
/// </remarks>
|
||||
public void LoadAllPlugins()
|
||||
{
|
||||
if (this.SafeMode)
|
||||
{
|
||||
Log.Information("PluginSafeMode was enabled, not loading any plugins.");
|
||||
return;
|
||||
}
|
||||
|
||||
var pluginDefs = new List<PluginDef>();
|
||||
var devPluginDefs = new List<PluginDef>();
|
||||
|
||||
|
|
@ -504,12 +498,6 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
/// </summary>
|
||||
public void ScanDevPlugins()
|
||||
{
|
||||
if (this.SafeMode)
|
||||
{
|
||||
Log.Information("PluginSafeMode was enabled, not scanning any dev plugins.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.devPluginDirectory.Exists)
|
||||
this.devPluginDirectory.Create();
|
||||
|
||||
|
|
@ -753,6 +741,14 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
// NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
|
||||
// plugin.Disable(); // Disable here, otherwise you can't enable+load later
|
||||
}
|
||||
else if (!plugin.CheckPolicy())
|
||||
{
|
||||
// During boot load, plugins always get added to the list so they can be fiddled with in the UI
|
||||
Log.Information(ex, $"Plugin not loaded due to policy, adding anyways: {dllFile.Name}");
|
||||
|
||||
// NOTE(goat): This can't work - plugins don't "unload" if they fail to load.
|
||||
// plugin.Disable(); // Disable here, otherwise you can't enable+load later
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
|
|
@ -1064,7 +1060,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
|||
/// <returns>A value indicating whether the plugin/manifest has been banned.</returns>
|
||||
public bool IsManifestBanned(PluginManifest manifest)
|
||||
{
|
||||
return !configuration.LoadBannedPlugins && this.bannedPlugins.Any(ban => (ban.Name == manifest.InternalName || ban.Name == Hash.GetStringSha256Hash(manifest.InternalName))
|
||||
return !this.configuration.LoadBannedPlugins && this.bannedPlugins.Any(ban => (ban.Name == manifest.InternalName || ban.Name == Hash.GetStringSha256Hash(manifest.InternalName))
|
||||
&& ban.AssemblyVersion >= manifest.AssemblyVersion);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -311,6 +311,9 @@ internal class LocalPlugin : IDisposable
|
|||
if (this.IsOrphaned)
|
||||
throw new InvalidPluginOperationException($"Plugin {this.Name} had no associated repo.");
|
||||
|
||||
if (!this.CheckPolicy())
|
||||
throw new InvalidPluginOperationException("Plugin was not loaded as per policy");
|
||||
|
||||
this.State = PluginState.Loading;
|
||||
Log.Information($"Loading {this.DllFile.Name}");
|
||||
|
||||
|
|
@ -553,6 +556,27 @@ internal class LocalPlugin : IDisposable
|
|||
this.SaveManifest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if anything forbids this plugin from loading.
|
||||
/// </summary>
|
||||
/// <returns>Whether or not this plugin shouldn't load.</returns>
|
||||
public bool CheckPolicy()
|
||||
{
|
||||
var startInfo = Service<DalamudStartInfo>.Get();
|
||||
var manager = Service<PluginManager>.Get();
|
||||
|
||||
if (startInfo.NoLoadPlugins)
|
||||
return false;
|
||||
|
||||
if (startInfo.NoLoadThirdPartyPlugins && this.Manifest.IsThirdParty)
|
||||
return false;
|
||||
|
||||
if (manager.SafeMode)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable this plugin, must be unloaded first.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue