forked from uliwitness/UliKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSString+CarbonUtilities.m
68 lines (51 loc) · 1.55 KB
/
NSString+CarbonUtilities.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* =============================================================================
PROJECT: Filie
FILE: NSString+CarbonUtilities.m
COPYRIGHT: (c) 2002 by Nathan Day, all rights reserved.
AUTHORS: Nathan Day - ND
LICENSES: GNU GPL, Modified BSD
REVISIONS:
2002-08-03 ND Created.
========================================================================== */
// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------
#import "NSString+CarbonUtilities.h"
/*
* class implementation NSString (CarbonUtilities)
*/
@implementation NSString (CarbonUtilities)
/*
* +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