Skip to content

Commit 457f880

Browse files
committed
Another try.
1 parent 2076477 commit 457f880

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Hexa.NET.ImGui.Widgets.Tests/FileUtilitiesTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,27 @@ public void EnumerateEntriesOSXTest()
2626
Console.WriteLine($"Path: {entry.Path}, File Name: {fileName}");
2727
}
2828
}
29+
30+
[Test]
31+
[Platform(Include = "Win", Reason = "This test is only applicable on Windows.")]
32+
public void EnumerateEntriesWinTest()
33+
{
34+
// Arrange
35+
string testDirectory = AppDomain.CurrentDomain.BaseDirectory;
36+
37+
foreach (var entry in FileUtilities.EnumerateEntriesWin(testDirectory, "*", SearchOption.TopDirectoryOnly))
38+
{
39+
var path = entry.Path.ToString();
40+
string fileName = Path.GetFileName(path);
41+
Assert.Multiple(() =>
42+
{
43+
Assert.That(string.IsNullOrEmpty(path), Is.False, "Path should not be empty");
44+
Assert.That(string.IsNullOrEmpty(fileName), Is.False, "File name should not be empty");
45+
});
46+
47+
// Optional: Print the path and file name for verification
48+
Console.WriteLine($"Path: {entry.Path}, File Name: {fileName}");
49+
}
50+
}
2951
}
3052
}

Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,11 @@ private static FileMetadata Convert(DirEnt entry, StdString path)
558558
{
559559
MemoryDump(&entry);
560560
int length = NET.Utilities.Utils.StrLen(entry.d_name);
561-
StdWString str = new(path.Size + length);
561+
StdWString str = new(path.Size + 1 + length);
562562
str.Append(path);
563563
str.Append('/');
564564
str.Append(entry.d_name);
565+
*(str.Data + str.Size) = '\0';
565566
FileMetadata meta = new();
566567
meta.Path = str;
567568

@@ -830,10 +831,11 @@ private static bool OSXTryReadDir(nint dirHandle, out OSXDirEnt dirEnt)
830831
private static FileMetadata OSXConvert(OSXDirEnt entry, StdString path)
831832
{
832833
int length = entry.d_namlen;
833-
StdWString str = new(path.Size + length);
834+
StdWString str = new(path.Size + 1 + length);
834835
str.Append(path);
835836
str.Append('/');
836837
str.Append(entry.d_name, length);
838+
*(str.Data + str.Size) = '\0';
837839
FileMetadata meta = new();
838840
meta.Path = str;
839841

0 commit comments

Comments
 (0)