Skip to content

Commit 56f87fb

Browse files
committed
Init
1 parent 6bcec6d commit 56f87fb

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

src/Files.App.CsWin32/NativeMethods.txt

+2
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,5 @@ SetCurrentProcessExplicitAppUserModelID
222222
GdipCreateBitmapFromScan0
223223
BITMAP
224224
GetObject
225+
FindFirstStream
226+
FindNextStream

src/Files.App/Helpers/Win32/Win32Helper.Storage.cs

+17-12
Original file line numberDiff line numberDiff line change
@@ -1166,27 +1166,32 @@ public static string ParseSymLink(string path)
11661166
}
11671167

11681168
// https://stackoverflow.com/a/7988352
1169-
public static IEnumerable<(string Name, long Size)> GetAlternateStreams(string path)
1169+
public static unsafe IEnumerable<(string Name, long Size)> GetAlternateStreams(string path)
11701170
{
11711171
Win32PInvoke.WIN32_FIND_STREAM_DATA findStreamData = new Win32PInvoke.WIN32_FIND_STREAM_DATA();
1172-
IntPtr hFile = Win32PInvoke.FindFirstStreamW(path, Win32PInvoke.StreamInfoLevels.FindStreamInfoStandard, findStreamData, 0);
11731172

1174-
if (hFile.ToInt64() != -1)
1173+
fixed (char* pszStr = path)
11751174
{
1176-
do
1175+
FindCloseSafeHandle hFile = PInvoke.FindFirstStream(new(pszStr), Windows.Win32.Storage.FileSystem.STREAM_INFO_LEVELS.FindStreamInfoStandard, findStreamData, 0);
1176+
1177+
if (hFile.DangerousGetHandle().ToInt64() != -1)
11771178
{
1178-
// The documentation for FindFirstStreamW says that it is always a ::$DATA
1179-
// stream type, but FindNextStreamW doesn't guarantee that for subsequent
1180-
// streams so we check to make sure
1181-
if (findStreamData.cStreamName.EndsWith(":$DATA") && findStreamData.cStreamName != "::$DATA")
1179+
do
11821180
{
1183-
yield return (findStreamData.cStreamName, findStreamData.StreamSize);
1181+
// The documentation for FindFirstStreamW says that it is always a ::$DATA
1182+
// stream type, but FindNextStreamW doesn't guarantee that for subsequent
1183+
// streams so we check to make sure
1184+
if (findStreamData.cStreamName.EndsWith(":$DATA") && findStreamData.cStreamName != "::$DATA")
1185+
{
1186+
yield return (findStreamData.cStreamName, findStreamData.StreamSize);
1187+
}
11841188
}
1185-
}
1186-
while (Win32PInvoke.FindNextStreamW(hFile, findStreamData));
1189+
while (PInvoke.FindNextStream(hFile, findStreamData));
11871190

1188-
Win32PInvoke.FindClose(hFile);
1191+
PInvoke.FindClose((Windows.Win32.Foundation.HANDLE)hFile);
1192+
}
11891193
}
1194+
11901195
}
11911196

11921197
public static bool GetWin32FindDataForPath(string targetPath, out Win32PInvoke.WIN32_FIND_DATA findData)

src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs

-15
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,6 @@ public static extern bool GetFileInformationByHandleEx(
340340
uint dwBufferSize
341341
);
342342

343-
[DllImport("kernel32.dll", ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
344-
public static extern IntPtr FindFirstStreamW(
345-
string lpFileName,
346-
StreamInfoLevels InfoLevel,
347-
[In, Out, MarshalAs(UnmanagedType.LPStruct)] WIN32_FIND_STREAM_DATA lpFindStreamData,
348-
uint dwFlags
349-
);
350-
351-
[DllImport("kernel32.dll", ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
352-
[return: MarshalAs(UnmanagedType.Bool)]
353-
public static extern bool FindNextStreamW(
354-
IntPtr hndFindFile,
355-
[In, Out, MarshalAs(UnmanagedType.LPStruct)] WIN32_FIND_STREAM_DATA lpFindStreamData
356-
);
357-
358343
[DllImport("Shcore.dll", SetLastError = true)]
359344
public static extern int GetDpiForMonitor(
360345
IntPtr hmonitor,

0 commit comments

Comments
 (0)