Paste: send-to-trash
Author: | mrjbq7 |
Mode: | factor |
Date: | Fri, 9 Jul 2010 00:46:53 |
Plain Text |
USING: alien.c-types alien.strings alien.syntax classes.struct
core-foundation io.encodings.utf8 kernel ;
IN: trash
STRUCT: FSRef
{ hidden UInt8[80] } ;
TYPEDEF: SInt32 OSStatus
TYPEDEF: UInt32 OptionBits
CONSTANT: kFSFileOperationDefaultOptions HEX: 00
CONSTANT: kFSFileOperationOverwrite HEX: 01
CONSTANT: kFSFileOperationSkipSourcePermissionErrors HEX: 02
CONSTANT: kFSFileOperationDoNotMoveAcrossVolumes HEX: 04
CONSTANT: kFSFileOperationSkipPreflight HEX: 08
FUNCTION: OSStatus FSMoveObjectToTrashSync (
FSRef* source,
FSRef* target,
OptionBits options
) ;
CONSTANT: noErr 0
CONSTANT: kFSPathMakeRefDefaultOptions HEX: 00
CONSTANT: kFSPathMakeRefDoNotFollowLeafSymlink HEX: 01
FUNCTION: char* GetMacOSStatusCommentString (
OSStatus err
) ;
FUNCTION: OSStatus FSPathMakeRefWithOptions (
UInt8* path,
OptionBits options,
FSRef* ref,
Boolean* isDirectory
) ;
: check-err ( err -- )
dup noErr = [ drop ] [
GetMacOSStatusCommentString utf8 alien>string throw
] if ;
: <fs-ref> ( path -- fs-ref )
utf8 string>alien
kFSPathMakeRefDoNotFollowLeafSymlink
FSRef <struct>
[ f FSPathMakeRefWithOptions check-err ] keep ;
: send-to-trash ( path -- )
<fs-ref> f kFSFileOperationDefaultOptions
FSMoveObjectToTrashSync check-err ;
New Annotation