Reworked the way a mp4 is saved a bit

This commit is contained in:
galad87 committed 2015-08-27 18:30:03 +02:00
1 parent 2c7fdefdcf
commit d047d4e481
1 file changed
+23 -31
+23 -31
View File
@@ -94,23 +94,9 @@
return NO; return NO;
} }
- (void)reloadFile:(NSURL *)absoluteURL
{
if (absoluteURL) {
self.mp4 = [[[MP42File alloc] initWithExistingFile:absoluteURL andDelegate:self] autorelease];
[fileTracksTable reloadData];
[self reloadPropertyView];
if (!self.mp4) {
[self close];
}
}
}
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{ {
self.mp4 = [[[MP42File alloc] initWithExistingFile:absoluteURL andDelegate:self] autorelease]; self.mp4 = [[[MP42File alloc] initWithURL:absoluteURL delegate:self] autorelease];
if (outError != NULL && !self.mp4) { if (outError != NULL && !self.mp4) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL]; *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
@@ -123,7 +109,7 @@
- (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError - (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{ {
self.mp4 = [[[MP42File alloc] initWithExistingFile:absoluteURL andDelegate:self] autorelease]; self.mp4 = [[[MP42File alloc] initWithURL:absoluteURL delegate:self] autorelease];
[fileTracksTable reloadData]; [fileTracksTable reloadData];
[self reloadPropertyView]; [self reloadPropertyView];
@@ -163,7 +149,6 @@
IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, IOReturn io_success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep,
kIOPMAssertionLevelOn, reasonForActivity, &assertionID); kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
BOOL result = NO; BOOL result = NO;
NSError *inError = nil;
NSMutableDictionary<NSString *, NSNumber *> * attributes = [[NSMutableDictionary alloc] init]; NSMutableDictionary<NSString *, NSNumber *> * attributes = [[NSMutableDictionary alloc] init];
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) { if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"chaptersPreviewTrack"] boolValue]) {
@@ -177,15 +162,15 @@
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.
result = [self.mp4 updateMP4FileWithAttributes:attributes error:&inError]; result = [self.mp4 updateMP4FileWithAttributes:attributes error:outError];
break; break;
case NSSaveAsOperation: case NSSaveAsOperation:
// movie doesn not exist, create a new one from scratch. // movie does not exist, create a new one from scratch.
if ([_64bit_data state]) { attributes[MP4264BitData] = @YES; } if ([_64bit_data state]) { attributes[MP4264BitData] = @YES; }
if ([_64bit_time state]) { attributes[MP4264BitTime] = @YES; } if ([_64bit_time state]) { attributes[MP4264BitTime] = @YES; }
result = [self.mp4 writeToUrl:url withAttributes:attributes error:&inError]; result = [self.mp4 writeToUrl:url withAttributes:attributes error:outError];
break; break;
default: default:
@@ -207,24 +192,31 @@
IOPMAssertionRelease(assertionID); IOPMAssertionRelease(assertionID);
} }
NSError *error = *outError;
MP42File *reloadedFile = nil;
if (result == YES) {
reloadedFile = [[[MP42File alloc] initWithURL:url delegate:self] autorelease];
}
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[NSApp endSheet:savingWindow]; [NSApp endSheet:savingWindow];
[savingWindow orderOut:self]; [savingWindow orderOut:self];
[optBar stopAnimation:self]; [optBar stopAnimation:self];
if (inError && inError.code == 101) { if (result == YES && error) {
// Write permission error, don't reload the file [self presentError:error
} else { modalForWindow:documentWindow
[self reloadFile:url]; delegate:nil
didPresentSelector:NULL
contextInfo:NULL];
} }
if (inError) { if (reloadedFile) {
[self presentError:inError self.mp4 = reloadedFile;
modalForWindow:documentWindow
delegate:nil
didPresentSelector:NULL
contextInfo:NULL];
} }
}); });
return result; return result;
@@ -816,7 +808,7 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn
} }
else { else {
MP42File *file = nil; MP42File *file = nil;
if ((file = [[MP42File alloc] initWithExistingFile:URL andDelegate:self])) { if ((file = [[MP42File alloc] initWithURL:URL delegate:self])) {
[self.mp4.metadata mergeMetadata:file.metadata]; [self.mp4.metadata mergeMetadata:file.metadata];
[file release]; [file release];
} }