Skip to content

Commit

Permalink
- fixed various typos
Browse files Browse the repository at this point in the history
- fixed minor memory management bugs (when object creation fails)
- initWithPath:fromPath: now returns nil if given a non-nil 'fromPath' that does not exist (previously it ignored the 'fromPath' in this case)
- added new public API to NDAlias named getFSRef:
- There is a resolveAliasFile category method on both NSURL and NSString, however, they behaved differently if the alias failed to resolve. The NSString version returned self while the NSURL version returned nil.  Changed the NSString version to return nil and updated the documentation.
- removed an '== YES' (a dangerous test).
- set ivars to 0 in dealloc
- updated the NSSavePanel category to conditionally use some new 10.6 API
- there is an NSURL method named URLByDeletingLastPathComponent, Apple created such an API in 10.6, so conditionalised it based on deployment target
- upgraded the project from the deprecated jam type. This allows Xcode 3.2 to open the project.
- switched to the 10.5 SDK
- removed Carbon.framework, added CoreServices.framework
- removed "nathan.*" files from the .xcodeproj
- the NSSavePanel category was missing from the project, added
- removed the old .pbproj project
  • Loading branch information
seanm committed Sep 5, 2009
1 parent b4186a9 commit 88a3bb5
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 115 deletions.
13 changes: 11 additions & 2 deletions Classes/NDAlias.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NDAlias.h
Created by Nathan Day on 05.12.01 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -213,6 +213,15 @@
@functiongroup Obtain the path the alias points to.
*/

/*!
@method getFSRef:
@abstract Get a <tt>FSRef</tt> for the receiver.
@discussion Initializes an <tt>FSRef</tt>.
@param fsRef a pointer to a <tt>FSRef</tt>.
@result Returns <tt>YES</tt> if the method was successful, if the function returns <tt>NO</tt> then the <tt>FSRef</tt> pointed to by <tt>fsRef</tt> is garbage.
*/
- (BOOL)getFSRef:(FSRef *)aFsRef;

/*!
This method is deprecated. Use -URL instead. Why? For consistency with Cocoa classes, which spell it in caps.
*/
Expand Down Expand Up @@ -336,6 +345,6 @@
@abstract Test alias equality
@discussion Returns YES if the receiver is equal to the passed object. Two NDAliases are defined as equal if and only if they resolve to equal FSRefs. Alias resolution is performed on both aliases, if there is any error, NO is returned.
*/
- (BOOL)isEqualToAlias:(id)otherObject;
- (BOOL)isEqualToAlias:(id)anOtherObject;

@end
38 changes: 29 additions & 9 deletions Classes/NDAlias.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NDAlias.m
Created by Nathan Day on 07.02.02 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -90,16 +90,30 @@ - (id)initWithPath:(NSString *)aPath fromPath:(NSString *)aFromPath
{
if( aPath && [[NSFileManager defaultManager] fileExistsAtPath:aPath] )
{
if( aFromPath && [[NSFileManager defaultManager] fileExistsAtPath:aFromPath] )
return [self initWithURL:[NSURL fileURLWithPath:aPath] fromURL:[NSURL fileURLWithPath:aFromPath]];
if( aFromPath )
{
if( [[NSFileManager defaultManager] fileExistsAtPath:aFromPath] )
{
self = [self initWithURL:[NSURL fileURLWithPath:aPath] fromURL:[NSURL fileURLWithPath:aFromPath]];
}
else
{
[super dealloc];
self = nil;
}
}
else
return [self initWithURL:[NSURL fileURLWithPath:aPath] fromURL:nil];
{
self = [self initWithURL:[NSURL fileURLWithPath:aPath] fromURL:nil];
}
}
else
{
[self release];
return nil;
[super dealloc];
self = nil;
}

return self;
}

/*
Expand Down Expand Up @@ -130,7 +144,7 @@ - (id)initWithURL:(NSURL *)aURL fromURL:(NSURL *)aFromURL
}
else
{
[self release];
[super dealloc];
self = nil;
}
}
Expand Down Expand Up @@ -197,7 +211,7 @@ - (id)initWithFSRef:(FSRef *)aFSRef
}
else
{
[self release];
[super dealloc];
self = nil;
}

Expand All @@ -221,7 +235,10 @@ - (void)encodeWithCoder:(NSCoder *)anEncoder
- (void)dealloc
{
if ( aliasHandle )
{
DisposeHandle( (Handle)aliasHandle );
aliasHandle = NULL;
}
[super dealloc];
}

Expand All @@ -232,9 +249,12 @@ - (void)dealloc
*/
- (void)finalize
{
/* Important: finalize methods must be thread-safe! DisposeHandle() is threadsafe since 10.3. */
/* Important: finalize methods must be threadsafe! DisposeHandle() is threadsafe since 10.3. */
if ( aliasHandle )
{
DisposeHandle( (Handle)aliasHandle );
aliasHandle = NULL;
}
[super finalize];
}

Expand Down
4 changes: 3 additions & 1 deletion Classes/NDResourceFork.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NDResourceFork.h category
Created by Nathan Day on 05.12.01 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -211,6 +211,7 @@ - (void)dealloc
[self closeFile];
NSLog (@"NDAlias ERROR: you neglected to call closeFile: before disposing this NDResourceFork");
}
fileReference = 0;
[super dealloc];
}

Expand All @@ -226,6 +227,7 @@ - (void)finalize
// Note: all finalize methods must be thread-safe! Thus we cannot call closeFile here because it calls CloseResFile() which, along with the rest of the Resource Manager, is not thread-safe.
NSLog (@"NDAlias ERROR: you neglected to call closeFile: before disposing this NDResourceFork");
}
fileReference = 0;
[super finalize];
}

Expand Down
17 changes: 17 additions & 0 deletions Classes/NSSavePanel+NDAlias.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ @implementation NSSavePanel (NDAlias)
- (NDAlias *)directoryAlias
{
NDAlias * anAlias = nil;

#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
NSURL * directory = [self directoryURL];
if (directory != nil)
{
anAlias = [NDAlias aliasWithURL:directory];
}
#else
NSString * directory = [self directory];
if (directory != nil)
{
anAlias = [NDAlias aliasWithPath:directory];
}
#endif

return anAlias;
}
Expand All @@ -52,11 +61,19 @@ - (NDAlias *)directoryAlias
*/
- (void)setDirectoryAlias:(NDAlias*)alias
{
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
NSURL* url = [alias URL];
if (url != nil)
{
[self setDirectoryURL:url];
}
#else
NSString* fullPath = [alias path];
if (fullPath != nil)
{
[self setDirectory:fullPath];
}
#endif
}

@end
12 changes: 6 additions & 6 deletions Classes/NSString+NDCarbonUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NSString+NDCarbonUtilities.h
Created by Nathan Day on 03.08.02 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -85,7 +85,7 @@
/*!
@method resolveAliasFile
@abstract Resolve an alias file.
@discussion Returns an POSIX path <tt>NSString</tt> refered to by the receveive if the receveive refers to an alias file. If it does not refer to an alias file the a string identical to the receveive is returned.
@discussion If the receiver does not refer to an alias file, the receiver itself is returned. If the receiver does refer to an alias file, alias resolution is attepted. If successful, a POSIX path <tt>NSString</tt> of the original is returned, else nil is returned.
@result An POSIX path <tt>NSString</tt>.
*/
- (NSString *)resolveAliasFile;
Expand All @@ -101,8 +101,8 @@

/*!
@method getPascalString:length:
@abstract Obtain a pascal string equivelent to the receveiver.
@discussion Fill the <tt>StringPtr</tt> with a pascal string equivelent to the receveiver.
@abstract Obtain a pascal string equivelent to the receiver.
@discussion Fill the <tt>StringPtr</tt> with a pascal string equivelent to the receiver.
@param buffer A <tt>StringPtr</tt> that contains the pascal string on completion.
@param length The maximum length the string can be. Pascal string can be no longer than <tt>255</tt> bytes long, <tt>256</tt> if you include the first length byte.
@result Returns <tt>YES</tt> if the method was successful, if <tt>NO</tt> is returns then <tt>buffer</tt> contains garbage.
Expand All @@ -111,7 +111,7 @@

/*!
@method pascalString
@abstract Obtain a pascal string equivelent to the receveiver.
@abstract Obtain a pascal string equivelent to the receiver.
@discussion Returns a representation of the receiver as a pascal string. The returned pascal string will be automatically freed just as a returned object would be released; your code should copy the pascal string or use <tt>getPascalString:length:</tt> if it needs to store the pascal string outside of the autorelease context in which the pascal string is created. Do not use this method in a Garbage Collected application, it has undefined behaviour!
@deprecated in version 10.5
@result A pointer to a pascal string.
Expand All @@ -121,7 +121,7 @@
/*!
@method trimWhitespace
@abstract Trims white space from a <tt>NSString</tt>.
@discussion Returns a new <tt>NSString</tt> equivelent to the receveiver but without any white space (return, new line, space, tab) at the begining or end of the string.
@discussion Returns a new <tt>NSString</tt> equivelent to the receiver but without any white space (return, new line, space, tab) at the begining or end of the string.
@result A new <tt>NSString</tt>.
*/
- (NSString *)trimWhitespace;
Expand Down
10 changes: 5 additions & 5 deletions Classes/NSString+NDCarbonUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NSString+NDCarbonUtilities.m
Created by Nathan Day on 03.08.02 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -103,16 +103,16 @@ - (NSString *)resolveAliasFile
FSRef theRef;
Boolean theIsTargetFolder,
theWasAliased;
NSString * theResolvedAlias = nil;;
NSString * theResolvedAlias = nil;

[self getFSRef:&theRef];
BOOL theSuccess = [self getFSRef:&theRef];

if( (FSResolveAliasFile( &theRef, YES, &theIsTargetFolder, &theWasAliased ) == noErr) )
if (theSuccess && FSResolveAliasFileWithMountFlags( &theRef, true, &theIsTargetFolder, &theWasAliased, 0 ) == noErr)
{
theResolvedAlias = (theWasAliased) ? [NSString stringWithFSRef:&theRef] : self;
}

return theResolvedAlias ? theResolvedAlias : self;
return theResolvedAlias;
}

/*
Expand Down
15 changes: 9 additions & 6 deletions Classes/NSURL+NDCarbonUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NSURL+NDCarbonUtilities.h
Created by Nathan Day on 05.12.01 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -43,7 +43,7 @@
/*!
@method URLWithFSRef:
@abstract Alloc and intialize a <tt>NSURL</tt>.
@discussion Returns a file url for the file refered to by a <tt>FSRef</tt>.
@discussion Returns a file url for the file referred to by a <tt>FSRef</tt>.
@param fsRef A pointer to a <tt>FSRef</tt>.
@result A <tt>NSURL</tt> containing a file url.
*/
Expand All @@ -52,7 +52,7 @@
/*!
@method URLWithFileSystemPathHFSStyle:
@abstract Alloc and intialize a <tt>NSURL</tt>.
@discussion Returns a file url for the file refered to by a HFS style path.
@discussion Returns a file url for the file referred to by a HFS style path.
@param hfsString A <tt>NSString</tt> containing a HFS style path.
@result A <tt>NSURL</tt> containing a file url.
*/
Expand Down Expand Up @@ -80,9 +80,12 @@
@method URLByDeletingLastPathComponent
@abstract Delete last component of a url.
@discussion Returns a new <tt>NSURL</tt> equivelent to the receiver with the last component removed.
@deprecated in version 10.6 because Apple added it to NSURL.
@result A new <tt>NSURL</tt>
*/
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
- (NSURL *)URLByDeletingLastPathComponent;
#endif

/*!
@method fileSystemPathHFSStyle
Expand All @@ -95,8 +98,8 @@
/*!
@method resolveAliasFile
@abstract Resolve an alias file.
@discussion Returns an file url <tt>NSURL</tt> refered to by the receveive if the receveive refers to an alias file. If it does not refer to an alias file the a url identical to the receveive is returned.
@result An file url <tt>NSURL</tt>.
@discussion If the receiver does not refer to an alias file, the receiver itself is returned. If the receiver does refer to an alias file, alias resolution is attepted. If successful, a file url <tt>NSURL</tt> to the original is returned, else nil is returned.
@result A file url <tt>NSURL</tt>.
*/
- (NSURL *)resolveAliasFile;

Expand Down Expand Up @@ -190,7 +193,7 @@
/*!
@method hasCustomIcon
@abstract Test if a file has a custom icon.
@discussion Test to see if the file refered to by the receiver has a custom icon. The is equivelent to testing for the <tt>kHasCustomIcon</tt> flag
@discussion Test to see if the file referred to by the receiver has a custom icon. The is equivelent to testing for the <tt>kHasCustomIcon</tt> flag
@result Returns <tt>YES</tt> if the file has a custom icon.
*/
- (BOOL)hasCustomIcon;
Expand Down
20 changes: 12 additions & 8 deletions Classes/NSURL+NDCarbonUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NSURL+NDCarbonUtilities.m
Created by Nathan Day on 05.12.01 under a MIT-style license.
Copyright (c) 2008 Nathan Day
Copyright (c) 2008-2009 Nathan Day
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -78,13 +78,15 @@ - (BOOL)getFSSpec:(FSSpec *)aFSSpec
/*
- URLByDeletingLastPathComponent
*/
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
- (NSURL *)URLByDeletingLastPathComponent
{
CFURLRef theURL = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault, (CFURLRef)self);

/* To support GC and non-GC, we need this contortion. */
return [NSMakeCollectable(theURL) autorelease];
}
#endif

/*
- fileSystemPathHFSStyle
Expand All @@ -103,13 +105,13 @@ - (NSString *)fileSystemPathHFSStyle
- (NSURL *)resolveAliasFile
{
FSRef theRef;
Boolean theIsTargetFolder,
Boolean theIsTargetFolder,
theWasAliased;
NSURL * theResolvedAlias = nil;;
NSURL * theResolvedAlias = nil;

[self getFSRef:&theRef];
BOOL theSuccess = [self getFSRef:&theRef];

if( (FSResolveAliasFile ( &theRef, YES, &theIsTargetFolder, &theWasAliased ) == noErr) )
if (theSuccess && FSResolveAliasFileWithMountFlags ( &theRef, true, &theIsTargetFolder, &theWasAliased, 0 ) == noErr)
{
theResolvedAlias = (theWasAliased) ? [NSURL URLWithFSRef:&theRef] : self;
}
Expand Down Expand Up @@ -161,7 +163,7 @@ - (NSPoint)finderLocation
*/
- (BOOL)setFinderInfoFlags:(UInt16)aFlags mask:(UInt16)aMask type:(OSType)aType creator:(OSType)aCreator
{
BOOL theResult = NO;
BOOL theResult = NO;
FSRef theFSRef;
FSCatalogInfo theInfo;

Expand All @@ -183,7 +185,7 @@ - (BOOL)setFinderInfoFlags:(UInt16)aFlags mask:(UInt16)aMask type:(OSType)aType
*/
- (BOOL)setFinderLocation:(NSPoint)aLocation
{
BOOL theResult = NO;
BOOL theResult = NO;
FSRef theFSRef;
FSCatalogInfo theInfo;

Expand All @@ -206,7 +208,9 @@ @implementation NSURL (NDCarbonUtilitiesInfoFlags)
- (BOOL)hasCustomIcon
{
UInt16 theFlags;
return [self finderInfoFlags:&theFlags type:NULL creator:NULL] == YES && (theFlags & kHasCustomIcon) != 0;
BOOL theSuccess = [self finderInfoFlags:&theFlags type:NULL creator:NULL];

return theSuccess && (theFlags & kHasCustomIcon) != 0;
}

@end
Expand Down
Loading

0 comments on commit 88a3bb5

Please sign in to comment.