feat: add "updated" label to plugin installer when a plugin was updated

This commit is contained in:
goat 2020-06-08 14:05:23 +02:00
parent 75b722eae0
commit aa84c06cd1
5 changed files with 52 additions and 23 deletions

View file

@ -51,8 +51,8 @@ namespace Dalamud {
public DiscordBotManager BotManager { get; private set; }
public PluginManager PluginManager { get; private set; }
public PluginRepository PluginRepository { get; private set; }
internal PluginManager PluginManager { get; private set; }
internal PluginRepository PluginRepository { get; private set; }
public readonly ClientState ClientState;

View file

@ -227,7 +227,7 @@ namespace Dalamud.Game {
try
{
var hasNeedsUpdate = this.dalamud.PluginRepository.UpdatePlugins(true).UpdatedCount != 0;
var hasNeedsUpdate = this.dalamud.PluginRepository.UpdatePlugins(true).UpdatedPlugins.Length != 0;
if (hasNeedsUpdate)
{

View file

@ -18,7 +18,7 @@ using Serilog;
namespace Dalamud.Plugin
{
class PluginInstallerWindow {
internal class PluginInstallerWindow {
private const string PluginRepoBaseUrl = "https://goaaats.github.io/DalamudPlugins/";
private PluginManager manager;
@ -30,6 +30,7 @@ namespace Dalamud.Plugin
private bool updateComplete = false;
private int updatePluginCount = 0;
private PluginRepository.PluginUpdateStatus[] updatedInternalName;
private enum PluginInstallStatus {
None,
@ -81,7 +82,18 @@ namespace Dalamud.Plugin
var isInstalled = this.manager.Plugins.Where(x => x.Definition != null).Any(
x => x.Definition.InternalName == pluginDefinition.InternalName);
if (ImGui.CollapsingHeader(pluginDefinition.Name + (isInstalled ? Loc.Localize("InstallerInstalled", " (installed)") : string.Empty) + "###Header" + pluginDefinition.InternalName)) {
var label = isInstalled ? Loc.Localize("InstallerInstalled", " (installed)") : string.Empty;
label = this.updatedInternalName != null &&
this.updatedInternalName.Any(x => x.InternalName == pluginDefinition.InternalName && x.WasUpdated)
? Loc.Localize("InstallerUpdated", " (updated)")
: label;
label = this.updatedInternalName != null &&
this.updatedInternalName.Any(x => x.InternalName == pluginDefinition.InternalName && x.WasUpdated == false)
? Loc.Localize("InstallerUpdateFailed", " (update failed)")
: label;
if (ImGui.CollapsingHeader(pluginDefinition.Name + label + "###Header" + pluginDefinition.InternalName)) {
ImGui.Indent();
ImGui.Text(pluginDefinition.Name);
@ -176,7 +188,8 @@ namespace Dalamud.Plugin
if (this.installStatus == PluginInstallStatus.Success) {
this.updateComplete = true;
this.updatePluginCount = t.Result.UpdatedCount;
this.updatePluginCount = t.Result.UpdatedPlugins.Length;
this.updatedInternalName = t.Result.UpdatedPlugins;
}
this.errorModalDrawing = this.installStatus == PluginInstallStatus.Fail;

View file

@ -36,15 +36,21 @@ namespace Dalamud.Plugin
// This handler should only be invoked on things that fail regular lookups, but it *is* global to this appdomain
AppDomain.CurrentDomain.AssemblyResolve += (object source, ResolveEventArgs e) =>
{
Log.Debug($"Resolving missing assembly {e.Name}");
// This looks weird but I'm pretty sure it's actually correct. Pretty sure. Probably.
var assemblyPath = Path.Combine(Path.GetDirectoryName(e.RequestingAssembly.Location), new AssemblyName(e.Name).Name + ".dll");
if (!File.Exists(assemblyPath))
{
Log.Error($"Assembly not found at {assemblyPath}");
try {
Log.Debug($"Resolving missing assembly {e.Name}");
// This looks weird but I'm pretty sure it's actually correct. Pretty sure. Probably.
var assemblyPath = Path.Combine(Path.GetDirectoryName(e.RequestingAssembly.Location),
new AssemblyName(e.Name).Name + ".dll");
if (!File.Exists(assemblyPath)) {
Log.Error($"Assembly not found at {assemblyPath}");
return null;
}
return Assembly.LoadFrom(assemblyPath);
} catch(Exception ex) {
Log.Error(ex, "Could not load assembly " + e.Name);
return null;
}
return Assembly.LoadFrom(assemblyPath);
};
}

View file

@ -12,7 +12,7 @@ using Serilog;
namespace Dalamud.Plugin
{
public class PluginRepository
internal class PluginRepository
{
private const string PluginRepoBaseUrl = "https://goatcorp.github.io/DalamudPlugins/";
@ -109,11 +109,16 @@ namespace Dalamud.Plugin
}
}
public (bool Success, int UpdatedCount) UpdatePlugins(bool dryRun = false)
internal class PluginUpdateStatus {
public string InternalName { get; set; }
public bool WasUpdated { get; set; }
}
public (bool Success, PluginUpdateStatus[] UpdatedPlugins) UpdatePlugins(bool dryRun = false)
{
Log.Information("Starting plugin update... dry:{0}", dryRun);
var updatedCount = 0;
var updatedList = new List<PluginUpdateStatus>();
var hasError = false;
try
@ -190,18 +195,23 @@ namespace Dalamud.Plugin
var installSuccess = InstallPlugin(remoteInfo, wasEnabled);
if (installSuccess)
{
updatedCount++;
}
else
if (!installSuccess)
{
Log.Error("InstallPlugin failed.");
hasError = true;
}
updatedList.Add(new PluginUpdateStatus {
InternalName = remoteInfo.InternalName,
WasUpdated = installSuccess
});
}
else {
updatedCount++;
updatedList.Add(new PluginUpdateStatus
{
InternalName = remoteInfo.InternalName,
WasUpdated = true
});
}
}
else
@ -218,7 +228,7 @@ namespace Dalamud.Plugin
Log.Information("Plugin update OK.");
return (!hasError, updatedCount);
return (!hasError, updatedList.ToArray());
}
}
}