Skip to content

Commit

Permalink
MacGui: replace some deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
galad87 committed Jul 6, 2024
1 parent b15a89b commit 01b8fbe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
6 changes: 4 additions & 2 deletions macosx/HBPreferencesController.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ + (void)registerUserDefaults
HBPreferencesController.hardwareDecoderSupported = NO;
}

NSData *moviesData = [NSKeyedArchiver archivedDataWithRootObject:moviesURL requiringSecureCoding:YES error:NULL];

[defaults registerDefaults:@{
HBShowOpenPanelAtLaunch: @YES,
HBShowSummaryPreview: @YES,
Expand All @@ -205,8 +207,8 @@ + (void)registerUserDefaults
HBAlwaysUseHardwareDecoder: @NO,
HBRecursiveScan: @NO,
HBExcludedFileExtensions: @[@"jpg", @"png", @"srt", @"ssa", @"ass", @"txt"],
HBLastDestinationDirectoryURL: [NSKeyedArchiver archivedDataWithRootObject:moviesURL],
HBLastSourceDirectoryURL: [NSKeyedArchiver archivedDataWithRootObject:moviesURL],
HBLastDestinationDirectoryURL: moviesData,
HBLastSourceDirectoryURL: moviesData,
HBUseSourceFolderDestination: @NO,
HBDefaultAutoNaming: @NO,
HBAutoNamingFormat: @[@"{Source}", @" ", @"{Title}"],
Expand Down
35 changes: 20 additions & 15 deletions macosx/HBQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,30 +188,35 @@ - (void)dealloc
- (NSMutableArray *)load
{
NSError *error;
NSArray *loadedItems = nil;

NSData *queue = [NSData dataWithContentsOfURL:self.fileURL];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:queue];
unarchiver.requiresSecureCoding = YES;

NSSet *objectClasses = [NSSet setWithObjects:[NSMutableArray class], [HBQueueJobItem class], [HBQueueActionStopItem class], nil];

NSArray *loadedItems = [unarchiver decodeTopLevelObjectOfClasses:objectClasses
forKey:NSKeyedArchiveRootObjectKey
error:&error];

if (error)
NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
if (data)
{
[HBUtilities writeErrorToActivityLog:error];
}
NSSet *objectClasses = [NSSet setWithObjects:[NSMutableArray class], [HBQueueJobItem class], [HBQueueActionStopItem class], nil];
loadedItems = [NSKeyedUnarchiver unarchivedObjectOfClasses:objectClasses fromData:data error:&error];

[unarchiver finishDecoding];
if (loadedItems == nil && error)
{
[HBUtilities writeErrorToActivityLog:error];
}
}

return loadedItems ? [loadedItems mutableCopy] : [NSMutableArray array];
}

- (void)save
{
if (![NSKeyedArchiver archiveRootObject:self.itemsInternal toFile:self.fileURL.path])
NSError *error = nil;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.itemsInternal requiringSecureCoding:YES error:&error];
if (data == nil)
{
[HBUtilities writeToActivityLog:"Failed to archive the queue"];
return;
}

BOOL result = [data writeToURL:self.fileURL atomically:YES];
if (result == NO)
{
[HBUtilities writeToActivityLog:"Failed to write the queue to disk"];
}
Expand Down

0 comments on commit 01b8fbe

Please sign in to comment.