NSString (NDCarbonUtilities)
Language: Objective-C, Author: Nathan Day
License: BSD (2-clause)
This category to NSString adds method to create strings from FSRef and viceversa. It also adds a method to resolve file aliases
NSString (NDCarbonUtilities) source preview
/* =============================================================================
PROJECT: Filie
FILE: NSString+NDCarbonUtilities.m
COPYRIGHT: (c) 2002 by Nathan Day, all rights reserved.
AUTHORS: Nathan Day - ND
LICENSES: GNU GPL, Modified BSD
REVISIONS:
2007-07-15 Adapted for CodeBeach
2002-08-03 ND Created.
========================================================================== */
// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------
#import "NSString+NDCarbonUtilities.h"
/*
* class implementation NSString (NDCarbonUtilities)
*/
@implementation NSString (NDCarbonUtilities)
/*
* +stringWithFSRef:
*/
+ (NSString *)stringWithFSRef:(const FSRef *)aFSRef
{
if( !aFSRef )
return nil;
UInt8 thePath[PATH_MAX + 1]; // plus 1 for \0 terminator
return (FSRefMakePath ( aFSRef, thePath, PATH_MAX ) == noErr) ? [NSString stringWithUTF8String: (char*) thePath] : nil;
}
/*
* -getFSRef:
*/
- (BOOL)getFSRef:(FSRef *)aFSRef
{
return FSPathMakeRef( (UInt8*) [self UTF8String], aFSRef, NULL ) == noErr;
}
/*
* -resolveAliasFile
*/
- (NSString *)resolveAliasFile
{
FSRef theRef;
Boolean theIsTargetFolder,
theWasAliased;
NSString * theResolvedAlias = nil;;
[self getFSRef:&theRef];
if( (FSResolveAliasFile ( &theRef, YES, &theIsTargetFolder, &theWasAliased ) == noErr) )
{
theResolvedAlias = (theWasAliased) ? [NSString stringWithFSRef:&theRef] : self;
}
return theResolvedAlias;
}
@end
NSString (NDCarbonUtilities) header preview
/* =============================================================================
FILE: NSString+NDCarbonUtilities.h
COPYRIGHT: (c) 2002 by Nathan Day, all rights reserved.
AUTHORS: Nathan Day - ND
LICENSES: GNU GPL, Modified BSD
REVISIONS:
2007-07-15 Adapted for CodeBeach
2002-08-03 ND Created.
========================================================================== */
// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------
@interface NSString (NDCarbonUtilities)
+(NSString*) stringWithFSRef:(const FSRef *)aFSRef;
-(BOOL) getFSRef:(FSRef *)aFSRef;
-(NSString*) resolveAliasFile;
@end
Download Archive
Compatible with:
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
- Mac OS X 10.5 PPC
- Mac OS X 10.5 Intel
Comments
Comment feed
