Skip to content

Commit

Permalink
fix: show penumbra setup warning properly
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Sep 8, 2023
1 parent c9aa82f commit c8968ce
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 26 deletions.
17 changes: 17 additions & 0 deletions PenumbraIpc.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Heliosphere.Ui;
using Penumbra.Api.Enums;
using Penumbra.Api.Helpers;

Expand Down Expand Up @@ -65,6 +67,21 @@ private void RegisterEvents() {
}
}

/// <summary>
/// Gets the mod directory from Penumbra. Will open a warning popup to users
/// who have not set Penumbra up correctly.
/// </summary>
/// <param name="modDirectory">The mod directory</param>
/// <returns>true if the mod directory is valid, false if invalid or Penumbra's IPC could not be contacted</returns>
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;
Expand Down
15 changes: 6 additions & 9 deletions Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
);
Expand Down Expand Up @@ -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;
Expand All @@ -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
);
Expand Down Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion Ui/ExternalImportWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Task>();
foreach (var id in this.Selected) {
if (!external.TryGetValue(id, out var info)) {
Expand Down
3 changes: 1 addition & 2 deletions Ui/InstallerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 5 additions & 6 deletions Ui/MultiPromptWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}

Expand Down
3 changes: 1 addition & 2 deletions Ui/MultiVariantPromptWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
3 changes: 1 addition & 2 deletions Ui/PromptWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Expand Down
6 changes: 2 additions & 4 deletions Ui/Tabs/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c8968ce

Please sign in to comment.