Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- FILE *fp = NULL, *cmdFP = NULL;
- BOOL error = YES;
- @try {
- NSString *archivePath = [archiveURL path];
- // Get the file size.
- NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize];
- if (fs == nil) return;
- fp = fopen([archivePath fileSystemRepresentation], "r");
- if (fp == nil) return;
- setenv("DESTINATION", [[archivePath stringByDeletingLastPathComponent] UTF8String], 1);
- cmdFP = popen([command fileSystemRepresentation], "w");
- if (cmdFP == nil) return;
- char buf[32*1024];
- size_t len;
- while((len = fread(buf, 1, sizeof buf, fp))) {
- fwrite(buf, 1, len, cmdFP);
- [self performSelectorOnMainThread: @selector(_notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithLong:len] waitUntilDone:NO];
- }
- error = NO;
- }
- @finally {
- if(fp) fclose(fp);
- if(cmdFP) pclose(cmdFP);
- if(error) {
- [self performSelectorOnMainThread:@selector(_notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
- } else {
- [self performSelectorOnMainThread:@selector(_notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
- }
- [pool drain];
- }
Add Comment
Please, Sign In to add comment