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 87f0856 commit c88fd30
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions Hexa.NET.ImGui.Widgets/Dialogs/FileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ public bool ShouldIgnore(string pattern, out bool result)
#region UNIX/LINUX

// Unix-based stat method
[LibraryImport("libc", EntryPoint = "stat", SetLastError = true)]
private static unsafe partial int FileStat(byte* path, out Stat buf);
[DllImport("libc", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stat", SetLastError = true)]
private static extern unsafe int FileStat(byte* path, out Stat buf);

[StructLayout(LayoutKind.Sequential)]
private struct Stat
Expand Down Expand Up @@ -485,15 +485,15 @@ public bool ShouldIgnore()
}

// P/Invoke for opendir
[DllImport("libc", EntryPoint = "opendir", SetLastError = true)]
[DllImport("libc", CallingConvention = CallingConvention.Cdecl, EntryPoint = "opendir", SetLastError = true)]
private static extern unsafe nint OpenDir(byte* name);

// P/Invoke for readdir
[DllImport("libc", EntryPoint = "readdir", SetLastError = true)]
[DllImport("libc", CallingConvention = CallingConvention.Cdecl, EntryPoint = "readdir", SetLastError = true)]
private static extern unsafe DirEnt* ReadDir(nint dir);

// P/Invoke for closedir
[DllImport("libc", EntryPoint = "closedir", SetLastError = true)]
[DllImport("libc", CallingConvention = CallingConvention.Cdecl, EntryPoint = "closedir", SetLastError = true)]
private static extern unsafe int CloseDir(nint dir);

public static IEnumerable<FileMetadata> EnumerateEntriesUnix(string path, string pattern, SearchOption option)
Expand Down Expand Up @@ -603,8 +603,9 @@ private static void FileStat(StdWString str, out Stat stat)
#region OSX

// Unix-based stat method
[LibraryImport("libSystem.B.dylib", EntryPoint = "stat", SetLastError = true)]
private static unsafe partial int OSXFileStat(byte* path, out OSXStat buf);

[DllImport("libSystem.B.dylib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "stat", SetLastError = true)]
private static extern unsafe int OSXFileStat(byte* path, out OSXStat buf);

[StructLayout(LayoutKind.Sequential)]
private struct OSXStat
Expand Down Expand Up @@ -759,15 +760,15 @@ public bool ShouldIgnore()
}

// P/Invoke for opendir
[DllImport("libSystem.B.dylib", EntryPoint = "opendir", SetLastError = true)]
[DllImport("libSystem.B.dylib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "opendir", SetLastError = true)]
private static extern unsafe nint OSXOpenDir(byte* name);

// P/Invoke for readdir
[DllImport("libSystem.B.dylib", EntryPoint = "readdir", SetLastError = true)]
[DllImport("libSystem.B.dylib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "readdir", SetLastError = true)]
private static extern unsafe OSXDirEnt* OSXReadDir(nint dir);

// P/Invoke for closedir
[DllImport("libSystem.B.dylib", EntryPoint = "closedir", SetLastError = true)]
[DllImport("libSystem.B.dylib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "closedir", SetLastError = true)]
private static extern unsafe int OSXCloseDir(nint dir);

public static IEnumerable<FileMetadata> EnumerateEntriesOSX(string path, string pattern, SearchOption option)
Expand All @@ -790,7 +791,6 @@ public static IEnumerable<FileMetadata> EnumerateEntriesOSX(string path, string
if (!dirEnt.ShouldIgnore(pattern, out var ignore))
{
var meta = OSXConvert(dirEnt, dir);
Print(meta);

if ((meta.Attributes & FileAttributes.Directory) != 0 && option == SearchOption.AllDirectories)
{
Expand All @@ -799,9 +799,7 @@ public static IEnumerable<FileMetadata> EnumerateEntriesOSX(string path, string

if (!ignore)
{
Print(meta);
yield return meta;
Print(meta);
meta.Path.Release();
}
}
Expand All @@ -814,11 +812,6 @@ public static IEnumerable<FileMetadata> EnumerateEntriesOSX(string path, string
walkStack.Release();
}

private static void Print(FileMetadata meta)
{
Console.WriteLine($"Print -> Ptr: {(nint)meta.Path.Data}");
}

private static nint OSXOpenDir(StdString str)
{
return OSXOpenDir(str.Data);
Expand All @@ -845,10 +838,9 @@ private static FileMetadata OSXConvert(OSXDirEnt entry, StdString path)
str.Append(entry.d_name, length);
*(str.Data + str.Size) = '\0';
FileMetadata meta = new();
meta.Path = str;

OSXFileStat(str, out var stat);

meta.Path = str;
meta.CreationTime = stat.st_ctimespec;
meta.LastAccessTime = stat.st_atimespec;
meta.LastWriteTime = stat.st_mtimespec;
Expand Down

0 comments on commit c88fd30

Please sign in to comment.