Skip to content

Commit

Permalink
feat: add migration warnings and dir helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kalilistic committed Oct 7, 2023
1 parent 7c0fdc3 commit a941f18
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
36 changes: 26 additions & 10 deletions Dalamud.DrunkenToad/Gui/Windows/MigrationWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Dalamud.DrunkenToad.Gui.Windows;

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -15,10 +16,10 @@
/// </summary>
public class MigrationWindow : SimpleWindow
{
public readonly ConcurrentQueue<string> ErrorQueue = new ();
public readonly ConcurrentQueue<string> StepQueue = new ();
private readonly ConcurrentQueue<string> errorQueue = new ();
private readonly ConcurrentQueue<Tuple<string, bool>> stepQueue = new ();
private readonly List<string> errorMessages = new ();
private readonly List<string> steps = new ();
private readonly List<Tuple<string, bool>> steps = new ();
private readonly Stopwatch stopwatch;
private bool isMigrationFinished;
private int previousStepCount;
Expand All @@ -30,6 +31,12 @@ public MigrationWindow(DalamudPluginInterface pluginInterface)
this.stopwatch.Start();
}

public void LogWarning(string message) => this.stepQueue.Enqueue(new Tuple<string, bool>(message, false));

public void LogInfo(string message) => this.stepQueue.Enqueue(new Tuple<string, bool>(message, true));

public void LogError(string message) => this.errorQueue.Enqueue(message);

public void StopMigration()
{
this.stopwatch.Stop();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
19 changes: 19 additions & 0 deletions Dalamud.DrunkenToad/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
/// </summary>
public static class FileHelper
{
/// <summary>
/// Ensures the existence of specified directories.
/// </summary>
/// <param name="dirPath">The directory path.</param>
/// <param name="subDir">The sub directory.</param>
public static void EnsureDirectoriesExist(string dirPath, string subDir)
{
CreateDirectoryIfNotExists(dirPath);
CreateDirectoryIfNotExists(Path.Combine(dirPath, subDir));
}

/// <summary>
/// Moves the specified file from the source directory to the destination directory and compresses into a zip file.
/// </summary>
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit a941f18

Please sign in to comment.