From a941f18174c1cd51a4075e54efedc02b30d9c8c1 Mon Sep 17 00:00:00 2001 From: kalilistic <35899782+kalilistic@users.noreply.github.com> Date: Sat, 7 Oct 2023 18:38:28 -0400 Subject: [PATCH] feat: add migration warnings and dir helpers --- .../Gui/Windows/MigrationWindow.cs | 36 +++++++++++++------ Dalamud.DrunkenToad/Helpers/FileHelper.cs | 19 ++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Dalamud.DrunkenToad/Gui/Windows/MigrationWindow.cs b/Dalamud.DrunkenToad/Gui/Windows/MigrationWindow.cs index dbbc448..924511e 100644 --- a/Dalamud.DrunkenToad/Gui/Windows/MigrationWindow.cs +++ b/Dalamud.DrunkenToad/Gui/Windows/MigrationWindow.cs @@ -1,5 +1,6 @@ namespace Dalamud.DrunkenToad.Gui.Windows; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -15,10 +16,10 @@ /// public class MigrationWindow : SimpleWindow { - public readonly ConcurrentQueue ErrorQueue = new (); - public readonly ConcurrentQueue StepQueue = new (); + private readonly ConcurrentQueue errorQueue = new (); + private readonly ConcurrentQueue> stepQueue = new (); private readonly List errorMessages = new (); - private readonly List steps = new (); + private readonly List> steps = new (); private readonly Stopwatch stopwatch; private bool isMigrationFinished; private int previousStepCount; @@ -30,6 +31,12 @@ public MigrationWindow(DalamudPluginInterface pluginInterface) this.stopwatch.Start(); } + public void LogWarning(string message) => this.stepQueue.Enqueue(new Tuple(message, false)); + + public void LogInfo(string message) => this.stepQueue.Enqueue(new Tuple(message, true)); + + public void LogError(string message) => this.errorQueue.Enqueue(message); + public void StopMigration() { this.stopwatch.Stop(); @@ -101,9 +108,9 @@ private void DrawHeaderSection() private void DrawStepsSection() { - while (!this.StepQueue.IsEmpty) + while (!this.stepQueue.IsEmpty) { - if (this.StepQueue.TryDequeue(out var msg) && !string.IsNullOrEmpty(msg)) + if (this.stepQueue.TryDequeue(out var msg) && !string.IsNullOrEmpty(msg.Item1)) { this.steps.Add(msg); } @@ -117,18 +124,27 @@ private void DrawStepsSection() { ImGui.Indent(1f); ImGui.PushFont(UiBuilder.IconFont); - ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen); - ImGui.Text(FontAwesomeIcon.Check.ToIconString()); + if (step.Item2) + { + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.HealerGreen); + ImGui.Text(FontAwesomeIcon.Check.ToIconString()); + } + else + { + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow); + ImGui.Text(FontAwesomeIcon.ExclamationTriangle.ToIconString()); + } + ImGui.PopStyleColor(1); ImGui.PopFont(); ImGui.Unindent(1f); ImGui.SameLine(); - ImGui.Text(step); + ImGui.Text(step.Item1); } - while (!this.ErrorQueue.IsEmpty) + while (!this.errorQueue.IsEmpty) { - if (this.ErrorQueue.TryDequeue(out var msg) && !string.IsNullOrEmpty(msg)) + if (this.errorQueue.TryDequeue(out var msg) && !string.IsNullOrEmpty(msg)) { this.errorMessages.Add(msg); } diff --git a/Dalamud.DrunkenToad/Helpers/FileHelper.cs b/Dalamud.DrunkenToad/Helpers/FileHelper.cs index 983dfec..a876c34 100644 --- a/Dalamud.DrunkenToad/Helpers/FileHelper.cs +++ b/Dalamud.DrunkenToad/Helpers/FileHelper.cs @@ -10,6 +10,17 @@ /// public static class FileHelper { + /// + /// Ensures the existence of specified directories. + /// + /// The directory path. + /// The sub directory. + public static void EnsureDirectoriesExist(string dirPath, string subDir) + { + CreateDirectoryIfNotExists(dirPath); + CreateDirectoryIfNotExists(Path.Combine(dirPath, subDir)); + } + /// /// Moves the specified file from the source directory to the destination directory and compresses into a zip file. /// @@ -173,4 +184,12 @@ public static bool VerifyFileAccess(string fileName) return false; } } + + private static void CreateDirectoryIfNotExists(string directoryPath) + { + if (!Directory.Exists(directoryPath)) + { + Directory.CreateDirectory(directoryPath); + } + } }