mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Merge pull request #579 from daemitus/banned
Delete button for outdated/banned, do banned plugins like outdated so they update.
This commit is contained in:
commit
2d9a0535f5
5 changed files with 118 additions and 45 deletions
|
|
@ -909,6 +909,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
||||||
var cursor = ImGui.GetCursorPos();
|
var cursor = ImGui.GetCursorPos();
|
||||||
|
|
||||||
// Name
|
// Name
|
||||||
ImGui.Text(label);
|
ImGui.Text(label);
|
||||||
|
|
||||||
|
|
@ -1166,12 +1167,19 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outdated API level
|
// Outdated API level
|
||||||
if (plugin.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel)
|
if (plugin.IsOutdated)
|
||||||
{
|
{
|
||||||
label += Locs.PluginTitleMod_OutdatedError;
|
label += Locs.PluginTitleMod_OutdatedError;
|
||||||
trouble = true;
|
trouble = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Banned
|
||||||
|
if (plugin.IsBanned)
|
||||||
|
{
|
||||||
|
label += Locs.PluginTitleMod_BannedError;
|
||||||
|
trouble = true;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.PushID($"installed{index}{plugin.Manifest.InternalName}");
|
ImGui.PushID($"installed{index}{plugin.Manifest.InternalName}");
|
||||||
|
|
||||||
if (this.DrawPluginCollapsingHeader(label, plugin, plugin.Manifest, plugin.Manifest.IsThirdParty, trouble, availablePluginUpdate != default, false, () => this.DrawInstalledPluginContextMenu(plugin), index))
|
if (this.DrawPluginCollapsingHeader(label, plugin, plugin.Manifest, plugin.Manifest.IsThirdParty, trouble, availablePluginUpdate != default, false, () => this.DrawInstalledPluginContextMenu(plugin), index))
|
||||||
|
|
@ -1216,13 +1224,20 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
ImGui.TextWrapped(manifest.Description);
|
ImGui.TextWrapped(manifest.Description);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel)
|
if (plugin.IsOutdated)
|
||||||
{
|
{
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||||
ImGui.TextWrapped(Locs.PluginBody_Outdated);
|
ImGui.TextWrapped(Locs.PluginBody_Outdated);
|
||||||
ImGui.PopStyleColor();
|
ImGui.PopStyleColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (plugin.IsBanned)
|
||||||
|
{
|
||||||
|
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||||
|
ImGui.TextWrapped(Locs.PluginBody_Banned);
|
||||||
|
ImGui.PopStyleColor();
|
||||||
|
}
|
||||||
|
|
||||||
// Available commands (if loaded)
|
// Available commands (if loaded)
|
||||||
if (plugin.IsLoaded)
|
if (plugin.IsLoaded)
|
||||||
{
|
{
|
||||||
|
|
@ -1243,6 +1258,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
// Controls
|
// Controls
|
||||||
this.DrawPluginControlButton(plugin);
|
this.DrawPluginControlButton(plugin);
|
||||||
this.DrawDevPluginButtons(plugin);
|
this.DrawDevPluginButtons(plugin);
|
||||||
|
this.DrawDeletePluginButton(plugin);
|
||||||
this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl);
|
this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl);
|
||||||
|
|
||||||
if (availablePluginUpdate != default)
|
if (availablePluginUpdate != default)
|
||||||
|
|
@ -1304,7 +1320,7 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress;
|
var disabled = this.updateStatus == OperationStatus.InProgress || this.installStatus == OperationStatus.InProgress;
|
||||||
|
|
||||||
// Disable everything if the plugin is outdated
|
// Disable everything if the plugin is outdated
|
||||||
disabled = disabled || (plugin.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !configuration.LoadAllApiLevels);
|
disabled = disabled || (plugin.IsOutdated && !configuration.LoadAllApiLevels) || plugin.IsBanned;
|
||||||
|
|
||||||
if (plugin.State == PluginState.InProgress)
|
if (plugin.State == PluginState.InProgress)
|
||||||
{
|
{
|
||||||
|
|
@ -1452,7 +1468,6 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
private void DrawDevPluginButtons(LocalPlugin localPlugin)
|
private void DrawDevPluginButtons(LocalPlugin localPlugin)
|
||||||
{
|
{
|
||||||
var configuration = Service<DalamudConfiguration>.Get();
|
var configuration = Service<DalamudConfiguration>.Get();
|
||||||
var pluginManager = Service<PluginManager>.Get();
|
|
||||||
|
|
||||||
if (localPlugin is LocalDevPlugin plugin)
|
if (localPlugin is LocalDevPlugin plugin)
|
||||||
{
|
{
|
||||||
|
|
@ -1495,33 +1510,40 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
{
|
{
|
||||||
ImGui.SetTooltip(Locs.PluginButtonToolTip_AutomaticReloading);
|
ImGui.SetTooltip(Locs.PluginButtonToolTip_AutomaticReloading);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Delete
|
private void DrawDeletePluginButton(LocalPlugin plugin)
|
||||||
if (plugin.State == PluginState.Unloaded)
|
{
|
||||||
|
var unloaded = plugin.State == PluginState.Unloaded;
|
||||||
|
var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated || plugin.IsBanned);
|
||||||
|
|
||||||
|
if (!showButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var pluginManager = Service<PluginManager>.Get();
|
||||||
|
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
ImGui.SameLine();
|
plugin.DllFile.Delete();
|
||||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
|
pluginManager.RemovePlugin(plugin);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
plugin.DllFile.Delete();
|
|
||||||
pluginManager.RemovePlugin(plugin);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}");
|
|
||||||
|
|
||||||
this.errorModalMessage = Locs.ErrorModal_DeleteFail(plugin.Name);
|
|
||||||
this.errorModalDrawing = true;
|
|
||||||
this.errorModalOnNextFrame = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.IsItemHovered())
|
|
||||||
{
|
|
||||||
ImGui.SetTooltip(Locs.PluginBody_DeleteDevPlugin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, $"Plugin installer threw an error during removal of {plugin.Name}");
|
||||||
|
|
||||||
|
this.errorModalMessage = Locs.ErrorModal_DeleteFail(plugin.Name);
|
||||||
|
this.errorModalDrawing = true;
|
||||||
|
this.errorModalOnNextFrame = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
{
|
||||||
|
ImGui.SetTooltip(Locs.PluginButtonToolTip_DeletePlugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1993,6 +2015,8 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
public static string PluginTitleMod_OutdatedError => Loc.Localize("InstallerOutdatedError", " (outdated)");
|
public static string PluginTitleMod_OutdatedError => Loc.Localize("InstallerOutdatedError", " (outdated)");
|
||||||
|
|
||||||
|
public static string PluginTitleMod_BannedError => Loc.Localize("InstallerOutdatedError", " (banned)");
|
||||||
|
|
||||||
public static string PluginTitleMod_New => Loc.Localize("InstallerNewPlugin ", " New!");
|
public static string PluginTitleMod_New => Loc.Localize("InstallerNewPlugin ", " New!");
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -2027,6 +2051,8 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
public static string PluginBody_Outdated => Loc.Localize("InstallerOutdatedPluginBody ", "This plugin is outdated and incompatible at the moment. Please wait for it to be updated by its author.");
|
public static string PluginBody_Outdated => Loc.Localize("InstallerOutdatedPluginBody ", "This plugin is outdated and incompatible at the moment. Please wait for it to be updated by its author.");
|
||||||
|
|
||||||
|
public static string PluginBody_Banned => Loc.Localize("InstallerBannedPluginBody ", "This plugin version is banned and not available at the moment. Please wait for it to be updated by its author.");
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Plugin buttons
|
#region Plugin buttons
|
||||||
|
|
|
||||||
22
Dalamud/Plugin/Internal/Exceptions/BannedPluginException.cs
Normal file
22
Dalamud/Plugin/Internal/Exceptions/BannedPluginException.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
namespace Dalamud.Plugin.Internal.Exceptions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This represents a banned plugin that attempted an operation.
|
||||||
|
/// </summary>
|
||||||
|
internal class BannedPluginException : PluginException
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="BannedPluginException"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message describing the invalid operation.</param>
|
||||||
|
public BannedPluginException(string message)
|
||||||
|
{
|
||||||
|
this.Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the message describing the invalid operation.
|
||||||
|
/// </summary>
|
||||||
|
public override string Message { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -145,19 +145,17 @@ namespace Dalamud.Plugin.Internal
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var notificationManager = Service<NotificationManager>.Get();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.Reload();
|
this.Reload();
|
||||||
Service<NotificationManager>.Get()
|
notificationManager.AddNotification($"The DevPlugin '{this.Name} was reloaded successfully.", "Plugin reloaded!", NotificationType.Success);
|
||||||
.AddNotification(
|
|
||||||
$"The DevPlugin '{this.Name} was reloaded successfully.", "Plugin reloaded!", NotificationType.Success);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex, "DevPlugin reload failed.");
|
Log.Error(ex, "DevPlugin reload failed.");
|
||||||
Service<NotificationManager>.Get()
|
notificationManager.AddNotification($"The DevPlugin '{this.Name} could not be reloaded.", "Plugin reload failed!", NotificationType.Error);
|
||||||
.AddNotification(
|
|
||||||
$"The DevPlugin '{this.Name} could not be reloaded.", "Plugin reload failed!", NotificationType.Error);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
this.fileWatcherTokenSource.Token);
|
this.fileWatcherTokenSource.Token);
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,8 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
var assemblyVersion = this.pluginAssembly.GetName().Version;
|
var assemblyVersion = this.pluginAssembly.GetName().Version;
|
||||||
|
|
||||||
// Files that may or may not exist
|
// Although it is conditionally used here, we need to set the initial value regardless.
|
||||||
this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
||||||
this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile);
|
|
||||||
this.testingFile = LocalPluginManifest.GetTestingFile(this.DllFile);
|
|
||||||
|
|
||||||
// If the parameter manifest was null
|
// If the parameter manifest was null
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
|
|
@ -108,28 +106,32 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
// Save the manifest to disk so there won't be any problems later.
|
// Save the manifest to disk so there won't be any problems later.
|
||||||
// We'll update the name property after it can be retrieved from the instance.
|
// We'll update the name property after it can be retrieved from the instance.
|
||||||
var manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
this.Manifest.Save(this.manifestFile);
|
||||||
this.Manifest.Save(manifestFile);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.Manifest = manifest;
|
this.Manifest = manifest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This bit converts from ".disabled" functionality to using the manifest.
|
// This converts from the ".disabled" file feature to the manifest instead.
|
||||||
|
this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile);
|
||||||
if (this.disabledFile.Exists)
|
if (this.disabledFile.Exists)
|
||||||
{
|
{
|
||||||
this.Manifest.Disabled = true;
|
this.Manifest.Disabled = true;
|
||||||
this.disabledFile.Delete();
|
this.disabledFile.Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This bit converts from ".testing" functionality to using the manifest.
|
// This converts from the ".testing" file feature to the manifest instead.
|
||||||
|
this.testingFile = LocalPluginManifest.GetTestingFile(this.DllFile);
|
||||||
if (this.testingFile.Exists)
|
if (this.testingFile.Exists)
|
||||||
{
|
{
|
||||||
this.Manifest.Testing = true;
|
this.Manifest.Testing = true;
|
||||||
this.testingFile.Delete();
|
this.testingFile.Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pluginManager = Service<PluginManager>.Get();
|
||||||
|
this.IsBanned = pluginManager.IsManifestBanned(this.Manifest);
|
||||||
|
|
||||||
this.SaveManifest();
|
this.SaveManifest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,11 +176,21 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDisabled => this.Manifest.Disabled;
|
public bool IsDisabled => this.Manifest.Disabled;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this plugin's API level is out of date.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsOutdated => this.Manifest.DalamudApiLevel < PluginManager.DalamudApiLevel;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether the plugin is for testing use only.
|
/// Gets a value indicating whether the plugin is for testing use only.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsTesting => this.Manifest.IsTestingExclusive || this.Manifest.Testing;
|
public bool IsTesting => this.Manifest.IsTestingExclusive || this.Manifest.Testing;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this plugin has been banned.
|
||||||
|
/// </summary>
|
||||||
|
public bool IsBanned { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this plugin is dev plugin.
|
/// Gets a value indicating whether this plugin is dev plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -223,6 +235,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
throw new InvalidPluginOperationException($"Unable to load {this.Name}, unload previously faulted, restart Dalamud");
|
throw new InvalidPluginOperationException($"Unable to load {this.Name}, unload previously faulted, restart Dalamud");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pluginManager.IsManifestBanned(this.Manifest))
|
||||||
|
throw new BannedPluginException($"Unable to load {this.Name}, banned");
|
||||||
|
|
||||||
if (this.Manifest.ApplicableVersion < startInfo.GameVersion)
|
if (this.Manifest.ApplicableVersion < startInfo.GameVersion)
|
||||||
throw new InvalidPluginOperationException($"Unable to load {this.Name}, no applicable version");
|
throw new InvalidPluginOperationException($"Unable to load {this.Name}, no applicable version");
|
||||||
|
|
||||||
|
|
@ -255,7 +270,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
var manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
var manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile);
|
||||||
if (manifestFile.Exists)
|
if (manifestFile.Exists)
|
||||||
|
{
|
||||||
this.Manifest = LocalPluginManifest.Load(manifestFile);
|
this.Manifest = LocalPluginManifest.Load(manifestFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -548,18 +548,23 @@ namespace Dalamud.Plugin.Internal
|
||||||
PluginLocations.Remove(plugin.AssemblyName.FullName);
|
PluginLocations.Remove(plugin.AssemblyName.FullName);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
catch (BannedPluginException)
|
||||||
|
{
|
||||||
|
// Out of date plugins get added so they can be updated.
|
||||||
|
Log.Information($"Plugin was banned, adding anyways: {dllFile.Name}");
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (plugin.IsDev)
|
if (plugin.IsDev)
|
||||||
{
|
{
|
||||||
// Dev plugins always get added to the list so they can be fiddled with in the UI
|
// Dev plugins always get added to the list so they can be fiddled with in the UI
|
||||||
Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}");
|
Log.Information(ex, $"Dev plugin failed to load, adding anyways: {dllFile.Name}");
|
||||||
plugin.Disable(); // Disable here, otherwise you can't enable+load later
|
plugin.Disable(); // Disable here, otherwise you can't enable+load later
|
||||||
}
|
}
|
||||||
else if (plugin.Manifest.DalamudApiLevel < DalamudApiLevel)
|
else if (plugin.IsOutdated)
|
||||||
{
|
{
|
||||||
// Out of date plugins get added so they can be updated.
|
// Out of date plugins get added so they can be updated.
|
||||||
Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}");
|
Log.Information(ex, $"Plugin was outdated, adding anyways: {dllFile.Name}");
|
||||||
// plugin.Disable(); // Don't disable, or it gets deleted next boot.
|
// plugin.Disable(); // Don't disable, or it gets deleted next boot.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -936,7 +941,12 @@ namespace Dalamud.Plugin.Internal
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsManifestBanned(PluginManifest manifest)
|
/// <summary>
|
||||||
|
/// Determine if a plugin has been banned by inspecting the manifest.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="manifest">Manifest to inspect.</param>
|
||||||
|
/// <returns>A value indicating whether the plugin/manifest has been banned.</returns>
|
||||||
|
public bool IsManifestBanned(PluginManifest manifest)
|
||||||
{
|
{
|
||||||
return this.bannedPlugins.Any(ban => ban.Name == manifest.InternalName && ban.AssemblyVersion == manifest.AssemblyVersion);
|
return this.bannedPlugins.Any(ban => ban.Name == manifest.InternalName && ban.AssemblyVersion == manifest.AssemblyVersion);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue