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