Improve NSSecureCoding support.
This commit is contained in:
1 parent
21ff474e5b
commit
b0881c91a9
2 files changed
+19
-3
No files matched your search
+14
-2
@@ -44,7 +44,12 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
|||||||
|
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:queueURL.path]) {
|
if ([[NSFileManager defaultManager] fileExistsAtPath:queueURL.path]) {
|
||||||
@try {
|
@try {
|
||||||
_items = [NSKeyedUnarchiver unarchiveObjectWithFile:queueURL.path];
|
NSData *queue = [NSData dataWithContentsOfURL:queueURL];
|
||||||
|
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:queue];
|
||||||
|
unarchiver.requiresSecureCoding = YES;
|
||||||
|
_items = [unarchiver decodeObjectOfClasses:[NSSet setWithObjects:[NSMutableArray class], [SBQueueItem class], nil]
|
||||||
|
forKey:NSKeyedArchiveRootObjectKey];
|
||||||
|
[unarchiver finishDecoding];
|
||||||
}
|
}
|
||||||
@catch (NSException *exception) {
|
@catch (NSException *exception) {
|
||||||
[[NSFileManager defaultManager] removeItemAtURL:queueURL error:nil];
|
[[NSFileManager defaultManager] removeItemAtURL:queueURL error:nil];
|
||||||
@@ -69,7 +74,14 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
|
|||||||
- (BOOL)saveQueueToDisk {
|
- (BOOL)saveQueueToDisk {
|
||||||
__block BOOL result;
|
__block BOOL result;
|
||||||
dispatch_sync(self.arrayQueue, ^{
|
dispatch_sync(self.arrayQueue, ^{
|
||||||
result = [NSKeyedArchiver archiveRootObject:self.items toFile:self.URL.path];
|
NSMutableData *data = [[NSMutableData alloc] init];
|
||||||
|
|
||||||
|
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
|
||||||
|
archiver.requiresSecureCoding = YES;
|
||||||
|
[archiver encodeObject:self.items forKey:NSKeyedArchiveRootObjectKey];
|
||||||
|
[archiver finishEncoding];
|
||||||
|
|
||||||
|
result = [data writeToURL:self.URL atomically:YES];
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,7 +409,11 @@ bail:
|
|||||||
_fileURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"SBQueueItemFileURL"];
|
_fileURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"SBQueueItemFileURL"];
|
||||||
_destURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"SBQueueItemDestURL"];
|
_destURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"SBQueueItemDestURL"];
|
||||||
_attributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"SBQueueItemAttributes"];
|
_attributes = [decoder decodeObjectOfClass:[NSDictionary class] forKey:@"SBQueueItemAttributes"];
|
||||||
_actionsInternal = [decoder decodeObjectOfClass:[NSMutableArray class] forKey:@"SBQueueItemActions"];
|
_actionsInternal = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[NSMutableArray class], [SBQueueSetAction class],
|
||||||
|
[SBQueueMetadataAction class], [SBQueueSubtitlesAction class],
|
||||||
|
[SBQueueSetLanguageAction class], [SBQueueFixFallbacksAction class],
|
||||||
|
[SBQueueClearTrackNameAction class], [SBQueueOrganizeGroupsAction class], nil]
|
||||||
|
forKey:@"SBQueueItemActions"];
|
||||||
|
|
||||||
_status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
|
_status = [decoder decodeIntForKey:@"SBQueueItemStatus"];
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user