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