]> gitweb.factorcode.org Git - factor.git/blob - extra/io/files/trash/macosx/macosx.factor
use radix literals
[factor.git] / extra / io / files / trash / macosx / macosx.factor
1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: alien.c-types alien.strings alien.syntax classes.struct
5 core-foundation io.encodings.utf8 io.files.trash kernel system ;
6
7 IN: io.files.trash.macosx
8
9 <PRIVATE
10
11 STRUCT: FSRef
12     { hidden UInt8[80] } ;
13
14 TYPEDEF: SInt32 OSStatus
15
16 TYPEDEF: UInt32 OptionBits
17
18 CONSTANT: noErr 0
19
20 CONSTANT: kFSFileOperationDefaultOptions 0x00
21 CONSTANT: kFSFileOperationOverwrite 0x01
22 CONSTANT: kFSFileOperationSkipSourcePermissionErrors 0x02
23 CONSTANT: kFSFileOperationDoNotMoveAcrossVolumes 0x04
24 CONSTANT: kFSFileOperationSkipPreflight 0x08
25
26 CONSTANT: kFSPathMakeRefDefaultOptions 0x00
27 CONSTANT: kFSPathMakeRefDoNotFollowLeafSymlink 0x01
28
29 FUNCTION: OSStatus FSMoveObjectToTrashSync (
30     FSRef* source,
31     FSRef* target,
32     OptionBits options
33 ) ;
34
35 FUNCTION: char* GetMacOSStatusCommentString (
36     OSStatus err
37 ) ;
38
39 FUNCTION: OSStatus FSPathMakeRefWithOptions (
40     UInt8* path,
41     OptionBits options,
42     FSRef* ref,
43     Boolean* isDirectory
44 ) ;
45
46 : check-err ( err -- )
47     dup noErr = [ drop ] [
48         GetMacOSStatusCommentString utf8 alien>string throw
49     ] if ;
50
51 ! FIXME: check isDirectory?
52
53 : <fs-ref> ( path -- fs-ref )
54     utf8 string>alien
55     kFSPathMakeRefDoNotFollowLeafSymlink
56     FSRef <struct>
57     [ f FSPathMakeRefWithOptions check-err ] keep ;
58
59 PRIVATE>
60
61 M: macosx send-to-trash ( path -- )
62     <fs-ref> f kFSFileOperationDefaultOptions
63     FSMoveObjectToTrashSync check-err ;
64
65