diff --git a/PenumbraIpc.cs b/PenumbraIpc.cs index 91e5084..37bb588 100644 --- a/PenumbraIpc.cs +++ b/PenumbraIpc.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; +using Heliosphere.Ui; using Penumbra.Api.Enums; using Penumbra.Api.Helpers; @@ -65,6 +67,21 @@ private void RegisterEvents() { } } + /// + /// Gets the mod directory from Penumbra. Will open a warning popup to users + /// who have not set Penumbra up correctly. + /// + /// The mod directory + /// true if the mod directory is valid, false if invalid or Penumbra's IPC could not be contacted + internal bool TryGetModDirectory([NotNullWhen(true)] out string? modDirectory) { + modDirectory = this.GetModDirectory(); + if (modDirectory?.Trim() == string.Empty) { + this.Plugin.PluginUi.AddToDraw(new SetUpPenumbraWindow(this.Plugin)); + } + + return !string.IsNullOrWhiteSpace(modDirectory); + } + internal bool AddMod(string path) { try { return this.AddModSubscriber.Invoke(path) == PenumbraApiEc.Success; diff --git a/Server.cs b/Server.cs index f6c7bbe..8d997cb 100644 --- a/Server.cs +++ b/Server.cs @@ -141,8 +141,7 @@ private void HandleConnection() { this.Plugin.Name, NotificationType.Info ); - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir)) { + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { await this.Plugin.AddDownloadAsync(new DownloadTask( this.Plugin, modDir, @@ -154,7 +153,7 @@ await this.Plugin.AddDownloadAsync(new DownloadTask( )); } else { this.Plugin.Interface.UiBuilder.AddNotification( - "Could not ask Penumbra where its directory is.", + "Cannot install mod: Penumbra is not set up.", this.Plugin.Name, NotificationType.Error ); @@ -213,8 +212,7 @@ await this.Plugin.AddDownloadAsync(new DownloadTask( var resp = await Plugin.GraphQl.MultiVariantInstall.ExecuteAsync(info.PackageId); resp.EnsureNoErrors(); - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir) && resp.Data?.Package?.Variants != null) { + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir) && resp.Data?.Package?.Variants != null) { foreach (var variant in resp.Data.Package.Variants) { if (variant.Versions.Count <= 0) { continue; @@ -232,7 +230,7 @@ await this.Plugin.AddDownloadAsync(new DownloadTask( } } else { this.Plugin.Interface.UiBuilder.AddNotification( - "Could not ask Penumbra where its directory is.", + "Cannot install mod: Penumbra is not set up.", this.Plugin.Name, NotificationType.Error ); @@ -279,10 +277,9 @@ await this.Plugin.AddDownloadAsync(new DownloadTask( var oneClick = this.OneClickPassed(info.OneClickPassword, holdingShift); - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (string.IsNullOrWhiteSpace(modDir)) { + if (!this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { this.Plugin.Interface.UiBuilder.AddNotification( - "Could not ask Penumbra where its directory is.", + "Cannot install mod: Penumbra is not set up.", this.Plugin.Name, NotificationType.Error ); diff --git a/Ui/ExternalImportWindow.cs b/Ui/ExternalImportWindow.cs index 86698e7..46d43a4 100644 --- a/Ui/ExternalImportWindow.cs +++ b/Ui/ExternalImportWindow.cs @@ -67,7 +67,7 @@ public DrawStatus Draw() { var label = this._processing ? "Working..." : "Import"; - if (ImGui.Button($"{label}###import") && this.Plugin.Penumbra.GetModDirectory() is { } penumbra && !string.IsNullOrWhiteSpace(penumbra)) { + if (ImGui.Button($"{label}###import") && this.Plugin.Penumbra.TryGetModDirectory(out var penumbra)) { var tasks = new List(); foreach (var id in this.Selected) { if (!external.TryGetValue(id, out var info)) { diff --git a/Ui/InstallerWindow.cs b/Ui/InstallerWindow.cs index 8010488..826fd94 100644 --- a/Ui/InstallerWindow.cs +++ b/Ui/InstallerWindow.cs @@ -206,8 +206,7 @@ public DrawStatus Draw() { var ret = DrawStatus.Continue; if (atEnd) { if (ImGui.Button("Download")) { - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir)) { + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { Task.Run(async () => await this.Plugin.AddDownloadAsync(new DownloadTask(this.Plugin, modDir, this.VersionId, this._options, this.IncludeTags, this.OpenInPenumbra, this.PenumbraCollection, this.DownloadKey))); ret = DrawStatus.Finished; } diff --git a/Ui/MultiPromptWindow.cs b/Ui/MultiPromptWindow.cs index 9e23093..90ce471 100644 --- a/Ui/MultiPromptWindow.cs +++ b/Ui/MultiPromptWindow.cs @@ -114,12 +114,11 @@ public DrawStatus Draw() { ref this._collection ); - var ret = false; + var ret = DrawStatus.Continue; if (ImGui.Button("Install")) { - ret = true; - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir)) { + ret = DrawStatus.Finished; + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { foreach (var info in this.Infos) { Task.Run(async () => await this.Plugin.AddDownloadAsync(new DownloadTask( this.Plugin, @@ -136,11 +135,11 @@ ref this._collection ImGui.SameLine(); if (ImGui.Button("Cancel")) { - ret = true; + ret = DrawStatus.Finished; } ImGui.End(); - return DrawStatus.Continue; + return ret; } } diff --git a/Ui/MultiVariantPromptWindow.cs b/Ui/MultiVariantPromptWindow.cs index c96fa48..4f1b376 100644 --- a/Ui/MultiVariantPromptWindow.cs +++ b/Ui/MultiVariantPromptWindow.cs @@ -96,8 +96,7 @@ ref this._collection if (ImGui.Button("Install")) { ret = DrawStatus.Finished; - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir)) { + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { foreach (var version in this.Variants.Values) { Task.Run(async () => await this.Plugin.AddDownloadAsync(new DownloadTask(this.Plugin, modDir, version.Id, this._includeTags, this._openInPenumbra, this._collection, this._downloadKey))); } diff --git a/Ui/PromptWindow.cs b/Ui/PromptWindow.cs index 6c4cc27..c20fa85 100644 --- a/Ui/PromptWindow.cs +++ b/Ui/PromptWindow.cs @@ -134,8 +134,7 @@ ref this._collection if (ImGui.Button("Install")) { ret = DrawStatus.Finished; - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir)) { + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { Task.Run(async () => await this.Plugin.AddDownloadAsync(new DownloadTask(this.Plugin, modDir, this.VersionId, this._includeTags, this._openInPenumbra, this._collection, this._downloadKey))); } } diff --git a/Ui/Tabs/Manager.cs b/Ui/Tabs/Manager.cs index 871b619..78760fd 100644 --- a/Ui/Tabs/Manager.cs +++ b/Ui/Tabs/Manager.cs @@ -341,8 +341,7 @@ private void DrawActionsTab(HeliosphereMeta pkg) { } if (pkg.FullInstall) { - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (!string.IsNullOrWhiteSpace(modDir)) { + if (this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { this.Plugin.DownloadCodes.TryGetCode(pkg.Id, out var code); await this.Plugin.AddDownloadAsync(new DownloadTask(this.Plugin, modDir, info.Versions[0].Id, pkg.IncludeTags, false, null, code)); } @@ -597,8 +596,7 @@ private async Task DownloadUpdatesInner(bool useConfig) { return; } - var modDir = this.Plugin.Penumbra.GetModDirectory(); - if (string.IsNullOrWhiteSpace(modDir)) { + if (!this.Plugin.Penumbra.TryGetModDirectory(out var modDir)) { return; }