]> gitweb.factorcode.org Git - factor.git/commitdiff
windows.kernel32, io.files.windows: Add support for listing alternate data
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 2 Nov 2015 02:17:51 +0000 (18:17 -0800)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 2 Nov 2015 02:17:51 +0000 (18:17 -0800)
streams, e.g. file paths like foo.txt:Zone.Identifier.

basis/io/files/windows/windows.factor
basis/windows/kernel32/kernel32.factor

index f9b419525cc750009675dae022c416dd84682e26..81e0274ca91f04044080ca3e54c7c0f36265ac95 100755 (executable)
@@ -6,9 +6,9 @@ combinators.short-circuit continuations destructors environment io
 io.backend io.binary io.buffers io.files io.files.private
 io.files.types io.pathnames io.ports io.streams.c io.streams.null
 io.timeouts kernel libc literals locals math math.bitwise namespaces
-sequences specialized-arrays system threads tr windows windows.errors
-windows.handles windows.kernel32 windows.shell32 windows.time
-windows.types windows.winsock ;
+sequences specialized-arrays system threads tr vectors windows
+windows.errors windows.handles windows.kernel32 windows.shell32
+windows.time windows.types windows.winsock ;
 SPECIALIZED-ARRAY: ushort
 IN: io.files.windows
 
@@ -381,3 +381,34 @@ M: windows home
         [ "USERPROFILE" os-env ]
         [ my-documents ]
     } 0|| ;
+
+: STREAM_DATA>out ( WIN32_FIND_STREAM_DATA -- pair/f )
+    [ cStreamName>> alien>native-string ]
+    [ StreamSize>> ] bi 2array ;
+
+: file-streams-rest ( streams handle -- streams )
+    WIN32_FIND_STREAM_DATA <struct>
+    [ FindNextStream ] 2keep
+    rot zero? [
+        GetLastError ERROR_HANDLE_EOF = [ win32-error ] unless
+        2drop
+    ] [
+        pick push file-streams-rest
+    ] if ;
+
+: file-streams ( path -- streams )
+    FindStreamInfoStandard
+    WIN32_FIND_STREAM_DATA <struct>
+    0
+    [ FindFirstStream ] 2keep drop
+    over ALIEN: -1 = [
+        2drop throw-win32-error
+    ] [
+        1vector swap file-streams-rest
+    ] if ;
+
+: alternate-file-streams ( path -- streams )
+    file-streams [ cStreamName>> alien>native-string "::$DATA" = not ] filter ;
+
+: alternate-file-streams? ( path -- streams )
+    alternate-file-streams empty? not ;
index c28f8e63166ee72622c0d24f955cbf5c7d1d2b99..a82bfa03f9a962cb698f25868b9dc90574846cb7 100644 (file)
@@ -1161,6 +1161,28 @@ ALIAS: FindFirstChangeNotification FindFirstChangeNotificationW
 ! FUNCTION: FindFirstFileExW
 FUNCTION: HANDLE FindFirstFileW ( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData )
 ALIAS: FindFirstFile FindFirstFileW
+
+ENUM: STREAM_INFO_LEVELS
+    FindStreamInfoStandard
+    FindStreamInfoMaxInfoLevel ;
+
+STRUCT: WIN32_FIND_STREAM_DATA
+    { StreamSize LARGE_INTEGER }
+    { cStreamName WCHAR[292] } ;
+
+TYPEDEF: WIN32_FIND_STREAM_DATA* PWIN32_FIND_STREAM_DATA
+
+FUNCTION: HANDLE FindFirstStreamW (
+    LPCWSTR            lpFileName,
+    STREAM_INFO_LEVELS InfoLevel,
+    LPVOID             lpFindStreamData,
+    DWORD              dwFlags
+)
+ALIAS: FindFirstStream FindFirstStreamW
+
+FUNCTION: BOOL FindNextStreamW ( HANDLE hFindStream, LPVOID lpFindStreamData )
+ALIAS: FindNextStream FindNextStreamW
+
 ! FUNCTION: FindFirstVolumeA
 ! FUNCTION: FindFirstVolumeMountPointA