This commit is contained in:
goat 2020-12-08 09:06:27 +01:00
commit c57d276065
2 changed files with 95 additions and 52 deletions

View file

@ -40,6 +40,17 @@ namespace Dalamud.Plugin
private PluginInstallStatus installStatus = PluginInstallStatus.None; private PluginInstallStatus installStatus = PluginInstallStatus.None;
private enum PluginFilter {
None,
Installed,
NotInstalled,
Updated,
Testing
}
private PluginFilter filter = PluginFilter.None;
private string filterText = "None";
public PluginInstallerWindow(Dalamud dalamud, string gameVersion) { public PluginInstallerWindow(Dalamud dalamud, string gameVersion) {
this.dalamud = dalamud; this.dalamud = dalamud;
this.gameVersion = gameVersion; this.gameVersion = gameVersion;
@ -57,9 +68,43 @@ namespace Dalamud.Plugin
ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar); ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar);
ImGui.Text(Loc.Localize("InstallerHint", "This window allows you install and remove in-game plugins.\nThey are made by third-party developers.")); ImGui.Text(Loc.Localize("InstallerHint", "This window allows you install and remove in-game plugins.\nThey are made by third-party developers."));
ImGui.SameLine(ImGui.GetWindowWidth() - 250 * ImGui.GetIO().FontGlobalScale);
ImGui.SameLine(ImGui.GetWindowWidth() - ((250 + 90 + ImGui.CalcTextSize(Loc.Localize("PluginFilter", "Filter")).X) * ImGui.GetIO().FontGlobalScale));
ImGui.SetNextItemWidth(240 * ImGui.GetIO().FontGlobalScale); ImGui.SetNextItemWidth(240 * ImGui.GetIO().FontGlobalScale);
ImGui.InputTextWithHint("###XPlPluginInstaller_Search", Loc.Localize("InstallerSearch", "Search"), ref this.searchText, 100); ImGui.InputTextWithHint("###XPlPluginInstaller_Search", Loc.Localize("InstallerSearch", "Search"), ref this.searchText, 100);
ImGui.SameLine();
ImGui.SetNextItemWidth(80 * ImGui.GetIO().FontGlobalScale);
if (ImGui.BeginCombo(Loc.Localize("PluginFilter", "Filter"), this.filterText, ImGuiComboFlags.NoArrowButton)) {
if (ImGui.Selectable(Loc.Localize("FilterNone", "None"))) {
this.filter = PluginFilter.None;
this.filterText = Loc.Localize("FilterNone", "None");
}
if (ImGui.Selectable(Loc.Localize("FilterInstalled", "Installed"))) {
this.filter = PluginFilter.Installed;
this.filterText = Loc.Localize("FilterInstalled", "Installed");
}
if (ImGui.Selectable(Loc.Localize("FilterNotInstalled", "Not installed"))) {
this.filter = PluginFilter.NotInstalled;
this.filterText = Loc.Localize("FilterNotInstalled", "Not installed");
}
if (ImGui.Selectable(Loc.Localize("FilterUpdated", "Updated"))) {
this.filter = PluginFilter.Updated;
this.filterText = Loc.Localize("FilterUpdated", "Updated");
}
if (this.dalamud.Configuration.DoPluginTest && ImGui.Selectable(Loc.Localize("FilterTesting", "Testing"))) {
this.filter = PluginFilter.Testing;
this.filterText = Loc.Localize("FilterTesting", "Testing");
}
ImGui.EndCombo();
}
ImGui.Separator(); ImGui.Separator();
ImGui.BeginChild("scrolling", new Vector2(0, 400 * ImGui.GetIO().FontGlobalScale), true, ImGuiWindowFlags.HorizontalScrollbar); ImGui.BeginChild("scrolling", new Vector2(0, 400 * ImGui.GetIO().FontGlobalScale), true, ImGuiWindowFlags.HorizontalScrollbar);
@ -103,17 +148,6 @@ namespace Dalamud.Plugin
var isInstalled = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any( var isInstalled = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any(
x => x.Definition.InternalName == pluginDefinition.InternalName); x => x.Definition.InternalName == pluginDefinition.InternalName);
var label = isInstalled ? Loc.Localize("InstallerInstalled", " (installed)") : string.Empty;
label = this.updatedPlugins != null &&
this.updatedPlugins.Any(x => x.InternalName == pluginDefinition.InternalName && x.WasUpdated)
? Loc.Localize("InstallerUpdated", " (updated)")
: label;
label = this.updatedPlugins != null &&
this.updatedPlugins.Any(x => x.InternalName == pluginDefinition.InternalName && x.WasUpdated == false)
? Loc.Localize("InstallerUpdateFailed", " (update failed)")
: label;
var isTestingAvailable = false; var isTestingAvailable = false;
if (Version.TryParse(pluginDefinition.AssemblyVersion, out var assemblyVersion) && Version.TryParse(pluginDefinition.TestingAssemblyVersion, out var testingAssemblyVersion)) if (Version.TryParse(pluginDefinition.AssemblyVersion, out var assemblyVersion) && Version.TryParse(pluginDefinition.TestingAssemblyVersion, out var testingAssemblyVersion))
isTestingAvailable = this.dalamud.Configuration.DoPluginTest && testingAssemblyVersion > assemblyVersion; isTestingAvailable = this.dalamud.Configuration.DoPluginTest && testingAssemblyVersion > assemblyVersion;
@ -124,7 +158,29 @@ namespace Dalamud.Plugin
continue; continue;
} }
label += isTestingAvailable ? " (testing version)" : string.Empty; var label = string.Empty;
if (isInstalled) {
label += Loc.Localize("InstallerInstalled", " (installed)");
if (this.filter == PluginFilter.NotInstalled) {
continue;
}
} else if (this.filter == PluginFilter.Installed) {
continue;
}
if (this.updatedPlugins != null && this.updatedPlugins.Any(x => x.InternalName == pluginDefinition.InternalName && x.WasUpdated == true)) {
label += Loc.Localize("InstallerUpdated", " (updated)");
} else if (this.updatedPlugins != null && this.updatedPlugins.Any(x => x.InternalName == pluginDefinition.InternalName && x.WasUpdated == false)) {
label += Loc.Localize("InstallerUpdateFailed", " (update failed)");
} else if (this.filter == PluginFilter.Updated) {
continue;
}
if (isTestingAvailable) {
label += " (testing version)";
} else if (this.filter == PluginFilter.Testing) {
continue;
}
ImGui.PushID(pluginDefinition.InternalName + pluginDefinition.AssemblyVersion); ImGui.PushID(pluginDefinition.InternalName + pluginDefinition.AssemblyVersion);

View file

@ -12,8 +12,7 @@ using Serilog;
namespace Dalamud.Plugin namespace Dalamud.Plugin
{ {
internal class PluginRepository internal class PluginRepository {
{
private string PluginFunctionBaseUrl => "https://us-central1-xl-functions.cloudfunctions.net/download-plugin/?plugin={0}&isUpdate={1}&isTesting={2}"; private string PluginFunctionBaseUrl => "https://us-central1-xl-functions.cloudfunctions.net/download-plugin/?plugin={0}&isUpdate={1}&isTesting={2}";
private string PluginMasterUrl => "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/master/pluginmaster.json"; private string PluginMasterUrl => "https://raw.githubusercontent.com/goatcorp/DalamudPlugins/master/pluginmaster.json";
@ -31,21 +30,18 @@ namespace Dalamud.Plugin
public InitializationState State { get; private set; } public InitializationState State { get; private set; }
public PluginRepository(Dalamud dalamud, string pluginDirectory, string gameVersion) public PluginRepository(Dalamud dalamud, string pluginDirectory, string gameVersion) {
{
this.dalamud = dalamud; this.dalamud = dalamud;
this.pluginDirectory = pluginDirectory; this.pluginDirectory = pluginDirectory;
ReloadPluginMasterAsync(); ReloadPluginMasterAsync();
} }
public void ReloadPluginMasterAsync() public void ReloadPluginMasterAsync() {
{
Task.Run(() => { Task.Run(() => {
State = InitializationState.InProgress; State = InitializationState.InProgress;
try try {
{
using var client = new WebClient(); using var client = new WebClient();
var data = client.DownloadString(PluginMasterUrl); var data = client.DownloadString(PluginMasterUrl);
@ -56,8 +52,7 @@ namespace Dalamud.Plugin
State = InitializationState.Success; State = InitializationState.Success;
} }
catch (Exception ex) catch (Exception ex) {
{
Log.Error(ex, "Could not download PluginMaster"); Log.Error(ex, "Could not download PluginMaster");
State = InitializationState.Fail; State = InitializationState.Fail;
} }
@ -68,16 +63,14 @@ namespace Dalamud.Plugin
} }
public bool InstallPlugin(PluginDefinition definition, bool enableAfterInstall = true, bool isUpdate = false, bool fromTesting = false) { public bool InstallPlugin(PluginDefinition definition, bool enableAfterInstall = true, bool isUpdate = false, bool fromTesting = false) {
try try {
{
var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, fromTesting ? definition.TestingAssemblyVersion : definition.AssemblyVersion)); var outputDir = new DirectoryInfo(Path.Combine(this.pluginDirectory, definition.InternalName, fromTesting ? definition.TestingAssemblyVersion : definition.AssemblyVersion));
var dllFile = new FileInfo(Path.Combine(outputDir.FullName, $"{definition.InternalName}.dll")); var dllFile = new FileInfo(Path.Combine(outputDir.FullName, $"{definition.InternalName}.dll"));
var disabledFile = new FileInfo(Path.Combine(outputDir.FullName, ".disabled")); var disabledFile = new FileInfo(Path.Combine(outputDir.FullName, ".disabled"));
var testingFile = new FileInfo(Path.Combine(outputDir.FullName, ".testing")); var testingFile = new FileInfo(Path.Combine(outputDir.FullName, ".testing"));
var wasDisabled = disabledFile.Exists; var wasDisabled = disabledFile.Exists;
if (dllFile.Exists && enableAfterInstall) if (dllFile.Exists && enableAfterInstall) {
{
if (disabledFile.Exists) if (disabledFile.Exists)
disabledFile.Delete(); disabledFile.Delete();
@ -130,8 +123,7 @@ namespace Dalamud.Plugin
return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false, PluginLoadReason.Installer); return this.dalamud.PluginManager.LoadPluginFromAssembly(dllFile, false, PluginLoadReason.Installer);
} }
catch (Exception e) catch (Exception e) {
{
Log.Error(e, "Plugin download failed hard."); Log.Error(e, "Plugin download failed hard.");
return false; return false;
} }
@ -142,18 +134,15 @@ namespace Dalamud.Plugin
public bool WasUpdated { get; set; } public bool WasUpdated { get; set; }
} }
public (bool Success, List<PluginUpdateStatus> UpdatedPlugins) UpdatePlugins(bool dryRun = false) public (bool Success, List<PluginUpdateStatus> UpdatedPlugins) UpdatePlugins(bool dryRun = false) {
{
Log.Information("Starting plugin update... dry:{0}", dryRun); Log.Information("Starting plugin update... dry:{0}", dryRun);
var updatedList = new List<PluginUpdateStatus>(); var updatedList = new List<PluginUpdateStatus>();
var hasError = false; var hasError = false;
try try {
{
var pluginsDirectory = new DirectoryInfo(this.pluginDirectory); var pluginsDirectory = new DirectoryInfo(this.pluginDirectory);
foreach (var installed in pluginsDirectory.GetDirectories()) foreach (var installed in pluginsDirectory.GetDirectories()) {
{
try { try {
var versions = installed.GetDirectories(); var versions = installed.GetDirectories();
@ -162,8 +151,7 @@ namespace Dalamud.Plugin
continue; continue;
} }
var sortedVersions = versions.OrderBy(dirInfo => var sortedVersions = versions.OrderBy(dirInfo => {
{
var success = Version.TryParse(dirInfo.Name, out Version version); var success = Version.TryParse(dirInfo.Name, out Version version);
if (!success) { Log.Debug("Unparseable version: {0}", dirInfo.Name); } if (!success) { Log.Debug("Unparseable version: {0}", dirInfo.Name); }
return version; return version;
@ -263,8 +251,7 @@ namespace Dalamud.Plugin
} }
} }
} }
catch (Exception e) catch (Exception e) {
{
Log.Error(e, "Plugin update failed."); Log.Error(e, "Plugin update failed.");
hasError = true; hasError = true;
} }
@ -275,32 +262,32 @@ namespace Dalamud.Plugin
} }
public void CleanupPlugins() { public void CleanupPlugins() {
try try {
{
var pluginsDirectory = new DirectoryInfo(this.pluginDirectory); var pluginsDirectory = new DirectoryInfo(this.pluginDirectory);
foreach (var installed in pluginsDirectory.GetDirectories()) foreach (var installed in pluginsDirectory.GetDirectories()) {
{
var versions = installed.GetDirectories(); var versions = installed.GetDirectories();
if (versions.Length == 0) if (versions.Length == 0) {
{
Log.Information("[PLUGINR] Has no versions: {0}", installed.FullName); Log.Information("[PLUGINR] Has no versions: {0}", installed.FullName);
continue; continue;
} }
var sortedVersions = versions.OrderBy(x => int.Parse(x.Name.Replace(".", ""))).ToArray(); var sortedVersions = versions.OrderBy(x => int.Parse(x.Name.Replace(".", ""))).ToArray();
for (var i = 0; i < sortedVersions.Length - 1; i++) { for (var i = 0; i < sortedVersions.Length - 1; i++) {
Log.Information("[PLUGINR] Trying to delete old {0} at {1}", installed.Name, sortedVersions[i].FullName); var disabledFile = new FileInfo(Path.Combine(sortedVersions[i].FullName, ".disabled"));
try { if (disabledFile.Exists) {
sortedVersions[i].Delete(true); Log.Information("[PLUGINR] Trying to delete old {0} at {1}", installed.Name, sortedVersions[i].FullName);
} catch (Exception ex) { try {
Log.Error(ex, "[PLUGINR] Could not delete old version"); sortedVersions[i].Delete(true);
}
catch (Exception ex) {
Log.Error(ex, "[PLUGINR] Could not delete old version");
}
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex) {
{
Log.Error(ex, "[PLUGINR] Plugin cleanup failed."); Log.Error(ex, "[PLUGINR] Plugin cleanup failed.");
} }
} }