summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2016-12-27 11:53:11 +0100
committerDamiano Galassi <[email protected]>2016-12-27 11:53:11 +0100
commit2cc18941fa64a74d0f86f00215f112d940266585 (patch)
tree45b4d9b423ebcc5be8605e413af3fc021359e3f9 /macosx
parentec1553108f3881a380904bcc8be7c19a626cb69a (diff)
MacGui: enable NSSecureCoding for the queue file.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBAudio.m4
-rw-r--r--macosx/HBAudioDefaults.m2
-rw-r--r--macosx/HBChapter.h2
-rw-r--r--macosx/HBCodingUtilities.h5
-rw-r--r--macosx/HBCodingUtilities.m13
-rw-r--r--macosx/HBDistributedArray.h2
-rw-r--r--macosx/HBDistributedArray.m14
-rw-r--r--macosx/HBJob.m6
-rw-r--r--macosx/HBPictureHUDController.h8
-rw-r--r--macosx/HBQueueController.m2
-rw-r--r--macosx/HBSubtitles.m6
-rw-r--r--macosx/HBTitle.m2
-rw-r--r--macosx/HBVideo.m2
13 files changed, 50 insertions, 18 deletions
diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m
index 1faae116e..be7df2465 100644
--- a/macosx/HBAudio.m
+++ b/macosx/HBAudio.m
@@ -285,8 +285,8 @@ NSString *HBAudioChangedNotification = @"HBAudioChangedNotification";
self = [super init];
decodeInt(_container);
- decodeObject(_sourceTracks, NSMutableArray);
- decodeObject(_tracks, NSMutableArray);
+ decodeCollectionOfObjects(_sourceTracks, NSArray, NSDictionary);
+ decodeCollectionOfObjects(_tracks, NSMutableArray, HBAudioTrack);
for (HBAudioTrack *track in _tracks)
{
diff --git a/macosx/HBAudioDefaults.m b/macosx/HBAudioDefaults.m
index 127e2a47a..204d13967 100644
--- a/macosx/HBAudioDefaults.m
+++ b/macosx/HBAudioDefaults.m
@@ -471,7 +471,7 @@
decodeInteger(_trackSelectionBehavior);
decodeObject(_trackSelectionLanguages, NSMutableArray);
- decodeObject(_tracksArray, NSMutableArray);
+ decodeCollectionOfObjects(_tracksArray, NSMutableArray, HBAudioTrackPreset);
decodeBool(_allowAACPassthru);
decodeBool(_allowAC3Passthru);
diff --git a/macosx/HBChapter.h b/macosx/HBChapter.h
index bef15d599..070a0f53d 100644
--- a/macosx/HBChapter.h
+++ b/macosx/HBChapter.h
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithTitle:(NSString *)title index:(NSUInteger)idx duration:(uint64_t)duration NS_DESIGNATED_INITIALIZER;
-@property (nonatomic, readwrite) NSString *title;
+@property (nonatomic, readwrite, copy) NSString *title;
@property (nonatomic, readonly) NSString *duration;
@property (nonatomic, readonly) NSUInteger index;
diff --git a/macosx/HBCodingUtilities.h b/macosx/HBCodingUtilities.h
index c8eb3763e..de50bfaf7 100644
--- a/macosx/HBCodingUtilities.h
+++ b/macosx/HBCodingUtilities.h
@@ -19,6 +19,8 @@
#define decodeDouble(x) x = [decoder decodeDoubleForKey:OBJC_STRINGIFY(x)]
#define decodeObject(x, cl) x = [HBCodingUtilities decodeObjectOfClass:[cl class] forKey:OBJC_STRINGIFY(x) decoder:decoder];
+#define decodeCollectionOfObjects(x, cl, objectcl) x = [HBCodingUtilities decodeObjectOfClasses:[NSSet setWithObjects:[cl class], [objectcl class], nil] forKey:OBJC_STRINGIFY(x) decoder:decoder];
+
#define decodeObjectOrFail(x, class) x = [HBCodingUtilities decodeObjectOfClass:class forKey:OBJC_STRINGIFY(x) decoder:decoder]; if (x == nil) {NSLog(@"Failed to decode: %@", OBJC_STRINGIFY(x)); goto fail;}
NS_ASSUME_NONNULL_BEGIN
@@ -41,6 +43,9 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (nullable id)decodeObjectOfClass:(Class)aClass forKey:(NSString *)key decoder:(NSCoder *)decoder;
+
++ (nullable id)decodeObjectOfClasses:(NSSet *)classes forKey:(NSString *)key decoder:(NSCoder *)decoder;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/macosx/HBCodingUtilities.m b/macosx/HBCodingUtilities.m
index a87ad3f7a..80e245a7b 100644
--- a/macosx/HBCodingUtilities.m
+++ b/macosx/HBCodingUtilities.m
@@ -42,4 +42,17 @@ static BOOL useSecureCoding;
}
}
++ (id)decodeObjectOfClasses:(NSSet *)classes forKey:(NSString *)key decoder:(NSCoder *)decoder
+{
+ if (useSecureCoding)
+ {
+ return [decoder decodeObjectOfClasses:classes forKey:key];
+ }
+ else
+ {
+ id obj = [decoder decodeObjectForKey:key];
+ return obj;
+ }
+}
+
@end
diff --git a/macosx/HBDistributedArray.h b/macosx/HBDistributedArray.h
index dee8bfc12..b410da472 100644
--- a/macosx/HBDistributedArray.h
+++ b/macosx/HBDistributedArray.h
@@ -35,7 +35,7 @@ typedef NS_ENUM(NSUInteger, HBDistributedArrayContent) {
*/
@interface HBDistributedArray<ObjectType> : NSMutableArray
-- (instancetype)initWithURL:(NSURL *)fileURL;
+- (instancetype)initWithURL:(NSURL *)fileURL class:(Class)objectClass;
/**
* Begins a transaction on the array
diff --git a/macosx/HBDistributedArray.m b/macosx/HBDistributedArray.m
index d5cb38976..432e5cd29 100644
--- a/macosx/HBDistributedArray.m
+++ b/macosx/HBDistributedArray.m
@@ -59,6 +59,8 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
@property (nonatomic, readonly) NSURL *fileURL;
@property (nonatomic, readwrite) NSTimeInterval modifiedTime;
+@property (nonatomic, readonly) NSSet *objectClasses;
+
@property (nonatomic, readonly) sem_t *mutex;
@property (nonatomic, readwrite) uint32_t mutexCount;
@@ -66,13 +68,14 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
@implementation HBDistributedArray
-- (instancetype)initWithURL:(NSURL *)fileURL
+- (instancetype)initWithURL:(NSURL *)fileURL class:(Class)objectClass
{
self = [super init];
if (self)
{
_fileURL = [fileURL copy];
_array = [[NSMutableArray alloc] init];
+ _objectClasses = [NSSet setWithObjects:[NSMutableArray class], objectClass, nil];
NSArray *runningInstances = [NSRunningApplication runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
const char *name = [NSString stringWithFormat:@"/%@.hblock", _fileURL.lastPathComponent].UTF8String;
@@ -196,7 +199,14 @@ NSString *HBDistributedArraWrittenToDisk = @"HBDistributedArraWrittenToDisk";
NSMutableArray *jobsArray = nil;
@try
{
- jobsArray = [NSKeyedUnarchiver unarchiveObjectWithFile:self.fileURL.path];
+ NSData *queue = [NSData dataWithContentsOfURL:self.fileURL];
+ NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:queue];
+ if ([unarchiver respondsToSelector:@selector(requiresSecureCoding)])
+ {
+ unarchiver.requiresSecureCoding = YES;
+ }
+ jobsArray = [unarchiver decodeObjectOfClasses:self.objectClasses forKey:NSKeyedArchiveRootObjectKey];
+ [unarchiver finishDecoding];
}
@catch (NSException *exception)
{
diff --git a/macosx/HBJob.m b/macosx/HBJob.m
index e3d608a9a..2adee6bbb 100644
--- a/macosx/HBJob.m
+++ b/macosx/HBJob.m
@@ -242,7 +242,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
- (void)encodeWithCoder:(NSCoder *)coder
{
- [coder encodeInt:1 forKey:@"HBJobVersion"];
+ [coder encodeInt:2 forKey:@"HBJobVersion"];
encodeInt(_state);
encodeObject(_name);
@@ -274,7 +274,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
{
int version = [decoder decodeIntForKey:@"HBJobVersion"];
- if (version == 1 && (self = [super init]))
+ if (version == 2 && (self = [super init]))
{
decodeInt(_state);
decodeObject(_name, NSString);
@@ -304,7 +304,7 @@ NSString *HBChaptersChangedNotification = @"HBChaptersChangedNotification";
_video.job = self;
decodeBool(_chaptersEnabled);
- decodeObject(_chapterTitles, NSArray);
+ decodeCollectionOfObjects(_chapterTitles, NSArray, HBChapter);
return self;
}
diff --git a/macosx/HBPictureHUDController.h b/macosx/HBPictureHUDController.h
index 1a11d2063..b127347e8 100644
--- a/macosx/HBPictureHUDController.h
+++ b/macosx/HBPictureHUDController.h
@@ -8,6 +8,8 @@
#import <Cocoa/Cocoa.h>
#import "HBHUD.h"
+NS_ASSUME_NONNULL_BEGIN
+
@protocol HBPictureHUDControllerDelegate <NSObject>
- (void)displayPreviewAtIndex:(NSUInteger)idx;
@@ -21,10 +23,12 @@
@property (nonatomic, nullable, assign) id<HBPictureHUDControllerDelegate> delegate;
-@property (nonatomic, nonnull) NSString *info;
-@property (nonatomic, nonnull) NSString *scale;
+@property (nonatomic, copy) NSString *info;
+@property (nonatomic, copy) NSString *scale;
@property (nonatomic) NSUInteger pictureCount;
@property (nonatomic) NSUInteger selectedIndex;
@end
+
+NS_ASSUME_NONNULL_END
diff --git a/macosx/HBQueueController.m b/macosx/HBQueueController.m
index 318233714..8dfef4e26 100644
--- a/macosx/HBQueueController.m
+++ b/macosx/HBQueueController.m
@@ -72,7 +72,7 @@
_core = [[HBCore alloc] initWithLogLevel:loggingLevel name:@"QueueCore"];
// Load the queue from disk.
- _jobs = [[HBDistributedArray alloc] initWithURL:queueURL];
+ _jobs = [[HBDistributedArray alloc] initWithURL:queueURL class:[HBJob class]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadQueue) name:HBDistributedArrayChanged object:_jobs];
}
diff --git a/macosx/HBSubtitles.m b/macosx/HBSubtitles.m
index 549d06647..f1a31174b 100644
--- a/macosx/HBSubtitles.m
+++ b/macosx/HBSubtitles.m
@@ -83,7 +83,7 @@ extern NSString *keySubTrackSrtFileURL;
NSDictionary *none = @{ keySubTrackName: NSLocalizedString(@"None", nil)};
[sourceTracks insertObject:none atIndex:0];
- NSDictionary *foreign = @{ keySubTrackName: foreignAudioSearchTrackName,
+ NSDictionary *foreign = @{ keySubTrackName: [foreignAudioSearchTrackName copy],
keySubTrackType: @(foreignAudioType) };
[sourceTracks insertObject:foreign atIndex:1];
@@ -446,8 +446,8 @@ extern NSString *keySubTrackSrtFileURL;
self = [super init];
decodeInt(_container);
- decodeObject(_sourceTracks, NSMutableArray);
- decodeObject(_tracks, NSMutableArray);
+ decodeCollectionOfObjects(_sourceTracks, NSArray, NSDictionary);
+ decodeCollectionOfObjects(_tracks, NSMutableArray, HBSubtitlesTrack);
for (HBSubtitlesTrack *track in _tracks)
{
diff --git a/macosx/HBTitle.m b/macosx/HBTitle.m
index 66d76efd3..cfe511157 100644
--- a/macosx/HBTitle.m
+++ b/macosx/HBTitle.m
@@ -29,7 +29,7 @@ extern NSString *keySubTrackType;
@property (nonatomic, readonly) hb_title_t *hb_title;
@property (nonatomic, readonly) hb_handle_t *hb_handle;
-@property (nonatomic, readwrite, strong) NSString *name;
+@property (nonatomic, readwrite, copy) NSString *name;
@property (nonatomic, readwrite) NSArray *audioTracks;
@property (nonatomic, readwrite) NSArray *subtitlesTracks;
diff --git a/macosx/HBVideo.m b/macosx/HBVideo.m
index 6dfc16325..26a45c239 100644
--- a/macosx/HBVideo.m
+++ b/macosx/HBVideo.m
@@ -552,7 +552,7 @@ NSString * const HBVideoChangedNotification = @"HBVideoChangedNotification";
[string appendString:@"fastdecode"];
}
- return string;
+ return [string copy];
}
- (void)applyPreset:(HBPreset *)preset jobSettings:(NSDictionary *)settings