Skip to content

Commit

Permalink
Another try.
Browse files Browse the repository at this point in the history
  • Loading branch information
JunaMeinhold committed Nov 8, 2024
1 parent 2076477 commit 457f880
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Hexa.NET.ImGui.Widgets.Tests/FileUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
}
}
}
6 changes: 4 additions & 2 deletions Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 457f880

Please sign in to comment.