factor/basis/io/files/windows/nt/nt.factor

66 lines
1.8 KiB
Factor
Raw Normal View History

2010-09-16 17:10:38 -04:00
USING: accessors alien.c-types alien.strings classes.struct
combinators combinators.short-circuit continuations environment
io.backend io.backend.windows io.encodings.utf16n
io.files.private io.files.windows io.pathnames kernel math
sequences specialized-arrays system tr
2010-09-16 17:10:38 -04:00
windows windows.errors windows.kernel32 windows.shell32
windows.time ;
SPECIALIZED-ARRAY: ushort
IN: io.files.windows.nt
2007-09-20 18:09:08 -04:00
2008-04-02 21:09:56 -04:00
M: winnt cwd
2009-08-29 21:39:06 -04:00
MAX_UNICODE_PATH dup <ushort-array>
[ GetCurrentDirectory win32-error=0/f ] keep
2008-04-20 06:15:46 -04:00
utf16n alien>string ;
2008-04-02 21:09:56 -04:00
M: winnt cd
SetCurrentDirectory win32-error=0/f ;
2009-08-29 21:39:06 -04:00
CONSTANT: unicode-prefix "\\\\?\\"
2008-04-02 21:09:56 -04:00
M: winnt root-directory? ( path -- ? )
2008-03-27 17:22:24 -04:00
{
2008-09-18 18:45:15 -04:00
{ [ dup empty? ] [ drop f ] }
{ [ dup [ path-separator? ] all? ] [ drop t ] }
{ [ dup trim-tail-separators { [ length 2 = ]
2008-09-18 18:45:15 -04:00
[ second CHAR: : = ] } 1&& ] [ drop t ] }
{ [ dup unicode-prefix head? ]
[ trim-tail-separators length unicode-prefix length 2 + = ] }
2008-09-18 18:45:15 -04:00
[ drop f ]
} cond ;
: prepend-prefix ( string -- string' )
dup unicode-prefix head? [
unicode-prefix prepend
] unless ;
TR: normalize-separators "/" "\\" ;
2008-04-02 21:09:56 -04:00
M: winnt normalize-path ( string -- string' )
absolute-path
normalize-separators
prepend-prefix ;
2008-04-02 21:09:56 -04:00
M: winnt CreateFile-flags ( DWORD -- DWORD )
FILE_FLAG_OVERLAPPED bitor ;
2007-09-20 18:09:08 -04:00
<PRIVATE
: windows-file-size ( path -- size )
2009-08-29 21:39:06 -04:00
normalize-path 0 WIN32_FILE_ATTRIBUTE_DATA <struct>
[ GetFileAttributesEx win32-error=0/f ] keep
2009-08-29 21:39:06 -04:00
[ nFileSizeLow>> ] [ nFileSizeHigh>> ] bi >64bit ;
PRIVATE>
2008-05-06 05:26:46 -04:00
M: winnt open-append
[ dup windows-file-size ] [ drop 0 ] recover
[ (open-append) ] dip >>ptr ;
2008-10-18 22:24:14 -04:00
M: winnt home
{
[ "HOMEDRIVE" os-env "HOMEPATH" os-env append-path ]
[ "USERPROFILE" os-env ]
[ my-documents ]
} 0|| ;