diff -r 000000000000 -r 59addced5e2a FileUtils.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FileUtils.m Fri May 02 12:49:43 2008 -0700 @@ -0,0 +1,55 @@ +// +// FileUtils.m +// MYUtilities +// +// Created by Jens Alfke on 1/14/08. +// Copyright 2008 Jens Alfke. All rights reserved. +// + +#import "FileUtils.h" + + +OSStatus PathToFSRef( NSString *path, FSRef *fsRef ) +{ + NSCParameterAssert(path); + return FSPathMakeRef((const UInt8 *)[path UTF8String],fsRef,NULL); +} + +OSStatus FSRefToPath( const FSRef *fsRef, NSString **outPath ) +{ + NSURL *url = (id) CFURLCreateFromFSRef(NULL,fsRef); + if( ! url ) + return paramErr; + *outPath = [url path]; + [url release]; + return noErr; +} + + +BOOL CheckOSErr( OSStatus err, NSError **error ) +{ + if( err ) { + if( error ) + *error = [NSError errorWithDomain: NSOSStatusErrorDomain code: err userInfo: nil]; + return NO; + } else { + return YES; + } +} + + +NSString* AppSupportDirectory() +{ + static NSString *sPath; + if( ! sPath ) { + NSString *dir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, + NSUserDomainMask, YES) + objectAtIndex: 0]; + dir = [dir stringByAppendingPathComponent: [[NSBundle mainBundle] bundleIdentifier]]; + if( ! [[NSFileManager defaultManager] fileExistsAtPath: dir] + && ! [[NSFileManager defaultManager] createDirectoryAtPath: dir attributes: nil] ) + [NSException raise: NSGenericException format: @"Unable to create app support dir %@",dir]; + sPath = [dir copy]; + } + return sPath; +}