]> gitweb.factorcode.org Git - factor.git/blob - basis/io/files/temp/macosx/macosx.factor
e5f6b9377e7cdcdfaf04b4b7fbb031c8f6b5960e
[factor.git] / basis / io / files / temp / macosx / macosx.factor
1 ! (c)2012 Joe Groff bsd license
2 USING: alien.c-types alien.syntax cocoa.plists cocoa.runtime
3 cocoa.types core-foundation.strings io.directories io.files
4 io.files.temp io.pathnames kernel sequences system ;
5 IN: io.files.temp.macosx
6
7 <PRIVATE
8
9 FUNCTION: id NSTemporaryDirectory ( )
10
11 TYPEDEF: NSUInteger NSSearchPathDirectory
12 CONSTANT: NSCachesDirectory 13
13
14 TYPEDEF: NSUInteger NSSearchPathDomainMask
15 CONSTANT: NSUserDomainMask 1
16
17 FUNCTION: id NSSearchPathForDirectoriesInDomains (
18    NSSearchPathDirectory directory,
19    NSSearchPathDomainMask domainMask,
20    char expandTilde
21 )
22
23 CONSTANT: factor-bundle-name "org.factorcode.Factor"
24
25 : factor-bundle-subdir ( path -- path )
26     factor-bundle-name append-path ;
27
28 : first-existing ( paths -- path )
29     [ exists? ] find nip
30     [ "no user cache directory found" throw ] unless* ; inline
31
32 PRIVATE>
33
34 M: macosx default-temp-directory
35     NSTemporaryDirectory CF>string factor-bundle-subdir ;
36
37 M: macosx default-cache-directory
38     NSCachesDirectory NSUserDomainMask 1 NSSearchPathForDirectoriesInDomains
39     plist> first-existing factor-bundle-subdir ;