Merge pull request #219 from Aireil/feat_auto_update

Add an auto-updater for plugins
This commit is contained in:
goaaats 2020-12-13 21:11:16 +01:00 committed by GitHub
commit 4a251ed190
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 12 deletions

View file

@ -32,6 +32,7 @@ namespace Dalamud
public bool ToggleUiHideDuringGpose { get; set; } = true;
public bool PrintPluginsWelcomeMsg { get; set; } = true;
public bool AutoUpdatePlugins { get; set; } = false;
[JsonIgnore]
public string ConfigPath;

View file

@ -212,20 +212,34 @@ namespace Dalamud.Game {
this.dalamud.Configuration.Save();
}
try {
var hasNeedsUpdate = this.dalamud.PluginRepository.UpdatePlugins(true).UpdatedPlugins.Count != 0;
Task.Run(() => this.dalamud.PluginRepository.UpdatePlugins(!this.dalamud.Configuration.AutoUpdatePlugins)).ContinueWith(t => {
if (t.IsFaulted) {
Log.Error(t.Exception, Loc.Localize("DalamudPluginUpdateCheckFail", "Could not check for plugin updates."));
} else {
var updatedPlugins = t.Result.UpdatedPlugins;
if (hasNeedsUpdate) {
this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry
{
MessageBytes = Encoding.UTF8.GetBytes(Loc.Localize("DalamudPluginUpdateRequired", "One or more of your plugins needs to be updated. Please use the /xlplugins command in-game to update them!")),
Type = XivChatType.Urgent
});
if (updatedPlugins.Count != 0) {
if (this.dalamud.Configuration.AutoUpdatePlugins) {
this.dalamud.Framework.Gui.Chat.Print(string.Format(Loc.Localize("DalamudPluginUpdateSuccessful", "Auto-update:")));
foreach (var plugin in updatedPlugins) {
if (plugin.WasUpdated) {
this.dalamud.Framework.Gui.Chat.Print(string.Format(Loc.Localize("DalamudPluginUpdateSuccessful", " 》 {0} updated to v{1}."), plugin.Name, plugin.Version));
} else {
this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry {
MessageBytes = Encoding.UTF8.GetBytes(string.Format(Loc.Localize("DalamudPluginUpdateFailed", " 》 {0} update to v{1} failed."), plugin.Name, plugin.Version)),
Type = XivChatType.Urgent
});
}
}
} else {
this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry {
MessageBytes = Encoding.UTF8.GetBytes(Loc.Localize("DalamudPluginUpdateRequired", "One or more of your plugins needs to be updated. Please use the /xlplugins command in-game to update them!")),
Type = XivChatType.Urgent
});
}
}
}
}
catch (Exception e) {
Log.Error(e, Loc.Localize("DalamudPluginUpdateCheckFail", "Could not check for plugin updates."));
}
});
this.hasSeenLoadingMsg = true;
}

View file

@ -30,6 +30,7 @@ namespace Dalamud.Interface
this.doDalamudTest = this.dalamud.Configuration.DoDalamudTest;
this.printPluginsWelcomeMsg = this.dalamud.Configuration.PrintPluginsWelcomeMsg;
this.autoUpdatePlugins = this.dalamud.Configuration.AutoUpdatePlugins;
this.languages = Localization.ApplicableLangCodes.Prepend("en").ToArray();
try {
@ -87,6 +88,7 @@ namespace Dalamud.Interface
private bool doToggleUiHideDuringGpose;
private bool printPluginsWelcomeMsg;
private bool autoUpdatePlugins;
#region Experimental
@ -132,6 +134,9 @@ namespace Dalamud.Interface
ImGui.Checkbox(Loc.Localize("DalamudSettingsPrintPluginsWelcomeMsg", "Display loaded plugins in the welcome message"), ref this.printPluginsWelcomeMsg);
ImGui.TextColored(this.hintTextColor, Loc.Localize("DalamudSettingsPrintPluginsWelcomeMsgHint", "Display loaded plugins in FFXIV chat when logging in with a character."));
ImGui.Checkbox(Loc.Localize("DalamudSettingsAutoUpdatePlugins", "Auto-update plugins"), ref this.autoUpdatePlugins);
ImGui.TextColored(this.hintTextColor, Loc.Localize("DalamudSettingsAutoUpdatePluginsMsgHint", "Automatically update plugins when logging in with a character."));
ImGui.EndTabItem();
}
@ -218,6 +223,7 @@ namespace Dalamud.Interface
this.dalamud.Configuration.DoDalamudTest = this.doDalamudTest;
this.dalamud.Configuration.PrintPluginsWelcomeMsg = this.printPluginsWelcomeMsg;
this.dalamud.Configuration.AutoUpdatePlugins = this.autoUpdatePlugins;
this.dalamud.Configuration.Save();
}

View file

@ -140,6 +140,8 @@ namespace Dalamud.Plugin
internal class PluginUpdateStatus {
public string InternalName { get; set; }
public string Name { get; set; }
public string Version { get; set; }
public bool WasUpdated { get; set; }
}
@ -244,11 +246,15 @@ namespace Dalamud.Plugin
updatedList.Add(new PluginUpdateStatus {
InternalName = remoteInfo.InternalName,
Name = remoteInfo.Name,
Version = testingAvailable ? remoteInfo.TestingAssemblyVersion : remoteInfo.AssemblyVersion,
WasUpdated = installSuccess
});
} else {
updatedList.Add(new PluginUpdateStatus {
InternalName = remoteInfo.InternalName,
Name = remoteInfo.Name,
Version = testingAvailable ? remoteInfo.TestingAssemblyVersion : remoteInfo.AssemblyVersion,
WasUpdated = true
});
}