Address deprecations with NSKeyedUnarchiver (#2973)

This commit is contained in:
Antoine Cœur
2022-04-30 05:44:59 +08:00
committed by GitHub
parent a4b1c2cadc
commit aafedcaae1
4 changed files with 53 additions and 8 deletions

View File

@@ -3566,7 +3566,16 @@ static void removeKeRangerRansomware()
NSPasteboard* pasteboard = info.draggingPasteboard;
if ([pasteboard.types containsObject:TORRENT_TABLE_VIEW_DATA_TYPE])
{
NSIndexSet* indexes = [NSKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:TORRENT_TABLE_VIEW_DATA_TYPE]];
NSIndexSet* indexes;
if (@available(macOS 10.13, *))
{
indexes = [NSKeyedUnarchiver unarchivedObjectOfClass:NSIndexSet.class fromData:[pasteboard dataForType:TORRENT_TABLE_VIEW_DATA_TYPE]
error:nil];
}
else
{
indexes = [NSKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:TORRENT_TABLE_VIEW_DATA_TYPE]];
}
//get the torrents to move
NSMutableArray* movingTorrents = [NSMutableArray arrayWithCapacity:indexes.count];

View File

@@ -40,7 +40,21 @@ GroupsController* fGroupsInstance = nil;
NSData* data;
if ((data = [NSUserDefaults.standardUserDefaults dataForKey:@"GroupDicts"]))
{
_fGroups = [NSKeyedUnarchiver unarchiveObjectWithData:data];
if (@available(macOS 10.13, *))
{
_fGroups = [NSKeyedUnarchiver unarchivedObjectOfClasses:[NSSet setWithObjects:NSMutableArray.class,
NSMutableDictionary.class,
NSNumber.class,
NSColor.class,
NSString.class,
nil]
fromData:data
error:nil];
}
else
{
_fGroups = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
}
else if ((data = [NSUserDefaults.standardUserDefaults dataForKey:@"Groups"])) //handle old groups
{
@@ -48,7 +62,7 @@ GroupsController* fGroupsInstance = nil;
[NSUserDefaults.standardUserDefaults removeObjectForKey:@"Groups"];
[self saveGroups];
}
else
if (_fGroups == nil)
{
//default groups
NSMutableDictionary* red = [NSMutableDictionary

View File

@@ -122,7 +122,16 @@
NSPasteboard* pasteboard = info.draggingPasteboard;
if ([pasteboard.types containsObject:GROUP_TABLE_VIEW_DATA_TYPE])
{
NSIndexSet* indexes = [NSKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:GROUP_TABLE_VIEW_DATA_TYPE]];
NSIndexSet* indexes;
if (@available(macOS 10.13, *))
{
indexes = [NSKeyedUnarchiver unarchivedObjectOfClass:NSIndexSet.class fromData:[pasteboard dataForType:GROUP_TABLE_VIEW_DATA_TYPE]
error:nil];
}
else
{
indexes = [NSKeyedUnarchiver unarchiveObjectWithData:[pasteboard dataForType:GROUP_TABLE_VIEW_DATA_TYPE]];
}
NSInteger oldRow = indexes.firstIndex;
if (oldRow < newRow)

View File

@@ -71,12 +71,25 @@
_fTorrentCell = [[TorrentCell alloc] init];
NSData* groupData = [_fDefaults dataForKey:@"CollapsedGroups"];
if (groupData)
NSData* groupData;
if ((groupData = [_fDefaults dataForKey:@"CollapsedGroupIndexes"]))
{
if (@available(macOS 10.13, *))
{
_fCollapsedGroups = [NSKeyedUnarchiver unarchivedObjectOfClass:NSMutableIndexSet.class fromData:groupData error:nil];
}
else
{
_fCollapsedGroups = [NSKeyedUnarchiver unarchiveObjectWithData:groupData];
}
}
else if ((groupData = [_fDefaults dataForKey:@"CollapsedGroups"])) //handle old groups
{
_fCollapsedGroups = [[NSUnarchiver unarchiveObjectWithData:groupData] mutableCopy];
[_fDefaults removeObjectForKey:@"CollapsedGroups"];
[self saveCollapsedGroups];
}
else
if (_fCollapsedGroups == nil)
{
_fCollapsedGroups = [[NSMutableIndexSet alloc] init];
}
@@ -141,7 +154,7 @@
- (void)saveCollapsedGroups
{
[self.fDefaults setObject:[NSArchiver archivedDataWithRootObject:self.fCollapsedGroups] forKey:@"CollapsedGroups"];
[self.fDefaults setObject:[NSKeyedArchiver archivedDataWithRootObject:self.fCollapsedGroups] forKey:@"CollapsedGroupIndexes"];
}
- (BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item