diff --git a/XADArchiveParser.m b/XADArchiveParser.m index 051c14e2..19675c82 100644 --- a/XADArchiveParser.m +++ b/XADArchiveParser.m @@ -560,7 +560,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename { // An empty array means scanning failed. Set a flag to // warn the caller, and fall through to single-file mode. - props[XADVolumeScanningFailedKey] = @YES; + [props setValue:[NSNumber numberWithBool:YES] forKey:XADVolumeScanningFailedKey]; } } } @@ -571,7 +571,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename parser.resourceFork = fork; parser.filename = filename.path; - props[XADVolumesKey] = @[filename.path]; + [props setValue:[NSArray arrayWithObject:filename.path] forKey:XADVolumesKey]; [parser addPropertiesFromDictionary:props]; return [parser autorelease]; @@ -1067,7 +1067,7 @@ + (void)throwExceptionFromError:(NSError *)error return; } NSMutableDictionary *exceptionUserInfo = [error.userInfo mutableCopy]; - exceptionUserInfo[@"XADError"] = @((XADError)error.code); + [exceptionUserInfo setValue:[NSNumber numberWithInt:(XADError)error.code] forKey:@"XADError"]; [[[NSException alloc] initWithName:XADExceptionName reason:[XADException describeXADError:(XADError)error.code] userInfo:exceptionUserInfo] raise]; @@ -1550,7 +1550,7 @@ +(XADArchiveParser *)archiveParserForFileURL:(NSURL *)filename error:(NSError ** return nil; } if (errorptr) { - *errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:@{NSURLErrorKey: filename}]; + *errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:[NSDictionary dictionaryWithObjectsAndKeys:filename, NSURLErrorKey, nil]]; } return nil; } @@ -1569,7 +1569,7 @@ +(XADArchiveParser *)archiveParserForPath:(NSString *)filename nserror:(NSError return nil; } if (errorptr) { - *errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:@{NSFilePathErrorKey: filename}]; + *errorptr = [NSError errorWithDomain:XADErrorDomain code:XADErrorNotSupported userInfo:[NSDictionary dictionaryWithObjectsAndKeys:filename, NSFilePathErrorKey, nil]]; } return nil; } diff --git a/XADException.m b/XADException.m index 8e75e5c4..4e6e4d97 100644 --- a/XADException.m +++ b/XADException.m @@ -79,22 +79,22 @@ +(XADError)parseException:(id)exception return XADErrorUnknown; } -+(NSError*)parseExceptionReturningNSError:(nonnull id)exception ++(NSError*)parseExceptionReturningNSError:(id)exception { if([exception isKindOfClass:[NSException class]]) { NSException *e=exception; NSString *name=[e name]; - NSMutableDictionary *usrInfo = [NSMutableDictionary dictionaryWithDictionary:e.userInfo ?: @{}]; - usrInfo[XADExceptionReasonKey] = e.reason; + NSMutableDictionary *usrInfo = [NSMutableDictionary dictionaryWithDictionary:e.userInfo ?: [NSDictionary dictionary]]; + [usrInfo setValue:e.reason forKey:XADExceptionReasonKey]; if ([name isEqualToString:XADExceptionName]) { - XADError errVal = [[e userInfo][@"XADError"] intValue]; + XADError errVal = [[[e userInfo] objectForKey:@"XADError"] intValue]; return [NSError errorWithDomain:XADErrorDomain code:errVal userInfo:usrInfo]; } else if([name isEqualToString:CSCannotOpenFileException]) { return [NSError errorWithDomain:XADErrorDomain code:XADErrorOpenFile userInfo:usrInfo]; } else if([name isEqualToString:CSFileErrorException]) { if (usrInfo && [usrInfo objectForKey:@"ErrNo"]) { - int errNo = [usrInfo[@"ErrNo"] intValue]; + int errNo = [[usrInfo objectForKey:@"ErrNo"] intValue]; [usrInfo removeObjectForKey:@"ErrNo"]; return [NSError errorWithDomain:NSPOSIXErrorDomain code:errNo userInfo:usrInfo]; } diff --git a/XADPlatformLinux.m b/XADPlatformLinux.m index 815dcfd0..04a5df39 100644 --- a/XADPlatformLinux.m +++ b/XADPlatformLinux.m @@ -105,7 +105,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path if(chmod(cpath,mode&~S_IFMT)!=0) return XADUnknownError; // TODO: bette error } - return XADNoError; + return XADErrorNone; } +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link @@ -115,7 +115,7 @@ +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)lin if(lstat(destcstr,&st)==0) unlink(destcstr); if(symlink([link fileSystemRepresentation],destcstr)!=0) return XADLinkError; - return XADNoError; + return XADErrorNone; } diff --git a/XADPlatformWindows.m b/XADPlatformWindows.m index 213afba2..9bd7a16a 100644 --- a/XADPlatformWindows.m +++ b/XADPlatformWindows.m @@ -97,7 +97,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path SetFileAttributesW(wpath,newattributes); } - return XADNoError; + return XADErrorNone; } +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link diff --git a/XADPlatformiOS.m b/XADPlatformiOS.m index 2cb6fec1..72262e8e 100644 --- a/XADPlatformiOS.m +++ b/XADPlatformiOS.m @@ -121,7 +121,7 @@ +(XADError)updateFileAttributesAtPath:(NSString *)path // Finally, set all attributes. setattrlist(cpath,&list,attrdata,attrptr-attrdata,FSOPT_NOFOLLOW); - return XADNoError; + return XADErrorNone; } +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)link @@ -131,7 +131,7 @@ +(XADError)createLinkAtPath:(NSString *)path withDestinationPath:(NSString *)lin if(lstat(destcstr,&st)==0) unlink(destcstr); if(symlink([link fileSystemRepresentation],destcstr)!=0) return XADLinkError; - return XADNoError; + return XADErrorNone; } diff --git a/XADSimpleUnarchiver.h b/XADSimpleUnarchiver.h index f5c690ab..bff84c44 100644 --- a/XADSimpleUnarchiver.h +++ b/XADSimpleUnarchiver.h @@ -131,6 +131,7 @@ XADEXPORT -(XADError)parse; -(XADError)_setupSubArchiveForEntryWithDataFork:(NSDictionary *)datadict resourceFork:(NSDictionary *)resourcedict; +-(BOOL)_setupSubArchiveForEntryWithDataFork:(NSDictionary *)datadict resourceFork:(NSDictionary *)resourcedict error:(NSError**)outError; -(XADError)unarchive; -(XADError)_unarchiveRegularArchive; diff --git a/XADSimpleUnarchiver.m b/XADSimpleUnarchiver.m index 3ed5107b..04b4655a 100644 --- a/XADSimpleUnarchiver.m +++ b/XADSimpleUnarchiver.m @@ -328,7 +328,7 @@ -(BOOL)parseWithError:(NSError**)error { if(entries.count) { if (error) { - *error = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:@{NSLocalizedDescriptionKey: @"You can not call parseAndUnarchive twice", NSDebugDescriptionErrorKey: @"You can not call parseAndUnarchive twice"}]; + *error = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"You can not call parseAndUnarchive twice", NSLocalizedDescriptionKey, nil]]; } return NO; @@ -344,8 +344,8 @@ -(BOOL)parseWithError:(NSError**)error if (extractsubarchives) { // Check if we have a single entry, which is an archive. if (entries.count==1) { - NSDictionary *entry=entries[0]; - NSNumber *archnum=entry[XADIsArchiveKey]; + NSDictionary *entry=[entries objectAtIndex:0]; + NSNumber *archnum=[entry objectForKey:XADIsArchiveKey]; BOOL isarc=archnum&&archnum.boolValue; if(isarc) return [self _setupSubArchiveForEntryWithDataFork:entry resourceFork:nil error:error]; } @@ -353,17 +353,17 @@ -(BOOL)parseWithError:(NSError**)error // Check if we have two entries, which are data and resource forks // of the same archive. if (entries.count==2) { - NSDictionary *first=entries[0]; - NSDictionary *second=entries[1]; - XADPath *name1=first[XADFileNameKey]; - XADPath *name2=second[XADFileNameKey]; - NSNumber *archnum1=first[XADIsArchiveKey]; - NSNumber *archnum2=second[XADIsArchiveKey]; + NSDictionary *first=[entries objectAtIndex:0]; + NSDictionary *second=[entries objectAtIndex:1]; + XADPath *name1=[first objectForKey:XADFileNameKey]; + XADPath *name2=[second objectForKey:XADFileNameKey]; + NSNumber *archnum1=[first objectForKey:XADIsArchiveKey]; + NSNumber *archnum2=[second objectForKey:XADIsArchiveKey]; BOOL isarc1=archnum1&&archnum1.boolValue; BOOL isarc2=archnum2&&archnum2.boolValue; if ([name1 isEqual:name2] && (isarc1||isarc2)) { - NSNumber *resnum=first[XADIsResourceForkKey]; + NSNumber *resnum=[first objectForKey:XADIsResourceForkKey]; NSDictionary *datafork,*resourcefork; if (resnum&&resnum.boolValue) { datafork=second; @@ -374,7 +374,7 @@ -(BOOL)parseWithError:(NSError**)error } // TODO: Handle resource forks for archives that require them. - NSNumber *archnum=datafork[XADIsArchiveKey]; + NSNumber *archnum=[datafork objectForKey:XADIsArchiveKey]; if(archnum&&archnum.boolValue) { return [self _setupSubArchiveForEntryWithDataFork:datafork resourceFork:resourcefork error:error]; } diff --git a/XADUnarchiver.m b/XADUnarchiver.m index 652eedfe..c5ed70ce 100644 --- a/XADUnarchiver.m +++ b/XADUnarchiver.m @@ -326,9 +326,9 @@ -(XADError)extractEntryWithDictionary:(NSDictionary *)dict as:(NSString *)path f // FIXME: Improve extractEntryWithDictionary:as:forceDirectories:error: with an NSError value. -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)path forceDirectories:(BOOL)force error:(NSError**)outErr { - __strong NSError *tmpErr = nil; + NSError *tmpErr = nil; BOOL okay; - @autoreleasepool { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSNumber *dirnum=dict[XADIsDirectoryKey]; NSNumber *linknum=dict[XADIsLinkKey]; @@ -367,6 +367,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p XADError error=0; okay=[self _ensureDirectoryExists:path.stringByDeletingLastPathComponent error:&tmpErr]; + [tmpErr retain]; if(!okay) goto end; // Attempt to extract embedded archives if requested. @@ -377,6 +378,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p if([delegate unarchiver:self shouldExtractArchiveEntryWithDictionary:dict to:unarchiverpath]) { okay=[self _extractArchiveEntryWithDictionary:dict to:unarchiverpath name:path.lastPathComponent error:&tmpErr]; + [tmpErr retain]; // If extraction was attempted, and succeeded for failed, skip everything else. // Otherwise, if the archive couldn't be opened, fall through and extract normally. if(!okay && ([tmpErr.domain isEqualToString:XADErrorDomain] && tmpErr.code != XADErrorSubArchive)) goto end; @@ -399,7 +401,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p tmpErr = nil; } else { okay = NO; - tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil]; + tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil]; } } break; @@ -413,7 +415,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p tmpErr = nil; } else { okay = NO; - tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil]; + tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil]; } } break; @@ -443,7 +445,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p tmpErr = nil; } else { okay = NO; - tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil]; + tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil]; } break; @@ -451,7 +453,7 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p // TODO: better error error=XADErrorBadParameters; okay = NO; - tmpErr = [NSError errorWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil]; + tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:XADErrorBadParameters userInfo:nil]; break; } @@ -479,18 +481,21 @@ -(BOOL)extractEntryWithDictionary:(NSDictionary *)dict as:(nullable NSString *)p tmpErr = nil; } else { okay = NO; - tmpErr = [NSError errorWithDomain:XADErrorDomain code:error userInfo:nil]; + tmpErr = [[NSError alloc] initWithDomain:XADErrorDomain code:error userInfo:nil]; } // Report success or failure end: - if(delegate && [delegate respondsToSelector:@selector(unarchiver:didExtractEntryWithDictionary:to:error:)]) + if([delegate respondsToSelector:@selector(unarchiver:didExtractEntryWithDictionary:to:error:)]) { [delegate unarchiver:self didExtractEntryWithDictionary:dict to:path nserror:okay ? nil : tmpErr]; } - } + [pool release]; + if (outErr && tmpErr) { - *outErr = tmpErr; + *outErr = [tmpErr autorelease]; + } else if (tmpErr) { + [tmpErr release]; } return okay; @@ -877,7 +882,7 @@ -(XADError)_ensureDirectoryExists:(NSString *)path if ([delegate respondsToSelector:@selector(unarchiver:didCreateDirectory:)]) { [delegate unarchiver:self didCreateDirectory:path]; } - return XADNoError; + return XADErrorNone; } #endif else return XADErrorMakeDirectory;