Guest User

Untitled

a guest
Mar 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1.  
  2. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  3. FILE *fp = NULL, *cmdFP = NULL;
  4. BOOL error = YES;
  5. @try {
  6. NSString *archivePath = [archiveURL path];
  7.  
  8. // Get the file size.
  9. NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize];
  10. if (fs == nil) return;
  11.  
  12. fp = fopen([archivePath fileSystemRepresentation], "r");
  13. if (fp == nil) return;
  14.  
  15. setenv("DESTINATION", [[archivePath stringByDeletingLastPathComponent] UTF8String], 1);
  16. cmdFP = popen([command fileSystemRepresentation], "w");
  17. if (cmdFP == nil) return;
  18.  
  19. char buf[32*1024];
  20. size_t len;
  21. while((len = fread(buf, 1, sizeof buf, fp))) {
  22. fwrite(buf, 1, len, cmdFP);
  23. [self performSelectorOnMainThread: @selector(_notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithLong:len] waitUntilDone:NO];
  24. }
  25.  
  26. error = NO;
  27. }
  28. @finally {
  29. if(fp) fclose(fp);
  30. if(cmdFP) pclose(cmdFP);
  31.  
  32. if(error) {
  33. [self performSelectorOnMainThread:@selector(_notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
  34. } else {
  35. [self performSelectorOnMainThread:@selector(_notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
  36. }
  37.  
  38. [pool drain];
  39. }
Add Comment
Please, Sign In to add comment