NSObject+OCExtensions.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // NSObject+OCExtensions.m
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2024/2/4.
  6. //
  7. #import "NSObject+OCExtensions.h"
  8. #import "SKAttachmentEmailer.h"
  9. @implementation NSObject (OCExtensions)
  10. @end
  11. @implementation NSDocument (OCExtensions)
  12. - (void)newSaveArchiveToURL:(NSURL *)fileURL email:(BOOL)email {
  13. NSTask *task = [[NSTask alloc] init];
  14. if ([[fileURL pathExtension] isEqualToString:@"dmg"]) {
  15. [task setLaunchPath:@"/usr/bin/hdiutil"];
  16. [task setArguments:[NSArray arrayWithObjects:@"create", @"-srcdir", [[self fileURL] path], @"-format", @"UDZO", @"-volname", [[fileURL lastPathComponent] stringByDeletingPathExtension], [fileURL path], nil]];
  17. } else {
  18. [task setLaunchPath:@"/usr/bin/tar"];
  19. [task setArguments:[NSArray arrayWithObjects:@"-czf", [fileURL path], [[self fileURL] lastPathComponent], nil]];
  20. }
  21. [task setCurrentDirectoryPath:[[[self fileURL] URLByDeletingLastPathComponent] path]];
  22. [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]];
  23. [task setStandardError:[NSFileHandle fileHandleWithNullDevice]];
  24. static SKAttachmentEmailer *emailer = nil;
  25. if (email)
  26. emailer = [SKAttachmentEmailer attachmentEmailerWithFileURL:fileURL subject:[self displayName] waitingForTask:task];
  27. @try {
  28. [task launch];
  29. }
  30. @catch (id exception) {
  31. [emailer taskFailed];
  32. }
  33. }
  34. @end
  35. @implementation NSString (OCExtensions)
  36. - (BOOL)isCaseInsensitiveEqual:(NSString *)aString {
  37. return [self caseInsensitiveCompare:aString] == NSOrderedSame;
  38. }
  39. @end