Revision: 11391
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11391&view=rev
Author: hofman
Date: 2007-10-25 13:25:26 -0700 (Thu, 25 Oct 2007)
Log Message:
-----------
Make sure decoding uses the correct order for non-keyed coding.
Modified Paths:
--------------
branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m
Modified: branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m
===================================================================
--- branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m 2007-10-25 17:20:37 UTC
(rev 11390)
+++ branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m 2007-10-25 20:25:26 UTC
(rev 11391)
@@ -394,6 +394,7 @@
- (id)initWithAlias:(BDAlias *)anAlias relativePath:(NSString *)relPath
delegate:(id)aDelegate;
{
NSParameterAssert(nil == aDelegate || [aDelegate
respondsToSelector:@selector(baseURLForAliasFile:)]);
+ NSParameterAssert(nil != anAlias);
if (self = [super init]) {
fileRef = NULL; // this is updated lazily, as we don't know the base
path at this point
alias = [anAlias retain];
@@ -440,10 +441,11 @@
if ((self = [self initWithAlias:anAlias relativePath:relPath
delegate:aDelegate])) {
if (baseURL)
// this initalizes the FSRef and update the alias
- [self fsRef];
+ [self fileRef];
}
[anAlias release];
} else {
+ [[super init] release];
self = nil;
}
return self;
@@ -457,14 +459,28 @@
- (id)initWithCoder:(NSCoder *)coder
{
OBASSERT_NOT_REACHED("BDSKAliasFile needs a base path for encoding");
- return [self initWithAliasData:[coder decodeObject] relativePath:[coder
decodeObject] delegate:nil];
+ NSData *data = nil;
+ NSString *relPath = nil;
+ if ([coder allowsKeyedCoding]) {
+ data = [coder decodeObjectForKey:@"aliasData"];
+ relPath = [coder decodeObjectForKey:@"relativePath"];
+ } else {
+ data = [coder decodeObject];
+ relPath = [coder decodeObject];
+ }
+ return [self initWithAliasData:data relativePath:relPath delegate:nil];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
OBASSERT_NOT_REACHED("BDSKAliasFile needs a base path for encoding");
- [coder encodeObject:[self aliasDataRelativeToPath:[[delegate
baseURLForAliasFile:self] path]]];
- [coder encodeObject:relativePath];
+ if ([coder allowsKeyedCoding]) {
+ [coder encodeObject:[self aliasDataRelativeToPath:[[delegate
baseURLForAliasFile:self] path]] forKey:@"aliasData"];
+ [coder encodeObject:relativePath forKey:@"relativePath"];
+ } else {
+ [coder encodeObject:[self aliasDataRelativeToPath:[[delegate
baseURLForAliasFile:self] path]]];
+ [coder encodeObject:relativePath];
+ }
}
- (void)dealloc
@@ -488,7 +504,7 @@
FSRef baseRef;
if (fileRef == NULL) {
// this does the updating if possible
- [self fsRef];
+ [self fileRef];
} else if (baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef)) {
Boolean didUpdate;
if (alias)
@@ -505,8 +521,21 @@
}
}
-- (const FSRef *)fsRef;
+- (void)setFileRef:(const FSRef *)newFileRef;
{
+ if (fileRef != NULL) {
+ NSZoneFree([self zone], (void *)fileRef);
+ fileRef = NULL;
+ }
+ FSRef *newRef = (FSRef *)NSZoneMalloc([self zone], sizeof(FSRef));
+ if (newRef) {
+ bcopy(fsRef, newRef, sizeof(FSRef));
+ fileRef = newRef;
+ }
+}
+
+- (const FSRef *)fileRef;
+{
NSURL *baseURL = [delegate baseURLForAliasFile:self];
FSRef baseRef;
Boolean hasBaseRef = baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef);
@@ -534,12 +563,8 @@
}
}
- if (hasRef) {
- FSRef *newRef = (FSRef *)NSZoneMalloc([self zone], sizeof(FSRef));
- if(newRef)
- bcopy(&aRef, newRef, sizeof(FSRef));
- fileRef = newRef;
- }
+ if (hasRef)
+ [self setFileRef:&aRef];
} else if (relativePath == nil) {
shouldUpdate = hasBaseRef;
}
@@ -564,13 +589,12 @@
- (NSURL *)fileURL;
{
BOOL hadFileRef = fileRef != NULL;
- const FSRef *aRef = [self fsRef];
+ const FSRef *aRef = [self fileRef];
NSURL *aURL = aRef == NULL ? nil :
[(id)CFURLCreateFromFSRef(CFAllocatorGetDefault(), aRef) autorelease];
if (aURL == nil && hadFileRef) {
- NSZoneFree([self zone], (void *)fileRef);
- fileRef = NULL;
- aRef = [self fsRef];
- if (aRef != NULL)
+ // apparently fileRef is invalid, try to update it
+ [self setFileRef:NULL];
+ if (aRef = [self fileRef])
aURL = [(id)CFURLCreateFromFSRef(CFAllocatorGetDefault(), aRef)
autorelease];
}
return aURL;
@@ -586,7 +610,7 @@
// make sure the fileRef is valid
[self fileURL];
- FSRef *fsRef = (FSRef *)[self fsRef];
+ FSRef *fsRef = (FSRef *)[self fileRef];
FSRef baseRef;
NSURL *baseURL;
BDAlias *anAlias = nil;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit