Merge branch 'net5'

This commit is contained in:
goat 2022-07-14 18:58:13 +02:00
commit d0d38269f9
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5
5 changed files with 57 additions and 25 deletions

View file

@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Feature"> <PropertyGroup Label="Feature">
<DalamudVersion>6.4.0.34</DalamudVersion> <DalamudVersion>6.4.0.36</DalamudVersion>
<Description>XIV Launcher addon framework</Description> <Description>XIV Launcher addon framework</Description>
<AssemblyVersion>$(DalamudVersion)</AssemblyVersion> <AssemblyVersion>$(DalamudVersion)</AssemblyVersion>
<Version>$(DalamudVersion)</Version> <Version>$(DalamudVersion)</Version>

View file

@ -210,7 +210,7 @@ namespace Dalamud.Interface.Internal
/// Opens the <see cref="DataWindow"/>. /// Opens the <see cref="DataWindow"/>.
/// </summary> /// </summary>
/// <param name="dataKind">The data kind to switch to after opening.</param> /// <param name="dataKind">The data kind to switch to after opening.</param>
public void OpenDataWindow(string dataKind = null) public void OpenDataWindow(string? dataKind = null)
{ {
this.dataWindow.IsOpen = true; this.dataWindow.IsOpen = true;
if (dataKind != null && this.dataWindow.IsOpen) if (dataKind != null && this.dataWindow.IsOpen)

View file

@ -1724,7 +1724,6 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
} }
else if (plugin.State == PluginState.Loaded || plugin.State == PluginState.LoadError || plugin.State == PluginState.DependencyResolutionFailed) else if (plugin.State == PluginState.Loaded || plugin.State == PluginState.LoadError || plugin.State == PluginState.DependencyResolutionFailed)
{ {
// TODO: We should draw the trash can button for policy-blocked plugins in safe mode, so plugins can be deleted
if (pluginManager.SafeMode) if (pluginManager.SafeMode)
{ {
ImGuiComponents.DisabledButton(Locs.PluginButton_SafeMode); ImGuiComponents.DisabledButton(Locs.PluginButton_SafeMode);
@ -1932,8 +1931,10 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
private void DrawDeletePluginButton(LocalPlugin plugin) private void DrawDeletePluginButton(LocalPlugin plugin)
{ {
var unloaded = plugin.State == PluginState.Unloaded; var unloaded = plugin.State == PluginState.Unloaded || plugin.State == PluginState.LoadError;
var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated || plugin.IsBanned || plugin.IsOrphaned);
// When policy check fails, the plugin is never loaded
var showButton = unloaded && (plugin.IsDev || plugin.IsOutdated || plugin.IsBanned || plugin.IsOrphaned || !plugin.CheckPolicy());
if (!showButton) if (!showButton)
return; return;
@ -1941,26 +1942,40 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
var pluginManager = Service<PluginManager>.Get(); var pluginManager = Service<PluginManager>.Get();
ImGui.SameLine(); ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt)) if (plugin.HasEverStartedLoad)
{ {
try ImGui.PushFont(InterfaceManager.IconFont);
{ ImGuiComponents.DisabledButton(FontAwesomeIcon.TrashAlt.ToIconString());
plugin.DllFile.Delete(); ImGui.PopFont();
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); if (ImGui.IsItemHovered())
this.errorModalDrawing = true; {
this.errorModalOnNextFrame = true; ImGui.SetTooltip(Locs.PluginButtonToolTip_DeletePluginRestricted);
} }
} }
else
if (ImGui.IsItemHovered())
{ {
ImGui.SetTooltip(Locs.PluginButtonToolTip_DeletePlugin); if (ImGuiComponents.IconButton(FontAwesomeIcon.TrashAlt))
{
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.PluginButtonToolTip_DeletePlugin);
}
} }
} }
@ -2369,6 +2384,8 @@ namespace Dalamud.Interface.Internal.Windows.PluginInstaller
public static string PluginButtonToolTip_DeletePlugin => Loc.Localize("InstallerDeletePlugin ", "Delete plugin"); public static string PluginButtonToolTip_DeletePlugin => Loc.Localize("InstallerDeletePlugin ", "Delete plugin");
public static string PluginButtonToolTip_DeletePluginRestricted => Loc.Localize("InstallerDeletePluginRestricted", "Cannot delete - please try restarting the game.");
public static string PluginButtonToolTip_VisitPluginUrl => Loc.Localize("InstallerVisitPluginUrl", "Visit plugin URL"); public static string PluginButtonToolTip_VisitPluginUrl => Loc.Localize("InstallerVisitPluginUrl", "Visit plugin URL");
public static string PluginButtonToolTip_UpdateSingle(string version) => Loc.Localize("InstallerUpdateSingle", "Update to {0}").Format(version); public static string PluginButtonToolTip_UpdateSingle(string version) => Loc.Localize("InstallerUpdateSingle", "Update to {0}").Format(version);

View file

@ -48,7 +48,7 @@ internal partial class PluginManager : IDisposable, IServiceType
private readonly object pluginListLock = new(); private readonly object pluginListLock = new();
private readonly DirectoryInfo pluginDirectory; private readonly DirectoryInfo pluginDirectory;
private readonly DirectoryInfo devPluginDirectory; private readonly DirectoryInfo devPluginDirectory;
private readonly BannedPlugin[] bannedPlugins; private readonly BannedPlugin[]? bannedPlugins;
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get(); private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get();
@ -78,7 +78,11 @@ internal partial class PluginManager : IDisposable, IServiceType
this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(this.startInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs")); this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(this.startInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs"));
var bannedPluginsJson = File.ReadAllText(Path.Combine(this.startInfo.AssetDirectory!, "UIRes", "bannedplugin.json")); var bannedPluginsJson = File.ReadAllText(Path.Combine(this.startInfo.AssetDirectory!, "UIRes", "bannedplugin.json"));
this.bannedPlugins = JsonConvert.DeserializeObject<BannedPlugin[]>(bannedPluginsJson) ?? Array.Empty<BannedPlugin>(); this.bannedPlugins = JsonConvert.DeserializeObject<BannedPlugin[]>(bannedPluginsJson);
if (this.bannedPlugins == null)
{
throw new InvalidDataException("Couldn't deserialize banned plugins manifest.");
}
this.ApplyPatches(); this.ApplyPatches();
} }
@ -771,8 +775,8 @@ internal partial class PluginManager : IDisposable, IServiceType
/// <param name="plugin">Plugin to remove.</param> /// <param name="plugin">Plugin to remove.</param>
public void RemovePlugin(LocalPlugin plugin) public void RemovePlugin(LocalPlugin plugin)
{ {
if (plugin.State != PluginState.Unloaded) if (plugin.State != PluginState.Unloaded && plugin.HasEverStartedLoad)
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded"); throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded and had loaded before");
lock (this.pluginListLock) lock (this.pluginListLock)
{ {
@ -846,7 +850,7 @@ internal partial class PluginManager : IDisposable, IServiceType
continue; continue;
} }
if (manifest.DalamudApiLevel < DalamudApiLevel - 1 && !configuration.LoadAllApiLevels) if (manifest.DalamudApiLevel < DalamudApiLevel - 1 && !this.configuration.LoadAllApiLevels)
{ {
Log.Information($"Lower API: cleaning up {versionDir.FullName}"); Log.Information($"Lower API: cleaning up {versionDir.FullName}");
versionDir.Delete(true); versionDir.Delete(true);
@ -1060,6 +1064,8 @@ internal partial class PluginManager : IDisposable, IServiceType
/// <returns>A value indicating whether the plugin/manifest has been banned.</returns> /// <returns>A value indicating whether the plugin/manifest has been banned.</returns>
public bool IsManifestBanned(PluginManifest manifest) public bool IsManifestBanned(PluginManifest manifest)
{ {
Debug.Assert(this.bannedPlugins != null, "this.bannedPlugins != null");
return !this.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); && ban.AssemblyVersion >= manifest.AssemblyVersion);
} }
@ -1071,6 +1077,8 @@ internal partial class PluginManager : IDisposable, IServiceType
/// <returns>The reason of the ban, if any.</returns> /// <returns>The reason of the ban, if any.</returns>
public string GetBanReason(PluginManifest manifest) public string GetBanReason(PluginManifest manifest)
{ {
Debug.Assert(this.bannedPlugins != null, "this.bannedPlugins != null");
return this.bannedPlugins.LastOrDefault(ban => ban.Name == manifest.InternalName).Reason; return this.bannedPlugins.LastOrDefault(ban => ban.Name == manifest.InternalName).Reason;
} }

View file

@ -189,6 +189,11 @@ internal class LocalPlugin : IDisposable
/// </summary> /// </summary>
public string BanReason { get; } public string BanReason { get; }
/// <summary>
/// Gets a value indicating whether the plugin has ever started to load.
/// </summary>
public bool HasEverStartedLoad { get; private set; }
/// <summary> /// <summary>
/// Gets a value indicating whether the plugin is loaded and running. /// Gets a value indicating whether the plugin is loaded and running.
/// </summary> /// </summary>
@ -335,6 +340,8 @@ internal class LocalPlugin : IDisposable
"Please refer to https://github.com/goatcorp/Dalamud/discussions/603 for more information."); "Please refer to https://github.com/goatcorp/Dalamud/discussions/603 for more information.");
} }
this.HasEverStartedLoad = true;
this.loader ??= PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig); this.loader ??= PluginLoader.CreateFromAssemblyFile(this.DllFile.FullName, SetupLoaderConfig);
if (reloading || this.IsDev) if (reloading || this.IsDev)