Revision: 26791 http://sourceforge.net/p/bibdesk/svn/26791 Author: hofman Date: 2021-09-02 14:53:11 +0000 (Thu, 02 Sep 2021) Log Message: ----------- Reorganize linked file, separate methods to update alias and relative path
Modified Paths: -------------- trunk/bibdesk/BDSKLinkedFile.m Modified: trunk/bibdesk/BDSKLinkedFile.m =================================================================== --- trunk/bibdesk/BDSKLinkedFile.m 2021-09-02 14:30:20 UTC (rev 26790) +++ trunk/bibdesk/BDSKLinkedFile.m 2021-09-02 14:53:11 UTC (rev 26791) @@ -485,15 +485,9 @@ return relativePath; } -- (void)setFileRef:(FSRef *)aRef { - BDSKZONEDESTROY(fileRef); - if (aRef != NULL) { - FSRef *newRef = (FSRef *)NSZoneMalloc([self zone], sizeof(FSRef)); - if (newRef) { - bcopy(aRef, newRef, sizeof(FSRef)); - fileRef = newRef; - } - } +- (void)setRelativePath:(NSString *)path fromPath:(NSString *)basePath { + [relativePath release]; + relativePath = [[path relativePathFromPath:basePath] retain]; } - (void)setFileURL:(NSURL *)aURL { @@ -506,10 +500,19 @@ } } -- (void)updateWithPath:(NSString *)path basePath:(NSString *)basePath baseRef:(FSRef *)baseRef { - BDSKASSERT(path != nil); +- (void)setFileRef:(FSRef *)aRef { + BDSKZONEDESTROY(fileRef); + if (aRef != NULL) { + FSRef *newRef = (FSRef *)NSZoneMalloc([self zone], sizeof(FSRef)); + if (newRef) { + bcopy(aRef, newRef, sizeof(FSRef)); + fileRef = newRef; + } + } +} + +- (void)updateAliasWithBaseRef:(FSRef *)baseRef { BDSKASSERT(fileRef != NULL); - BDSKASSERT(basePath != nil); BDSKASSERT(baseRef != NULL); // update the alias @@ -529,20 +532,8 @@ locator.alias = anAlias; } } - - [relativePath release]; - relativePath = [[path relativePathFromPath:basePath] retain]; } -- (BOOL)updateWithPath:(NSString *)path basePath:(NSString *)basePath { - FSRef baseRef; - if (BDSKPathToFSRef(basePath, &baseRef)) { - [self updateWithPath:path basePath:basePath baseRef:&baseRef]; - return YES; - } - return NO; -} - - (void)updateFileRef; { NSString *basePath = [delegate basePathForLinkedFile:self]; @@ -586,8 +577,10 @@ if (aURL != nil) { if (fileURL == nil) fileURL = [aURL retain]; - if (shouldUpdate) - [self updateWithPath:[aURL path] basePath:basePath baseRef:&baseRef]; + if (shouldUpdate) { + [self updateAliasWithBaseRef:&baseRef]; + [self setRelativePath:[aURL path] fromPath:basePath]; + } [aURL release]; } } @@ -619,7 +612,11 @@ [aURL release]; aURL = BDSKCreateURLFromFSRef(fileRef); NSString *basePath = [delegate basePathForLinkedFile:self]; - [self updateWithPath:[aURL path] basePath:basePath]; + FSRef baseRef; + if (BDSKPathToFSRef(basePath, &baseRef)) { + [self updateAliasWithBaseRef:&baseRef]; + [self setRelativePath:[aURL path] fromPath:basePath]; + } } [self setFileURL:aURL]; } @@ -730,8 +727,13 @@ NSURL *aURL = BDSKCreateURLFromFSRef(fileRef); if (aURL != nil) { // if the path has changed, updating will be done below - if (aPath == nil || [[aURL path] isEqualToString:aPath]) - [self updateWithPath:[aURL path] basePath:basePath]; + if (aPath == nil || [[aURL path] isEqualToString:aPath]) { + FSRef baseRef; + if (BDSKPathToFSRef(basePath, &baseRef)) { + [self updateAliasWithBaseRef:&baseRef]; + [self setRelativePath:[aURL path] fromPath:basePath]; + } + } [aURL release]; } else { // the fileRef was invalid, reset it and update @@ -740,10 +742,8 @@ if (fileRef == NULL && aPath) { // this can happen after an auto file to a volume, as the file is actually not moved but copied [self setAliasWithPath:aPath basePath:basePath]; - if (basePath) { - [relativePath release]; - relativePath = [[aPath relativePathFromPath:basePath] retain]; - } + if (basePath) + [self setRelativePath:aPath fromPath:basePath]; } } } @@ -763,7 +763,10 @@ [aURL release]; } if (needsUpdate) { - if (NO == [self updateWithPath:aPath basePath:basePath]) + FSRef baseRef; + if (BDSKPathToFSRef(basePath, &baseRef)) + [self updateAliasWithBaseRef:&baseRef]; + else [self setAliasWithPath:aPath basePath:basePath]; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit