diff --git a/DownloadTask.cs b/DownloadTask.cs index da786cb..030aad9 100644 --- a/DownloadTask.cs +++ b/DownloadTask.cs @@ -347,11 +347,15 @@ private void DetermineIfUpdate(IDownloadTask_GetVersion info) { Directory.Move(oldName, this.PenumbraModPath!); } } else if (directories.Length > 1) { + var rejoined = directories + .Select(name => Path.Join(this.ModDirectory, name)) + .ToArray(); + throw new MultipleModDirectoriesException( info.Variant.Package.Name, info.Variant.Name, info.Version, - directories + rejoined ); } } diff --git a/Ui/Dialogs/Dialog.cs b/Ui/Dialogs/Dialog.cs index 526c70a..87839eb 100644 --- a/Ui/Dialogs/Dialog.cs +++ b/Ui/Dialogs/Dialog.cs @@ -1,9 +1,14 @@ +using System.Numerics; using Heliosphere.Util; using ImGuiNET; namespace Heliosphere.Ui.Dialogs; -internal abstract class Dialog(string title, ImGuiWindowFlags windowFlags = ImGuiWindowFlags.None) : IDrawable { +internal abstract class Dialog( + string title, + ImGuiWindowFlags windowFlags = ImGuiWindowFlags.None, + Vector2 windowSize = default +) : IDrawable { internal string Title { get; } = title; private ImGuiWindowFlags WindowFlags { get; } = windowFlags; private bool _visible = true; @@ -16,6 +21,10 @@ public DrawStatus Draw() { return DrawStatus.Finished; } + if (windowSize != default) { + ImGui.SetNextWindowSize(windowSize, ImGuiCond.Appearing); + } + using var end = new OnDispose(ImGui.End); if (!ImGui.Begin(this.Title, ref this._visible, this.WindowFlags)) { return DrawStatus.Continue; diff --git a/Ui/Dialogs/MultipleModDirectoriesDialog.cs b/Ui/Dialogs/MultipleModDirectoriesDialog.cs index 06ac026..9b137f2 100644 --- a/Ui/Dialogs/MultipleModDirectoriesDialog.cs +++ b/Ui/Dialogs/MultipleModDirectoriesDialog.cs @@ -12,18 +12,18 @@ internal class MultipleModDirectoriesDialog : Dialog { private MultipleModDirectoriesException Info { get; } private List<(string, string?)> DirectoryVersions { get; } - private Dictionary PathStatus { get; } + private Dictionary PathStatus { get; } = []; private Stopwatch Stopwatch { get; } = Stopwatch.StartNew(); - internal MultipleModDirectoriesDialog(Plugin plugin, MultipleModDirectoriesException info) : base($"{Plugin.Name}##mmdd-{info.PackageName}-{info.VariantName}-{info.Version}") { + internal MultipleModDirectoriesDialog(Plugin plugin, MultipleModDirectoriesException info) : base($"{Plugin.Name}##mmdd-{info.PackageName}-{info.VariantName}-{info.Version}", ImGuiWindowFlags.NoSavedSettings, new Vector2(450, 300)) { this.Plugin = plugin; this.Info = info; this.DirectoryVersions = [ .. this.Info.Directories .Select(path => (path, HeliosphereMeta.ParseDirectory(Path.GetFileName(path))?.Version)) - .OrderBy(tuple => tuple.Version) + .OrderByDescending(tuple => tuple.Version), ]; this.UpdateStatuses(); @@ -40,10 +40,8 @@ private void UpdateStatuses() { } protected override DrawStatus InnerDraw() { - ImGui.SetWindowSize(new Vector2(450, 300), ImGuiCond.Appearing); - if (this.Stopwatch.Elapsed >= TimeSpan.FromSeconds(3)) { - this.Stopwatch.Reset(); + this.Stopwatch.Restart(); this.UpdateStatuses(); } @@ -63,16 +61,13 @@ protected override DrawStatus InnerDraw() { foreach (var (path, version) in this.DirectoryVersions) { ImGui.Bullet(); - if (!this.PathStatus.TryGetValue(path, out var exists)) { - exists = false; - } - + var exists = this.PathStatus.GetValueOrDefault(path, false); using (ImGuiHelper.DisabledUnless(exists)) { ImGui.SameLine(); ImGui.TextUnformatted($"v{version} -"); ImGui.SameLine(); - if (ImGui.SmallButton("Open")) { + if (ImGui.SmallButton($"Open##{path}")) { Process.Start(new ProcessStartInfo(path) { UseShellExecute = true, });