mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
feat: move plugin update into separate function, add update button to applicable available plugin
This commit is contained in:
parent
83edcc583f
commit
12adc4099f
2 changed files with 92 additions and 66 deletions
|
|
@ -591,8 +591,9 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
label += Locs.PluginTitleMod_UnloadError;
|
label += Locs.PluginTitleMod_UnloadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var availablePluginUpdate = this.pluginListUpdatable.FirstOrDefault(up => up.InstalledPlugin == plugin);
|
||||||
// Update available
|
// Update available
|
||||||
if (this.pluginListUpdatable.FirstOrDefault(up => up.InstalledPlugin == plugin) != default)
|
if (availablePluginUpdate != default)
|
||||||
{
|
{
|
||||||
label += Locs.PluginTitleMod_HasUpdate;
|
label += Locs.PluginTitleMod_HasUpdate;
|
||||||
}
|
}
|
||||||
|
|
@ -676,6 +677,9 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
this.DrawDevPluginButtons(plugin);
|
this.DrawDevPluginButtons(plugin);
|
||||||
this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl);
|
this.DrawVisitRepoUrlButton(plugin.Manifest.RepoUrl);
|
||||||
|
|
||||||
|
if (availablePluginUpdate != default)
|
||||||
|
this.DrawUpdateSinglePluginButton(plugin, availablePluginUpdate);
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.TextColored(ImGuiColors.DalamudGrey3, $" v{plugin.Manifest.AssemblyVersion}");
|
ImGui.TextColored(ImGuiColors.DalamudGrey3, $" v{plugin.Manifest.AssemblyVersion}");
|
||||||
|
|
||||||
|
|
@ -776,6 +780,19 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DrawUpdateSinglePluginButton(LocalPlugin plugin, AvailablePluginUpdate update)
|
||||||
|
{
|
||||||
|
ImGui.SameLine();
|
||||||
|
|
||||||
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.Download))
|
||||||
|
{
|
||||||
|
this.dalamud.PluginManager.UpdateSinglePlugin(update, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemHovered())
|
||||||
|
ImGui.SetTooltip(Locs.PluginButtonToolTip_UpdateSingle(update.UpdateManifest.AssemblyVersion.ToString()));
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawOpenPluginSettingsButton(LocalPlugin plugin)
|
private void DrawOpenPluginSettingsButton(LocalPlugin plugin)
|
||||||
{
|
{
|
||||||
if (plugin.DalamudInterface?.UiBuilder?.HasConfigUi ?? false)
|
if (plugin.DalamudInterface?.UiBuilder?.HasConfigUi ?? false)
|
||||||
|
|
@ -1130,6 +1147,8 @@ namespace Dalamud.Interface.Internal.Windows
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Footer
|
#region Footer
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ using Dalamud.Game.Text;
|
||||||
using Dalamud.Plugin.Internal.Exceptions;
|
using Dalamud.Plugin.Internal.Exceptions;
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Dalamud.Plugin.Internal
|
namespace Dalamud.Plugin.Internal
|
||||||
|
|
@ -599,84 +600,90 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
Log.Information("Starting plugin update");
|
Log.Information("Starting plugin update");
|
||||||
|
|
||||||
var listChanged = false;
|
|
||||||
|
|
||||||
var updatedList = new List<PluginUpdateStatus>();
|
var updatedList = new List<PluginUpdateStatus>();
|
||||||
|
|
||||||
// Prevent collection was modified errors
|
// Prevent collection was modified errors
|
||||||
for (var i = 0; i < this.updatablePlugins.Count; i++)
|
for (var i = 0; i < this.updatablePlugins.Count; i++)
|
||||||
{
|
{
|
||||||
var metadata = this.updatablePlugins[i];
|
updatedList.Add(this.UpdateSinglePlugin(this.updatablePlugins[i], dryRun));
|
||||||
|
|
||||||
var plugin = metadata.InstalledPlugin;
|
|
||||||
|
|
||||||
// Can't update that!
|
|
||||||
if (plugin is LocalDevPlugin)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var updateStatus = new PluginUpdateStatus()
|
|
||||||
{
|
|
||||||
InternalName = plugin.Manifest.InternalName,
|
|
||||||
Name = plugin.Manifest.Name,
|
|
||||||
Version = metadata.UseTesting
|
|
||||||
? metadata.UpdateManifest.TestingAssemblyVersion
|
|
||||||
: metadata.UpdateManifest.AssemblyVersion,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (dryRun)
|
|
||||||
{
|
|
||||||
updateStatus.WasUpdated = true;
|
|
||||||
updatedList.Add(updateStatus);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Unload if loaded
|
|
||||||
if (plugin.State == PluginState.Loaded || plugin.State == PluginState.LoadError)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
plugin.Unload();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, "Error during unload (update)");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
plugin.Disable();
|
|
||||||
this.installedPlugins.Remove(plugin);
|
|
||||||
listChanged = true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, "Error during disable (update)");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.InstallPlugin(metadata.UpdateManifest, metadata.UseTesting, PluginLoadReason.Update);
|
|
||||||
listChanged = true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log.Error(ex, "Error during install (update)");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listChanged)
|
this.NotifyInstalledPluginsChanged();
|
||||||
this.NotifyInstalledPluginsChanged();
|
|
||||||
|
|
||||||
Log.Information("Plugin update OK.");
|
Log.Information("Plugin update OK.");
|
||||||
|
|
||||||
return updatedList;
|
return updatedList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update a single plugin, provided a valid <see cref="AvailablePluginUpdate"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="metadata">The available plugin update.</param>
|
||||||
|
/// <param name="dryRun">Whether or not to actually perform the update, or just indicate success.</param>
|
||||||
|
/// <returns>The status of the update.</returns>
|
||||||
|
[CanBeNull]
|
||||||
|
public PluginUpdateStatus UpdateSinglePlugin(AvailablePluginUpdate metadata, bool dryRun)
|
||||||
|
{
|
||||||
|
var plugin = metadata.InstalledPlugin;
|
||||||
|
|
||||||
|
// Can't update that!
|
||||||
|
if (plugin is LocalDevPlugin)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var updateStatus = new PluginUpdateStatus
|
||||||
|
{
|
||||||
|
InternalName = plugin.Manifest.InternalName,
|
||||||
|
Name = plugin.Manifest.Name,
|
||||||
|
Version = metadata.UseTesting ? metadata.UpdateManifest.TestingAssemblyVersion : metadata.UpdateManifest.AssemblyVersion
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dryRun)
|
||||||
|
{
|
||||||
|
updateStatus.WasUpdated = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateStatus.WasUpdated = true;
|
||||||
|
|
||||||
|
// Unload if loaded
|
||||||
|
if (plugin.State == PluginState.Loaded || plugin.State == PluginState.LoadError)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
plugin.Unload();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Error during unload (update)");
|
||||||
|
updateStatus.WasUpdated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
plugin.Disable();
|
||||||
|
this.installedPlugins.Remove(plugin);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Error during disable (update)");
|
||||||
|
updateStatus.WasUpdated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.InstallPlugin(metadata.UpdateManifest, metadata.UseTesting, PluginLoadReason.Update);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex, "Error during install (update)");
|
||||||
|
updateStatus.WasUpdated = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return updateStatus;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Print to chat any plugin updates and whether they were successful.
|
/// Print to chat any plugin updates and whether they were successful.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue