From 457f880287c52aebe8a0a8f69d307975d260b59f Mon Sep 17 00:00:00 2001 From: Juna <46632782+JunaMeinhold@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:17:11 +0100 Subject: [PATCH] Another try. --- .../FileUtilitiesTests.cs | 22 +++++++++++++++++++ .../Dialogs/FileUtilities.cs | 6 +++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Hexa.NET.ImGui.Widgets.Tests/FileUtilitiesTests.cs b/Hexa.NET.ImGui.Widgets.Tests/FileUtilitiesTests.cs index ac4de92..cdc5d71 100644 --- a/Hexa.NET.ImGui.Widgets.Tests/FileUtilitiesTests.cs +++ b/Hexa.NET.ImGui.Widgets.Tests/FileUtilitiesTests.cs @@ -26,5 +26,27 @@ public void EnumerateEntriesOSXTest() Console.WriteLine($"Path: {entry.Path}, File Name: {fileName}"); } } + + [Test] + [Platform(Include = "Win", Reason = "This test is only applicable on Windows.")] + public void EnumerateEntriesWinTest() + { + // Arrange + string testDirectory = AppDomain.CurrentDomain.BaseDirectory; + + foreach (var entry in FileUtilities.EnumerateEntriesWin(testDirectory, "*", SearchOption.TopDirectoryOnly)) + { + var path = entry.Path.ToString(); + string fileName = Path.GetFileName(path); + Assert.Multiple(() => + { + Assert.That(string.IsNullOrEmpty(path), Is.False, "Path should not be empty"); + Assert.That(string.IsNullOrEmpty(fileName), Is.False, "File name should not be empty"); + }); + + // Optional: Print the path and file name for verification + Console.WriteLine($"Path: {entry.Path}, File Name: {fileName}"); + } + } } } \ No newline at end of file diff --git a/Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs b/Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs index 78c7426..aa1ddec 100644 --- a/Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs +++ b/Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs @@ -558,10 +558,11 @@ private static FileMetadata Convert(DirEnt entry, StdString path) { MemoryDump(&entry); int length = NET.Utilities.Utils.StrLen(entry.d_name); - StdWString str = new(path.Size + length); + StdWString str = new(path.Size + 1 + length); str.Append(path); str.Append('/'); str.Append(entry.d_name); + *(str.Data + str.Size) = '\0'; FileMetadata meta = new(); meta.Path = str; @@ -830,10 +831,11 @@ private static bool OSXTryReadDir(nint dirHandle, out OSXDirEnt dirEnt) private static FileMetadata OSXConvert(OSXDirEnt entry, StdString path) { int length = entry.d_namlen; - StdWString str = new(path.Size + length); + StdWString str = new(path.Size + 1 + length); str.Append(path); str.Append('/'); str.Append(entry.d_name, length); + *(str.Data + str.Size) = '\0'; FileMetadata meta = new(); meta.Path = str;