Use NSDocument's asynchronous saving instead of the the previous ugly hack.
This commit is contained in:
1 parent
475efae14c
commit
18af7bce53
1 file changed
+53
-68
+53
-68
@@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
+ (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)type
|
+ (BOOL)canConcurrentlyReadDocumentsOfType:(NSString *)type
|
||||||
{
|
{
|
||||||
return NO;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isEntireFileLoaded
|
- (BOOL)isEntireFileLoaded
|
||||||
@@ -142,50 +142,42 @@
|
|||||||
|
|
||||||
#pragma mark Save methods
|
#pragma mark Save methods
|
||||||
|
|
||||||
- (BOOL)saveDidComplete:(NSError **)outError URL:(NSURL *)absoluteURL
|
- (BOOL)canAsynchronouslyWriteToURL:(NSURL *)url
|
||||||
|
ofType:(NSString *)typeName
|
||||||
|
forSaveOperation:(NSSaveOperationType)saveOperation
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)saveDidComplete:(NSError *)outError URL:(NSURL *)absoluteURL
|
||||||
{
|
{
|
||||||
[NSApp endSheet:savingWindow];
|
[NSApp endSheet:savingWindow];
|
||||||
[savingWindow orderOut:self];
|
[savingWindow orderOut:self];
|
||||||
[optBar stopAnimation:self];
|
[optBar stopAnimation:self];
|
||||||
|
|
||||||
if (*outError && [*outError code] == 101) {
|
if (outError && [outError code] == 101) {
|
||||||
// Write permission error, don't reload the file
|
// Write permission error, don't reload the file
|
||||||
} else {
|
} else {
|
||||||
[self reloadFile:absoluteURL];
|
[self reloadFile:absoluteURL];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*outError) {
|
if (outError) {
|
||||||
[self presentError:*outError
|
[self presentError:outError
|
||||||
modalForWindow:documentWindow
|
modalForWindow:documentWindow
|
||||||
delegate:nil
|
delegate:nil
|
||||||
didPresentSelector:NULL
|
didPresentSelector:NULL
|
||||||
contextInfo:NULL];
|
contextInfo:NULL];
|
||||||
|
|
||||||
[*outError release];
|
[outError release];
|
||||||
}
|
}
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)saveDidEnd:(id)sender {
|
|
||||||
/* Post an event so our event loop wakes up */
|
|
||||||
[NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
|
|
||||||
location:NSZeroPoint
|
|
||||||
modifierFlags:0
|
|
||||||
timestamp:0
|
|
||||||
windowNumber:0
|
|
||||||
context:NULL
|
|
||||||
subtype:0
|
|
||||||
data1:0
|
|
||||||
data2:0] atStart:NO];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)writeSafelyToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
|
- (BOOL)writeSafelyToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName
|
||||||
forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError;
|
forSaveOperation:(NSSaveOperationType)saveOperation error:(NSError **)outError;
|
||||||
{
|
{
|
||||||
__block BOOL success = NO;
|
NSError *inError = nil;
|
||||||
__block int32_t done = 0;
|
|
||||||
__block NSError *inError = NULL;
|
|
||||||
|
|
||||||
NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init];
|
NSMutableDictionary * attributes = [[NSMutableDictionary alloc] init];
|
||||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
|
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue])
|
||||||
@@ -193,65 +185,58 @@
|
|||||||
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBOrganizeAlternateGroups"] boolValue])
|
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"SBOrganizeAlternateGroups"] boolValue])
|
||||||
[attributes setObject:@YES forKey:MP42OrganizeAlternateGroups];
|
[attributes setObject:@YES forKey:MP42OrganizeAlternateGroups];
|
||||||
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[optBar setIndeterminate:YES];
|
||||||
|
[optBar startAnimation:self];
|
||||||
|
[saveOperationName setStringValue:@"Saving…"];
|
||||||
|
[NSApp beginSheet:savingWindow modalForWindow:documentWindow
|
||||||
|
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
||||||
|
});
|
||||||
|
|
||||||
[optBar setIndeterminate:YES];
|
[self unblockUserInteraction];
|
||||||
[optBar startAnimation:self];
|
|
||||||
[saveOperationName setStringValue:@"Saving…"];
|
|
||||||
[NSApp beginSheet:savingWindow modalForWindow:documentWindow
|
|
||||||
modalDelegate:nil didEndSelector:NULL contextInfo:nil];
|
|
||||||
|
|
||||||
IOPMAssertionID assertionID;
|
IOPMAssertionID assertionID;
|
||||||
// Enable sleep assertion
|
// Enable sleep assertion
|
||||||
CFStringRef reasonForActivity= CFSTR("Subler Save Operation");
|
CFStringRef reasonForActivity= CFSTR("Subler Save Operation");
|
||||||
IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep,
|
IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep,
|
||||||
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
|
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
|
||||||
|
BOOL success = NO;
|
||||||
|
|
||||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
switch (saveOperation) {
|
||||||
switch (saveOperation) {
|
case NSSaveOperation:
|
||||||
case NSSaveOperation:
|
// movie file already exists, so we'll just update
|
||||||
// movie file already exists, so we'll just update
|
// the movie resource
|
||||||
// the movie resource
|
success = [self.mp4 updateMP4FileWithAttributes:attributes error:&inError];
|
||||||
success = [self.mp4 updateMP4FileWithAttributes:attributes error:&inError];
|
break;
|
||||||
break;
|
case NSSaveAsOperation:
|
||||||
case NSSaveAsOperation:
|
if ([_64bit_data state]) [attributes setObject:@YES forKey:MP4264BitData];
|
||||||
if ([_64bit_data state]) [attributes setObject:@YES forKey:MP4264BitData];
|
if ([_64bit_time state]) [attributes setObject:@YES forKey:MP4264BitTime];
|
||||||
if ([_64bit_time state]) [attributes setObject:@YES forKey:MP4264BitTime];
|
success = [self.mp4 writeToUrl:absoluteURL withAttributes:attributes error:&inError];
|
||||||
success = [self.mp4 writeToUrl:absoluteURL withAttributes:attributes error:&inError];
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
NSAssert(NO, @"Unhandled save operation");
|
||||||
// not implemented
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (success && _optimize) {
|
|
||||||
[saveOperationName setStringValue:@"Optimizing…"];
|
|
||||||
success = [self.mp4 optimize];
|
|
||||||
_optimize = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
done = 1;
|
|
||||||
[inError retain];
|
|
||||||
});
|
|
||||||
|
|
||||||
while (!done) {
|
|
||||||
@autoreleasepool {
|
|
||||||
@try {
|
|
||||||
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES];
|
|
||||||
if (event) [NSApp sendEvent:event];
|
|
||||||
}
|
|
||||||
@catch (NSException *localException) {
|
|
||||||
NSLog(@"Exception thrown during save: %@", localException);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (io_success == kIOReturnSuccess)
|
if (success && _optimize) {
|
||||||
IOPMAssertionRelease(assertionID);
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[saveOperationName setStringValue:@"Optimizing…"];
|
||||||
|
});
|
||||||
|
success = [self.mp4 optimize];
|
||||||
|
_optimize = NO;
|
||||||
|
}
|
||||||
|
|
||||||
*outError = [inError autorelease];
|
|
||||||
[*outError retain];
|
if (io_success == kIOReturnSuccess) {
|
||||||
|
IOPMAssertionRelease(assertionID);
|
||||||
|
}
|
||||||
|
|
||||||
[attributes release];
|
[attributes release];
|
||||||
[self saveDidComplete:outError URL:absoluteURL];
|
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self saveDidComplete:inError URL:absoluteURL];
|
||||||
|
});
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user