Commit ba6c7ff5 authored by Damiano Galassi's avatar Damiano Galassi

MacGui: make use of some newer NSCoding api to better report decoding failure.

parent c8e8231c
......@@ -278,10 +278,9 @@ NSString *HBAudioEncoderChangedNotification = @"HBAudioEncoderChangedNotificatio
self = [super init];
decodeInt(_container); if (_container != HB_MUX_MP4 && _container != HB_MUX_MKV && _container != HB_MUX_WEBM) { goto fail; }
decodeCollectionOfObjects(_sourceTracks, NSArray, HBTitleAudioTrack);
if (_sourceTracks == nil || _sourceTracks.count < 1) { goto fail; }
decodeCollectionOfObjects(_tracks, NSMutableArray, HBAudioTrack);
if (_tracks == nil) { goto fail; }
decodeCollectionOfObjectsOrFail(_sourceTracks, NSArray, HBTitleAudioTrack);
if (_sourceTracks.count < 1) { goto fail; }
decodeCollectionOfObjectsOrFail(_tracks, NSMutableArray, HBAudioTrack);
for (HBAudioTrack *track in _tracks)
{
......
......@@ -474,11 +474,8 @@
goto fail;
}
decodeCollectionOfObjects(_trackSelectionLanguages, NSMutableArray, NSString);
if (_trackSelectionLanguages == nil) { goto fail; }
decodeCollectionOfObjects(_tracksArray, NSMutableArray, HBAudioTrackPreset);
if (_tracksArray == nil) { goto fail; }
decodeCollectionOfObjectsOrFail(_trackSelectionLanguages, NSMutableArray, NSString);
decodeCollectionOfObjectsOrFail(_tracksArray, NSMutableArray, HBAudioTrackPreset);
decodeBool(_allowAACPassthru);
decodeBool(_allowAC3Passthru);
......
......@@ -19,15 +19,10 @@
#define decodeDouble(x) x = [decoder decodeDoubleForKey:OBJC_STRINGIFY(x)]
#define decodeObject(x, cl) x = [decoder decodeObjectOfClass:[cl class] forKey:OBJC_STRINGIFY(x)];
#define decodeCollectionOfObjects(x, cl, objectcl) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], nil] forKey:OBJC_STRINGIFY(x)];
#define decodeCollectionOfObjects2(x, cl, objectcl, objectcl2) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], [objectcl2 class], nil] forKey:OBJC_STRINGIFY(x)];
#define decodeCollectionOfObjects3(x, cl, objectcl, objectcl2, objectcl3) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], [objectcl2 class], [objectcl3 class], nil] forKey:OBJC_STRINGIFY(x)];
#define fail(x) [decoder failWithError:[NSError errorWithDomain:@"HBKitErrorDomain" code:1 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to decode %@", OBJC_STRINGIFY(x)]}]]; goto fail;
#define decodeCollectionOfObjects4(x, cl, objectcl, objectcl2, objectcl3, objectcl4) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], [objectcl2 class], [objectcl3 class], [objectcl4 class], nil] forKey:OBJC_STRINGIFY(x)];
#define decodeCollectionOfObjects5(x, cl, objectcl, objectcl2, objectcl3, objectcl4, objectcl5) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], [objectcl2 class], [objectcl3 class], [objectcl4 class], [objectcl5 class], nil] forKey:OBJC_STRINGIFY(x)];
#define decodeCollectionOfObjects(x, cl, objectcl) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], nil] forKey:OBJC_STRINGIFY(x)];
#define decodeCollectionOfObjectsOrFail(x, cl, objectcl) x = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], nil] forKey:OBJC_STRINGIFY(x)]; if (x == nil || ![x isKindOfClass:[cl class]]) { fail(x) }
#define decodeObjectOrFail(x, cl) x = [decoder decodeObjectOfClass:[cl class] forKey:OBJC_STRINGIFY(x)]; if (x == nil) {NSLog(@"Failed to decode: %@", OBJC_STRINGIFY(x)); goto fail;}
#define decodeObjectOrFail(x, cl) x = [decoder decodeObjectOfClass:[cl class] forKey:OBJC_STRINGIFY(x)]; if (x == nil) { fail(x) }
......@@ -187,7 +187,7 @@ typedef void (^HBCoreCleanupHandler)(void);
NSAssert(url, @"[HBCore canScan:] called with nil url.");
#ifdef __SANDBOX_ENABLED__
BOOL accessingSecurityScopedResource = [url startAccessingSecurityScopedResource];
HBSecurityAccessToken *token = [HBSecurityAccessToken tokenWithObject:url];
#endif
if (![[NSFileManager defaultManager] fileExistsAtPath:url.path]) {
......@@ -235,10 +235,7 @@ typedef void (^HBCoreCleanupHandler)(void);
}
#ifdef __SANDBOX_ENABLED__
if (accessingSecurityScopedResource)
{
[url stopAccessingSecurityScopedResource];
}
token = nil;
#endif
return YES;
......
......@@ -194,20 +194,21 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
*/
- (void)reload
{
NSMutableArray<HBUniqueObject> *jobsArray = nil;
@try
{
NSData *queue = [NSData dataWithContentsOfURL:self.fileURL];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:queue];
unarchiver.requiresSecureCoding = YES;
jobsArray = [unarchiver decodeObjectOfClasses:self.objectClasses forKey:NSKeyedArchiveRootObjectKey];
[unarchiver finishDecoding];
}
@catch (NSException *exception)
NSMutableArray<HBUniqueObject> *jobsArray;
NSError *error;
NSData *queue = [NSData dataWithContentsOfURL:self.fileURL];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:queue];
unarchiver.requiresSecureCoding = YES;
jobsArray = [unarchiver decodeTopLevelObjectOfClasses:self.objectClasses forKey:NSKeyedArchiveRootObjectKey error:&error];
if (error)
{
jobsArray = nil;
[HBUtilities writeErrorToActivityLog:error];
}
[unarchiver finishDecoding];
// Swap the proxy objects representation with the new
// one read from disk
NSMutableArray *proxyArray = [NSMutableArray array];
......
......@@ -11,8 +11,7 @@
- (BOOL)canBeHidden;
// Responder chains is nice and good, but NSViewController
// are not automatically inserted in the responder chain prior 10.10
// and are removed when the view is hidden, so let's deliver the
// are removed when the view is hidden, so let's deliver the
// events manually.
- (BOOL)HB_keyDown:(NSEvent *)event;
......
......@@ -481,8 +481,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
_video.job = self;
decodeBool(_chaptersEnabled);
decodeCollectionOfObjects(_chapterTitles, NSArray, HBChapter);
if (_chapterTitles == nil) { goto fail; }
decodeCollectionOfObjectsOrFail(_chapterTitles, NSArray, HBChapter);
return self;
}
......
......@@ -64,7 +64,7 @@
_proxy = [_connection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
dispatch_sync(dispatch_get_main_queue(), ^{
[self forwardError:@"XPC: Service did report an error\n"];
[self forwardError:error.description];
[HBUtilities writeErrorToActivityLog:error];
});
}];
......
......@@ -461,10 +461,9 @@
_tokens = [NSMutableArray array];
decodeInt(_container); if (_container != HB_MUX_MP4 && _container != HB_MUX_MKV && _container != HB_MUX_WEBM) { goto fail; }
decodeCollectionOfObjects(_sourceTracks, NSArray, HBTitleSubtitlesTrack);
if (_sourceTracks == nil || _sourceTracks.count < 1) { goto fail; }
decodeCollectionOfObjects(_tracks, NSMutableArray, HBSubtitlesTrack);
if (_tracks == nil) { goto fail; }
decodeCollectionOfObjectsOrFail(_sourceTracks, NSArray, HBTitleSubtitlesTrack);
if (_sourceTracks.count < 1) { goto fail; }
decodeCollectionOfObjectsOrFail(_tracks, NSMutableArray, HBSubtitlesTrack);
for (HBSubtitlesTrack *track in _tracks)
{
......
......@@ -230,8 +230,7 @@
{
goto fail;
}
decodeCollectionOfObjects(_trackSelectionLanguages, NSMutableArray, NSString);
if (_trackSelectionLanguages == nil) { goto fail; }
decodeCollectionOfObjectsOrFail(_trackSelectionLanguages, NSMutableArray, NSString);
decodeBool(_addForeignAudioSearch);
decodeBool(_addForeignAudioSubtitle);
......
......@@ -46,7 +46,7 @@
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
self.core = [[HBCore alloc] initWithLogLevel:1 queue:self.queue];
[self.core scanURL:sampleURL titleIndex:0 previews:1 minDuration:0 progressHandler:^(HBState state, HBProgress progress, NSString * _Nonnull info) {
[self.core scanURL:sampleURL titleIndex:0 previews:1 minDuration:0 keepPreviews:NO progressHandler:^(HBState state, HBProgress progress, NSString * _Nonnull info) {
} completionHandler:^(HBCoreResult result) {
dispatch_semaphore_signal(sem);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment