1 USING: continuations destructors io.buffers io.files io.backend
2 io.timeouts io.ports io.pathnames io.files.private
3 io.backend.windows io.files.windows io.encodings.utf16n windows
4 windows.kernel32 kernel libc math threads system environment
5 alien.c-types alien.arrays alien.strings sequences combinators
6 combinators.short-circuit ascii splitting alien strings assocs
7 namespaces make accessors tr windows.time windows.shell32
9 IN: io.files.windows.nt
12 MAX_UNICODE_PATH dup "ushort" <c-array>
13 [ GetCurrentDirectory win32-error=0/f ] keep
17 SetCurrentDirectory win32-error=0/f ;
19 : unicode-prefix ( -- seq )
22 M: winnt root-directory? ( path -- ? )
24 { [ dup empty? ] [ drop f ] }
25 { [ dup [ path-separator? ] all? ] [ drop t ] }
26 { [ dup trim-tail-separators { [ length 2 = ]
27 [ second CHAR: : = ] } 1&& ] [ drop t ] }
28 { [ dup unicode-prefix head? ]
29 [ trim-tail-separators length unicode-prefix length 2 + = ] }
33 : prepend-prefix ( string -- string' )
34 dup unicode-prefix head? [
35 unicode-prefix prepend
38 TR: normalize-separators "/" "\\" ;
40 M: winnt normalize-path ( string -- string' )
45 M: winnt CreateFile-flags ( DWORD -- DWORD )
46 FILE_FLAG_OVERLAPPED bitor ;
50 : windows-file-size ( path -- size )
51 normalize-path 0 "WIN32_FILE_ATTRIBUTE_DATA" <c-object>
52 [ GetFileAttributesEx win32-error=0/f ] keep
53 [ WIN32_FILE_ATTRIBUTE_DATA-nFileSizeLow ]
54 [ WIN32_FILE_ATTRIBUTE_DATA-nFileSizeHigh ] bi >64bit ;
59 [ dup windows-file-size ] [ drop 0 ] recover
60 [ (open-append) ] dip >>ptr ;
64 [ "HOMEDRIVE" os-env "HOMEPATH" os-env append-path ]
65 [ "USERPROFILE" os-env ]