refactor: new code style in PluginInstallerWindow.cs

This commit is contained in:
goat 2021-04-01 20:53:49 +02:00
parent a295cec35e
commit 03b1927434

View file

@ -1,25 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Http;
using System.Numerics; using System.Numerics;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CheapLoc; using CheapLoc;
using Dalamud.Interface; using Dalamud.Interface;
using ImGuiNET; using ImGuiNET;
using Newtonsoft.Json;
using Serilog; using Serilog;
namespace Dalamud.Plugin namespace Dalamud.Plugin
{ {
internal class PluginInstallerWindow { /// <summary>
/// Class responsible for drawing the plugin installer.
/// </summary>
internal class PluginInstallerWindow
{
private readonly Dalamud dalamud; private readonly Dalamud dalamud;
private readonly Vector4 colorGrey = new Vector4(0.70f, 0.70f, 0.70f, 1.00f);
private string gameVersion; private string gameVersion;
private bool errorModalDrawing = true; private bool errorModalDrawing = true;
@ -32,29 +32,20 @@ namespace Dalamud.Plugin
private List<PluginDefinition> pluginListAvailable; private List<PluginDefinition> pluginListAvailable;
private List<PluginDefinition> pluginListInstalled; private List<PluginDefinition> pluginListInstalled;
private string searchText = ""; private string searchText = string.Empty;
private readonly Vector4 colorGrey = new Vector4(0.70f, 0.70f, 0.70f, 1.00f);
private enum PluginInstallStatus {
None,
InProgress,
Success,
Fail
}
private PluginInstallStatus installStatus = PluginInstallStatus.None;
private enum PluginSortKind {
Alphabetical,
DownloadCount,
LastUpdate
}
private PluginSortKind sortKind = PluginSortKind.Alphabetical; private PluginSortKind sortKind = PluginSortKind.Alphabetical;
private string filterText = Loc.Localize("SortAlphabetical", "Alphabetical"); private string filterText = Loc.Localize("SortAlphabetical", "Alphabetical");
public PluginInstallerWindow(Dalamud dalamud, string gameVersion) { private PluginInstallStatus installStatus = PluginInstallStatus.None;
/// <summary>
/// Initializes a new instance of the <see cref="PluginInstallerWindow"/> class.
/// </summary>
/// <param name="dalamud">The relevant Dalamud instance.</param>
/// <param name="gameVersion">The version of the game.</param>
public PluginInstallerWindow(Dalamud dalamud, string gameVersion)
{
this.dalamud = dalamud; this.dalamud = dalamud;
this.gameVersion = gameVersion; this.gameVersion = gameVersion;
@ -62,12 +53,236 @@ namespace Dalamud.Plugin
this.dalamud.PluginRepository.ReloadPluginMasterAsync(); this.dalamud.PluginRepository.ReloadPluginMasterAsync();
} }
private void RefetchPlugins() { private enum PluginInstallStatus
{
None,
InProgress,
Success,
Fail,
}
private enum PluginSortKind
{
Alphabetical,
DownloadCount,
LastUpdate,
}
/// <summary>
/// Draw the plugin installer view ImGui.
/// </summary>
/// <returns>Whether or not the plugin installer window is open.</returns>
public bool Draw()
{
var windowOpen = true;
ImGui.SetNextWindowSize(new Vector2(810, 520) * ImGui.GetIO().FontGlobalScale);
ImGui.Begin(
Loc.Localize("InstallerHeader", "Plugin Installer") + (this.dalamud.Configuration.DoPluginTest ? " (TESTING)" : string.Empty) + "###XlPluginInstaller",
ref windowOpen,
ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (5 * ImGui.GetIO().FontGlobalScale));
var descriptionText = Loc.Localize("InstallerHint", "This window allows you to install and remove in-game plugins.\nThey are made by third-party developers.");
ImGui.Text(descriptionText);
var sortingTextSize = ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")) + ImGui.CalcTextSize(Loc.Localize("PluginSort", "Sort By"));
ImGui.SameLine(ImGui.GetWindowWidth() - sortingTextSize.X - ((250 + 20) * ImGui.GetIO().FontGlobalScale));
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (ImGui.CalcTextSize(descriptionText).Y / 4) - 2);
ImGui.SetCursorPosX(ImGui.GetWindowWidth() - sortingTextSize.X - ((250 + 20) * ImGui.GetIO().FontGlobalScale));
ImGui.SetNextItemWidth(240 * ImGui.GetIO().FontGlobalScale);
ImGui.InputTextWithHint("###XPlPluginInstaller_Search", Loc.Localize("InstallerSearch", "Search"), ref this.searchText, 100);
ImGui.SameLine();
ImGui.SetNextItemWidth((10 * ImGui.GetIO().FontGlobalScale) + ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")).X);
if (ImGui.BeginCombo(Loc.Localize("PluginSort", "Sort By"), this.filterText, ImGuiComboFlags.NoArrowButton))
{
if (ImGui.Selectable(Loc.Localize("SortAlphabetical", "Alphabetical")))
{
this.sortKind = PluginSortKind.Alphabetical;
this.filterText = Loc.Localize("SortAlphabetical", "Alphabetical");
this.ResortPlugins();
}
if (ImGui.Selectable(Loc.Localize("SortDownloadCounts", "Download Count")))
{
this.sortKind = PluginSortKind.DownloadCount;
this.filterText = Loc.Localize("SortDownloadCounts", "Download Count");
this.ResortPlugins();
}
if (ImGui.Selectable(Loc.Localize("SortLastUpdate", "Last Update")))
{
this.sortKind = PluginSortKind.LastUpdate;
this.filterText = Loc.Localize("SortLastUpdate", "Last Update");
this.ResortPlugins();
}
ImGui.EndCombo();
}
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (5 * ImGui.GetIO().FontGlobalScale));
string initializationStatusText = null;
if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.InProgress)
{
initializationStatusText = Loc.Localize("InstallerLoading", "Loading plugins...");
this.pluginListAvailable = null;
}
else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail)
{
initializationStatusText = Loc.Localize("InstallerDownloadFailed", "Download failed.");
this.pluginListAvailable = null;
}
else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.FailThirdRepo)
{
initializationStatusText = Loc.Localize("InstallerDownloadFailedThird", "One of your third party repos is unreachable or there is no internet connection.");
this.pluginListAvailable = null;
}
else
{
if (this.pluginListAvailable == null)
{
this.RefetchPlugins();
}
}
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(1, 3) * ImGui.GetIO().FontGlobalScale);
if (ImGui.BeginTabBar("PluginsTabBar", ImGuiTabBarFlags.NoTooltip))
{
this.DrawTab(false, initializationStatusText);
this.DrawTab(true, initializationStatusText);
ImGui.EndTabBar();
ImGui.Separator();
}
ImGui.PopStyleVar();
ImGui.Dummy(new Vector2(3f, 3f) * ImGui.GetIO().FontGlobalScale);
if (this.installStatus == PluginInstallStatus.InProgress)
{
ImGui.Button(Loc.Localize("InstallerUpdating", "Updating..."));
}
else
{
if (this.updateComplete)
{
ImGui.Button(this.updatePluginCount == 0
? Loc.Localize("InstallerNoUpdates", "No updates found!")
: string.Format(Loc.Localize("InstallerUpdateComplete", "{0} plugins updated!"), this.updatePluginCount));
}
else
{
if (ImGui.Button(Loc.Localize("InstallerUpdatePlugins", "Update plugins")))
{
this.installStatus = PluginInstallStatus.InProgress;
Task.Run(() => this.dalamud.PluginRepository.UpdatePlugins()).ContinueWith(t =>
{
this.installStatus =
t.Result.Success ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
this.installStatus =
t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus;
if (this.installStatus == PluginInstallStatus.Success)
{
this.updateComplete = true;
}
if (t.Result.UpdatedPlugins != null)
{
this.updatePluginCount = t.Result.UpdatedPlugins.Count;
this.updatedPlugins = t.Result.UpdatedPlugins;
}
this.errorModalDrawing = this.installStatus == PluginInstallStatus.Fail;
this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail;
this.dalamud.PluginRepository.PrintUpdatedPlugins(this.updatedPlugins, Loc.Localize("DalamudPluginUpdates", "Updates:"));
});
}
}
}
ImGui.SameLine();
if (ImGui.Button(Loc.Localize("SettingsInstaller", "Settings")))
{
this.dalamud.DalamudUi.OpenSettings();
}
var closeText = Loc.Localize("Close", "Close");
ImGui.SameLine(ImGui.GetWindowWidth() - ImGui.CalcTextSize(closeText).X - (16 * ImGui.GetIO().FontGlobalScale));
if (ImGui.Button(closeText))
{
windowOpen = false;
this.dalamud.Configuration.Save();
}
if (ImGui.BeginPopupModal(Loc.Localize("InstallerError", "Installer failed"), ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize))
{
var message = Loc.Localize(
"InstallerErrorHint",
"The plugin installer ran into an issue or the plugin is incompatible.\nPlease restart the game and report this error on our discord.");
if (this.updatedPlugins != null)
{
if (this.updatedPlugins.Any(x => x.WasUpdated == false))
{
var extraInfoMessage = Loc.Localize(
"InstallerErrorPluginInfo",
"\n\nThe following plugins caused these issues:\n\n{0}\nYou may try removing these plugins manually and reinstalling them.");
var insert = this.updatedPlugins.Where(x => x.WasUpdated == false)
.Aggregate(
string.Empty,
(current, pluginUpdateStatus) =>
current + $"* {pluginUpdateStatus.InternalName}\n");
extraInfoMessage = string.Format(extraInfoMessage, insert);
message += extraInfoMessage;
}
}
ImGui.Text(message);
ImGui.Spacing();
if (ImGui.Button(Loc.Localize("OK", "OK"), new Vector2(120, 40)))
{
ImGui.CloseCurrentPopup();
}
ImGui.EndPopup();
}
if (this.errorModalOnNextFrame)
{
ImGui.OpenPopup(Loc.Localize("InstallerError", "Installer failed"));
this.errorModalOnNextFrame = false;
}
ImGui.End();
return windowOpen;
}
private void RefetchPlugins()
{
var hiddenPlugins = this.dalamud.PluginManager.Plugins.Where( var hiddenPlugins = this.dalamud.PluginManager.Plugins.Where(
x => this.dalamud.PluginRepository.PluginMaster.All( x => this.dalamud.PluginRepository.PluginMaster.All(
y => y.InternalName != x.Definition.InternalName || y.InternalName == x.Definition.InternalName && y.IsHide)).Select(x => x.Definition).ToList(); y => y.InternalName != x.Definition.InternalName || (y.InternalName == x.Definition.InternalName && y.IsHide))).Select(x => x.Definition).ToList();
this.pluginListInstalled = this.dalamud.PluginRepository.PluginMaster this.pluginListInstalled = this.dalamud.PluginRepository.PluginMaster
.Where(def => { .Where(def =>
{
return this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any( return this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).Any(
x => x.Definition.InternalName == def.InternalName); x => x.Definition.InternalName == def.InternalName);
}) })
@ -76,16 +291,18 @@ namespace Dalamud.Plugin
this.pluginListInstalled.AddRange(hiddenPlugins); this.pluginListInstalled.AddRange(hiddenPlugins);
this.pluginListInstalled.Sort((x, y) => x.Name.CompareTo(y.Name)); this.pluginListInstalled.Sort((x, y) => x.Name.CompareTo(y.Name));
ResortPlugins(); this.ResortPlugins();
} }
private void ResortPlugins() { private void ResortPlugins()
{
var availableDefs = this.dalamud.PluginRepository.PluginMaster.Where( var availableDefs = this.dalamud.PluginRepository.PluginMaster.Where(
x => this.pluginListInstalled.All(y => x.InternalName != y.InternalName)) x => this.pluginListInstalled.All(y => x.InternalName != y.InternalName))
.GroupBy(x => new { x.InternalName, x.AssemblyVersion }) .GroupBy(x => new { x.InternalName, x.AssemblyVersion })
.Select(y => y.First()).ToList(); .Select(y => y.First()).ToList();
switch (this.sortKind) { switch (this.sortKind)
{
case PluginSortKind.Alphabetical: case PluginSortKind.Alphabetical:
this.pluginListAvailable = availableDefs.OrderBy(x => x.Name).ToList(); this.pluginListAvailable = availableDefs.OrderBy(x => x.Name).ToList();
this.pluginListInstalled.Sort((x, y) => x.Name.CompareTo(y.Name)); this.pluginListInstalled.Sort((x, y) => x.Name.CompareTo(y.Name));
@ -103,198 +320,36 @@ namespace Dalamud.Plugin
} }
} }
public bool Draw() { private void DrawTab(bool installed, string statusText)
var windowOpen = true; {
ImGui.SetNextWindowSize(new Vector2(810, 520) * ImGui.GetIO().FontGlobalScale);
ImGui.Begin(Loc.Localize("InstallerHeader", "Plugin Installer") + (this.dalamud.Configuration.DoPluginTest ? " (TESTING)" : string.Empty) + "###XlPluginInstaller", ref windowOpen,
ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (5 * ImGui.GetIO().FontGlobalScale));
var descriptionText = Loc.Localize("InstallerHint", "This window allows you to install and remove in-game plugins.\nThey are made by third-party developers.");
ImGui.Text(descriptionText);
var sortingTextSize = ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")) + ImGui.CalcTextSize(Loc.Localize("PluginSort", "Sort By"));
ImGui.SameLine(ImGui.GetWindowWidth() - sortingTextSize.X - ((250 + 20) * ImGui.GetIO().FontGlobalScale));
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (ImGui.CalcTextSize(descriptionText).Y / 4) - 2);
ImGui.SetCursorPosX(ImGui.GetWindowWidth() - sortingTextSize.X - ((250 + 20) * ImGui.GetIO().FontGlobalScale));
ImGui.SetNextItemWidth(240 * ImGui.GetIO().FontGlobalScale);
ImGui.InputTextWithHint("###XPlPluginInstaller_Search", Loc.Localize("InstallerSearch", "Search"), ref this.searchText, 100);
ImGui.SameLine();
ImGui.SetNextItemWidth((10 * ImGui.GetIO().FontGlobalScale) + ImGui.CalcTextSize(Loc.Localize("SortDownloadCounts", "Download Count")).X);
if (ImGui.BeginCombo(Loc.Localize("PluginSort", "Sort By"), this.filterText, ImGuiComboFlags.NoArrowButton)) {
if (ImGui.Selectable(Loc.Localize("SortAlphabetical", "Alphabetical"))) {
this.sortKind = PluginSortKind.Alphabetical;
this.filterText = Loc.Localize("SortAlphabetical", "Alphabetical");
ResortPlugins();
}
if (ImGui.Selectable(Loc.Localize("SortDownloadCounts", "Download Count"))) {
this.sortKind = PluginSortKind.DownloadCount;
this.filterText = Loc.Localize("SortDownloadCounts", "Download Count");
ResortPlugins();
}
if (ImGui.Selectable(Loc.Localize("SortLastUpdate", "Last Update"))) {
this.sortKind = PluginSortKind.LastUpdate;
this.filterText = Loc.Localize("SortLastUpdate", "Last Update");
ResortPlugins();
}
ImGui.EndCombo();
}
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - (5 * ImGui.GetIO().FontGlobalScale));
string initializationStatusText = null;
if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.InProgress) {
initializationStatusText = Loc.Localize("InstallerLoading", "Loading plugins...");
this.pluginListAvailable = null;
} else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.Fail) {
initializationStatusText = Loc.Localize("InstallerDownloadFailed", "Download failed.");
this.pluginListAvailable = null;
} else if (this.dalamud.PluginRepository.State == PluginRepository.InitializationState.FailThirdRepo) {
initializationStatusText = Loc.Localize("InstallerDownloadFailedThird", "One of your third party repos is unreachable or there is no internet connection.");
this.pluginListAvailable = null;
} else {
if (this.pluginListAvailable == null) {
RefetchPlugins();
}
}
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(1, 3) * ImGui.GetIO().FontGlobalScale);
if (ImGui.BeginTabBar("PluginsTabBar", ImGuiTabBarFlags.NoTooltip)) {
DrawTab(false, initializationStatusText);
DrawTab(true, initializationStatusText);
ImGui.EndTabBar();
ImGui.Separator();
}
ImGui.PopStyleVar();
ImGui.Dummy(new Vector2(3f, 3f) * ImGui.GetIO().FontGlobalScale);
if (this.installStatus == PluginInstallStatus.InProgress) {
ImGui.Button(Loc.Localize("InstallerUpdating", "Updating..."));
} else {
if (this.updateComplete) {
ImGui.Button(this.updatePluginCount == 0
? Loc.Localize("InstallerNoUpdates", "No updates found!")
: string.Format(Loc.Localize("InstallerUpdateComplete", "{0} plugins updated!"), this.updatePluginCount));
} else {
if (ImGui.Button(Loc.Localize("InstallerUpdatePlugins", "Update plugins"))) {
this.installStatus = PluginInstallStatus.InProgress;
Task.Run(() => this.dalamud.PluginRepository.UpdatePlugins()).ContinueWith(t => {
this.installStatus =
t.Result.Success ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
this.installStatus =
t.IsFaulted ? PluginInstallStatus.Fail : this.installStatus;
if (this.installStatus == PluginInstallStatus.Success) {
this.updateComplete = true;
}
if (t.Result.UpdatedPlugins != null) {
this.updatePluginCount = t.Result.UpdatedPlugins.Count;
this.updatedPlugins = t.Result.UpdatedPlugins;
}
this.errorModalDrawing = this.installStatus == PluginInstallStatus.Fail;
this.errorModalOnNextFrame = this.installStatus == PluginInstallStatus.Fail;
this.dalamud.PluginRepository.PrintUpdatedPlugins(updatedPlugins, Loc.Localize("DalamudPluginUpdates", "Updates:"));
});
}
}
}
ImGui.SameLine();
if (ImGui.Button(Loc.Localize("SettingsInstaller", "Settings"))) {
this.dalamud.DalamudUi.OpenSettings();
}
var closeText = Loc.Localize("Close", "Close");
ImGui.SameLine(ImGui.GetWindowWidth() - ImGui.CalcTextSize(closeText).X - (16 * ImGui.GetIO().FontGlobalScale));
if (ImGui.Button(closeText)) {
windowOpen = false;
this.dalamud.Configuration.Save();
}
if (ImGui.BeginPopupModal(Loc.Localize("InstallerError","Installer failed"), ref this.errorModalDrawing, ImGuiWindowFlags.AlwaysAutoResize)) {
var message = Loc.Localize("InstallerErrorHint",
"The plugin installer ran into an issue or the plugin is incompatible.\nPlease restart the game and report this error on our discord.");
if (this.updatedPlugins != null) {
if (this.updatedPlugins.Any(x => x.WasUpdated == false)) {
var extraInfoMessage = Loc.Localize("InstallerErrorPluginInfo",
"\n\nThe following plugins caused these issues:\n\n{0}\nYou may try removing these plugins manually and reinstalling them.");
var insert = this.updatedPlugins.Where(x => x.WasUpdated == false)
.Aggregate(string.Empty,
(current, pluginUpdateStatus) =>
current + $"* {pluginUpdateStatus.InternalName}\n");
extraInfoMessage = string.Format(extraInfoMessage, insert);
message += extraInfoMessage;
}
}
ImGui.Text(message);
ImGui.Spacing();
if (ImGui.Button(Loc.Localize("OK", "OK"), new Vector2(120, 40))) { ImGui.CloseCurrentPopup(); }
ImGui.EndPopup();
}
if (this.errorModalOnNextFrame) {
ImGui.OpenPopup(Loc.Localize("InstallerError", "Installer failed"));
this.errorModalOnNextFrame = false;
}
ImGui.End();
return windowOpen;
}
private void DrawTab(bool installed, string statusText) {
if (ImGui.BeginTabItem(installed ? Loc.Localize("InstallerInstalledPluginList", "Installed Plugins") if (ImGui.BeginTabItem(installed ? Loc.Localize("InstallerInstalledPluginList", "Installed Plugins")
: Loc.Localize("InstallerAvailablePluginList", "Available Plugins"))) { : Loc.Localize("InstallerAvailablePluginList", "Available Plugins")))
ImGui.BeginChild("Scrolling" + (installed ? "Installed" : "Available"), {
new Vector2(0, 384 * ImGui.GetIO().FontGlobalScale), true, ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.NoBackground); ImGui.BeginChild(
"Scrolling" + (installed ? "Installed" : "Available"),
new Vector2(0, 384 * ImGui.GetIO().FontGlobalScale),
true,
ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.NoBackground);
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 5); ImGui.SetCursorPosY(ImGui.GetCursorPosY() - 5);
if (statusText != null) { if (statusText != null)
ImGui.TextColored(this.colorGrey, statusText); ImGui.TextColored(this.colorGrey, statusText);
} else { else
DrawPluginList(installed ? this.pluginListInstalled : this.pluginListAvailable, installed); this.DrawPluginList(installed ? this.pluginListInstalled : this.pluginListAvailable, installed);
}
ImGui.EndChild(); ImGui.EndChild();
ImGui.EndTabItem(); ImGui.EndTabItem();
} }
} }
private void DrawPluginList(List<PluginDefinition> pluginDefinitions, bool installed) { private void DrawPluginList(List<PluginDefinition> pluginDefinitions, bool installed)
{
var didAny = false; var didAny = false;
var didAnyWithSearch = false; var didAnyWithSearch = false;
var hasSearchString = !string.IsNullOrWhiteSpace(this.searchText); var hasSearchString = !string.IsNullOrWhiteSpace(this.searchText);
for (var index = 0; index < pluginDefinitions.Count; index++) { for (var index = 0; index < pluginDefinitions.Count; index++)
{
var pluginDefinition = pluginDefinitions[index]; var pluginDefinition = pluginDefinitions[index];
if (pluginDefinition.ApplicableVersion != this.gameVersion && if (pluginDefinition.ApplicableVersion != this.gameVersion &&
@ -314,12 +369,10 @@ namespace Dalamud.Plugin
if (hasSearchString && if (hasSearchString &&
!(pluginDefinition.Name.ToLowerInvariant().Contains(this.searchText.ToLowerInvariant()) || !(pluginDefinition.Name.ToLowerInvariant().Contains(this.searchText.ToLowerInvariant()) ||
string.Equals(pluginDefinition.Author, this.searchText, string.Equals(pluginDefinition.Author, this.searchText, StringComparison.InvariantCultureIgnoreCase) ||
StringComparison.InvariantCultureIgnoreCase) || (pluginDefinition.Tags != null && pluginDefinition.Tags.Contains(
pluginDefinition.Tags != null && this.searchText.ToLowerInvariant(),
pluginDefinition.Tags.Contains(this.searchText.ToLowerInvariant(), StringComparer.InvariantCultureIgnoreCase))))
StringComparer.InvariantCultureIgnoreCase)
))
continue; continue;
didAnyWithSearch = true; didAnyWithSearch = true;
@ -330,17 +383,22 @@ namespace Dalamud.Plugin
var isTestingAvailable = false; var isTestingAvailable = false;
if (Version.TryParse(pluginDefinition.AssemblyVersion, out var assemblyVersion) && if (Version.TryParse(pluginDefinition.AssemblyVersion, out var assemblyVersion) &&
Version.TryParse(pluginDefinition.TestingAssemblyVersion, out var testingAssemblyVersion)) Version.TryParse(pluginDefinition.TestingAssemblyVersion, out var testingAssemblyVersion))
{
isTestingAvailable = this.dalamud.Configuration.DoPluginTest && isTestingAvailable = this.dalamud.Configuration.DoPluginTest &&
testingAssemblyVersion > assemblyVersion; testingAssemblyVersion > assemblyVersion;
}
if (this.dalamud.Configuration.DoPluginTest && pluginDefinition.IsTestingExclusive) if (this.dalamud.Configuration.DoPluginTest && pluginDefinition.IsTestingExclusive)
isTestingAvailable = true; isTestingAvailable = true;
else if (!this.dalamud.Configuration.DoPluginTest && pluginDefinition.IsTestingExclusive) continue; else if (!this.dalamud.Configuration.DoPluginTest && pluginDefinition.IsTestingExclusive) continue;
var label = string.Empty; var label = string.Empty;
if (isInstalled && !installed) { if (isInstalled && !installed)
{
label += Loc.Localize("InstallerInstalled", " (installed)"); label += Loc.Localize("InstallerInstalled", " (installed)");
} else if (!isInstalled && installed) { }
else if (!isInstalled && installed)
{
label += Loc.Localize("InstallerDisabled", " (disabled)"); label += Loc.Localize("InstallerDisabled", " (disabled)");
} }
@ -357,7 +415,8 @@ namespace Dalamud.Plugin
ImGui.PushID(pluginDefinition.InternalName + pluginDefinition.AssemblyVersion + installed + index); ImGui.PushID(pluginDefinition.InternalName + pluginDefinition.AssemblyVersion + installed + index);
if (ImGui.CollapsingHeader(pluginDefinition.Name + label + "###Header" + pluginDefinition.InternalName)) { if (ImGui.CollapsingHeader(pluginDefinition.Name + label + "###Header" + pluginDefinition.InternalName))
{
ImGui.Indent(); ImGui.Indent();
ImGui.Text(pluginDefinition.Name); ImGui.Text(pluginDefinition.Name);
@ -375,19 +434,24 @@ namespace Dalamud.Plugin
if (!string.IsNullOrWhiteSpace(pluginDefinition.Description)) if (!string.IsNullOrWhiteSpace(pluginDefinition.Description))
ImGui.TextWrapped(pluginDefinition.Description); ImGui.TextWrapped(pluginDefinition.Description);
if (!isInstalled) { if (!isInstalled)
if (this.installStatus == PluginInstallStatus.InProgress) { {
if (this.installStatus == PluginInstallStatus.InProgress)
{
ImGui.Button(Loc.Localize("InstallerInProgress", "Install in progress...")); ImGui.Button(Loc.Localize("InstallerInProgress", "Install in progress..."));
} else { }
else
{
var versionString = isTestingAvailable var versionString = isTestingAvailable
? pluginDefinition.TestingAssemblyVersion + " (testing version)" ? pluginDefinition.TestingAssemblyVersion + " (testing version)"
: pluginDefinition.AssemblyVersion; : pluginDefinition.AssemblyVersion;
if (ImGui.Button($"Install v{versionString}")) { if (ImGui.Button($"Install v{versionString}"))
{
this.installStatus = PluginInstallStatus.InProgress; this.installStatus = PluginInstallStatus.InProgress;
Task.Run(() => this.dalamud.PluginRepository.InstallPlugin( Task.Run(() => this.dalamud.PluginRepository.InstallPlugin(pluginDefinition, true, false, isTestingAvailable)).ContinueWith(t =>
pluginDefinition, true, false, isTestingAvailable)).ContinueWith(t => { {
this.installStatus = this.installStatus =
t.Result ? PluginInstallStatus.Success : PluginInstallStatus.Fail; t.Result ? PluginInstallStatus.Success : PluginInstallStatus.Fail;
this.installStatus = this.installStatus =
@ -399,7 +463,8 @@ namespace Dalamud.Plugin
} }
} }
if (!string.IsNullOrEmpty(pluginDefinition.RepoUrl)) { if (!string.IsNullOrEmpty(pluginDefinition.RepoUrl))
{
ImGui.PushFont(InterfaceManager.IconFont); ImGui.PushFont(InterfaceManager.IconFont);
ImGui.SameLine(); ImGui.SameLine();
@ -409,7 +474,9 @@ namespace Dalamud.Plugin
ImGui.PopFont(); ImGui.PopFont();
} }
} else { }
else
{
var installedPlugin = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).First( var installedPlugin = this.dalamud.PluginManager.Plugins.Where(x => x.Definition != null).First(
x => x.Definition.InternalName == x => x.Definition.InternalName ==
pluginDefinition.InternalName); pluginDefinition.InternalName);
@ -417,7 +484,8 @@ namespace Dalamud.Plugin
var commands = this.dalamud.CommandManager.Commands.Where( var commands = this.dalamud.CommandManager.Commands.Where(
x => x.Value.LoaderAssemblyName == installedPlugin.Definition?.InternalName && x => x.Value.LoaderAssemblyName == installedPlugin.Definition?.InternalName &&
x.Value.ShowInHelp); x.Value.ShowInHelp);
if (commands.Any()) { if (commands.Any())
{
ImGui.Dummy(new Vector2(10f, 10f) * ImGui.GetIO().FontGlobalScale); ImGui.Dummy(new Vector2(10f, 10f) * ImGui.GetIO().FontGlobalScale);
foreach (var command in commands) foreach (var command in commands)
ImGui.TextWrapped($"{command.Key} → {command.Value.HelpMessage}"); ImGui.TextWrapped($"{command.Key} → {command.Value.HelpMessage}");
@ -425,13 +493,18 @@ namespace Dalamud.Plugin
ImGui.NewLine(); ImGui.NewLine();
if (!installedPlugin.IsRaw) { if (!installedPlugin.IsRaw)
{
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button(Loc.Localize("InstallerDisable", "Disable"))) { if (ImGui.Button(Loc.Localize("InstallerDisable", "Disable")))
try { {
try
{
this.dalamud.PluginManager.DisablePlugin(installedPlugin.Definition); this.dalamud.PluginManager.DisablePlugin(installedPlugin.Definition);
} catch (Exception exception) { }
catch (Exception exception)
{
Log.Error(exception, "Could not disable plugin."); Log.Error(exception, "Could not disable plugin.");
this.errorModalDrawing = true; this.errorModalDrawing = true;
this.errorModalOnNextFrame = true; this.errorModalOnNextFrame = true;
@ -439,14 +512,16 @@ namespace Dalamud.Plugin
} }
} }
if (installedPlugin.PluginInterface.UiBuilder.HasConfigUi) { if (installedPlugin.PluginInterface.UiBuilder.HasConfigUi)
{
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button(Loc.Localize("InstallerOpenConfig", "Open Configuration"))) if (ImGui.Button(Loc.Localize("InstallerOpenConfig", "Open Configuration")))
installedPlugin.PluginInterface.UiBuilder.OpenConfigUi(); installedPlugin.PluginInterface.UiBuilder.OpenConfigUi();
} }
if (!string.IsNullOrEmpty(installedPlugin.Definition.RepoUrl)) { if (!string.IsNullOrEmpty(installedPlugin.Definition.RepoUrl))
{
ImGui.PushFont(InterfaceManager.IconFont); ImGui.PushFont(InterfaceManager.IconFont);
ImGui.SameLine(); ImGui.SameLine();
@ -460,9 +535,11 @@ namespace Dalamud.Plugin
ImGui.SameLine(); ImGui.SameLine();
ImGui.TextColored(new Vector4(0.5f, 0.5f, 0.5f, 1.0f), $" v{installedPlugin.Definition.AssemblyVersion}"); ImGui.TextColored(new Vector4(0.5f, 0.5f, 0.5f, 1.0f), $" v{installedPlugin.Definition.AssemblyVersion}");
if (installedPlugin.IsRaw) { if (installedPlugin.IsRaw)
{
ImGui.SameLine(); ImGui.SameLine();
ImGui.TextColored(new Vector4(1.0f, 0.0f, 0.0f, 1.0f), ImGui.TextColored(
new Vector4(1.0f, 0.0f, 0.0f, 1.0f),
this.dalamud.PluginRepository.PluginMaster.Any(x => x.InternalName == installedPlugin.Definition.InternalName) this.dalamud.PluginRepository.PluginMaster.Any(x => x.InternalName == installedPlugin.Definition.InternalName)
? " This plugin is available in one of your repos, please remove it from the devPlugins folder." ? " This plugin is available in one of your repos, please remove it from the devPlugins folder."
: " To disable this plugin, please remove it from the devPlugins folder."); : " To disable this plugin, please remove it from the devPlugins folder.");
@ -472,7 +549,8 @@ namespace Dalamud.Plugin
ImGui.Unindent(); ImGui.Unindent();
} }
if (ImGui.BeginPopupContextItem("item context menu")) { if (ImGui.BeginPopupContextItem("item context menu"))
{
if (ImGui.Selectable("Hide from installer")) if (ImGui.Selectable("Hide from installer"))
this.dalamud.Configuration.HiddenPluginInternalName.Add(pluginDefinition.InternalName); this.dalamud.Configuration.HiddenPluginInternalName.Add(pluginDefinition.InternalName);
ImGui.EndPopup(); ImGui.EndPopup();
@ -481,19 +559,31 @@ namespace Dalamud.Plugin
ImGui.PopID(); ImGui.PopID();
} }
if (!didAny) { if (!didAny)
if (installed) { {
ImGui.TextColored(this.colorGrey, if (installed)
Loc.Localize("InstallerNoInstalled", {
ImGui.TextColored(
this.colorGrey,
Loc.Localize(
"InstallerNoInstalled",
"No plugins are currently installed. You can install them from the Available Plugins tab.")); "No plugins are currently installed. You can install them from the Available Plugins tab."));
} else { }
ImGui.TextColored(this.colorGrey, else
Loc.Localize("InstallerNoCompatible", {
ImGui.TextColored(
this.colorGrey,
Loc.Localize(
"InstallerNoCompatible",
"No compatible plugins were found :( Please restart your game and try again.")); "No compatible plugins were found :( Please restart your game and try again."));
} }
} else if (!didAnyWithSearch) }
ImGui.TextColored(new Vector4(0.7f, 0.7f, 0.7f, 1.0f), else if (!didAnyWithSearch)
{
ImGui.TextColored(
new Vector4(0.7f, 0.7f, 0.7f, 1.0f),
Loc.Localize("InstallNoMatching", "No plugins were found matching your search.")); Loc.Localize("InstallNoMatching", "No plugins were found matching your search."));
} }
} }
} }
}