]> git.mxchange.org Git - simgear.git/blob - simgear/misc/CocoaHelpers.mm
Fix #1783: repeated error message on console
[simgear.git] / simgear / misc / CocoaHelpers.mm
1 #include <Cocoa/Cocoa.h>
2 #include <Foundation/NSAutoreleasePool.h>
3
4 #include <simgear/misc/sg_path.hxx>
5
6 namespace {
7     
8 class CocoaAutoreleasePool
9 {
10 public:
11     CocoaAutoreleasePool()
12     {
13         pool = [[NSAutoreleasePool alloc] init];
14     }
15
16     ~CocoaAutoreleasePool()
17     {
18         [pool release];
19     }
20
21 private:
22     NSAutoreleasePool* pool;
23 };
24
25 } // of anonyous namespace
26
27 SGPath appleSpecialFolder(int dirType, int domainMask, const SGPath& def)
28 {
29     CocoaAutoreleasePool ap;
30     NSFileManager* fm = [NSFileManager defaultManager];
31     NSSearchPathDirectory d = static_cast<NSSearchPathDirectory>(dirType);
32     NSURL* pathUrl = [fm URLForDirectory:d
33                                 inDomain:domainMask
34                        appropriateForURL:Nil
35                                   create:YES
36                                    error:nil];
37     if (!pathUrl) {
38         return def;;
39     }
40     
41     return SGPath([[pathUrl path] UTF8String], def.getPermissionChecker());
42 }