// // NSObject+OCExtensions.m // PDF Reader Pro // // Created by tangchao on 2024/2/4. // #import "NSObject+OCExtensions.h" #import "SKAttachmentEmailer.h" @implementation NSObject (OCExtensions) @end @implementation NSDocument (OCExtensions) - (void)newSaveArchiveToURL:(NSURL *)fileURL email:(BOOL)email { NSTask *task = [[NSTask alloc] init]; if ([[fileURL pathExtension] isEqualToString:@"dmg"]) { [task setLaunchPath:@"/usr/bin/hdiutil"]; [task setArguments:[NSArray arrayWithObjects:@"create", @"-srcdir", [[self fileURL] path], @"-format", @"UDZO", @"-volname", [[fileURL lastPathComponent] stringByDeletingPathExtension], [fileURL path], nil]]; } else { [task setLaunchPath:@"/usr/bin/tar"]; [task setArguments:[NSArray arrayWithObjects:@"-czf", [fileURL path], [[self fileURL] lastPathComponent], nil]]; } [task setCurrentDirectoryPath:[[[self fileURL] URLByDeletingLastPathComponent] path]]; [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]]; [task setStandardError:[NSFileHandle fileHandleWithNullDevice]]; static SKAttachmentEmailer *emailer = nil; if (email) emailer = [SKAttachmentEmailer attachmentEmailerWithFileURL:fileURL subject:[self displayName] waitingForTask:task]; @try { [task launch]; } @catch (id exception) { [emailer taskFailed]; } } @end @implementation NSString (OCExtensions) - (BOOL)isCaseInsensitiveEqual:(NSString *)aString { return [self caseInsensitiveCompare:aString] == NSOrderedSame; } @end