mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-18 22:07:44 +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
|
|
@ -17,6 +17,7 @@ using Dalamud.Game.Text;
|
|||
using Dalamud.Plugin.Internal.Exceptions;
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using HarmonyLib;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dalamud.Plugin.Internal
|
||||
|
|
@ -599,84 +600,90 @@ namespace Dalamud.Plugin.Internal
|
|||
{
|
||||
Log.Information("Starting plugin update");
|
||||
|
||||
var listChanged = false;
|
||||
|
||||
var updatedList = new List<PluginUpdateStatus>();
|
||||
|
||||
// Prevent collection was modified errors
|
||||
for (var i = 0; i < this.updatablePlugins.Count; i++)
|
||||
{
|
||||
var metadata = this.updatablePlugins[i];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
updatedList.Add(this.UpdateSinglePlugin(this.updatablePlugins[i], dryRun));
|
||||
}
|
||||
|
||||
if (listChanged)
|
||||
this.NotifyInstalledPluginsChanged();
|
||||
this.NotifyInstalledPluginsChanged();
|
||||
|
||||
Log.Information("Plugin update OK.");
|
||||
|
||||
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>
|
||||
/// Print to chat any plugin updates and whether they were successful.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue