Files
simgear/simgear/misc/CocoaHelpers.mm
T
James Turner 0f5cbc35a2 Apple directory helpers
- drop use of deprecated FSFindFolder (use NSFileManager)
- support Downloads and Pictures directories
2014-01-28 11:16:19 +00:00

41 lines
933 B
Plaintext

#include <Cocoa/Cocoa.h>
#include <Foundation/NSAutoreleasePool.h>
#include <simgear/misc/sg_path.hxx>
namespace {
class CocoaAutoreleasePool
{
public:
CocoaAutoreleasePool()
{
pool = [[NSAutoreleasePool alloc] init];
}
~CocoaAutoreleasePool()
{
[pool release];
}
private:
NSAutoreleasePool* pool;
};
} // of anonyous namespace
SGPath appleSpecialFolder(int dirType, int domainMask, const SGPath& def)
{
CocoaAutoreleasePool ap;
NSFileManager* fm = [NSFileManager defaultManager];
NSURL* pathUrl = [fm URLForDirectory:dirType
inDomain:domainMask
appropriateForURL:Nil
create:YES
error:nil];
if (!pathUrl) {
return def;;
}
return SGPath([[pathUrl path] UTF8String], def.getPermissionChecker());
}