Skip to content

Commit

Permalink
Address deprecations with NSKeyedUnarchiver
Browse files Browse the repository at this point in the history
  • Loading branch information
Coeur committed Apr 23, 2022
1 parent 4f70baa commit fa1da2b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
10 changes: 9 additions & 1 deletion macosx/Controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3563,7 +3563,15 @@ - (BOOL)outlineView:(NSOutlineView*)outlineView acceptDrop:(id<NSDraggingInfo>)i
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];
Expand Down
11 changes: 9 additions & 2 deletions macosx/GroupsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ - (instancetype)init
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
{
_fGroups = [NSUnarchiver unarchiveObjectWithData:data];
[NSUserDefaults.standardUserDefaults removeObjectForKey:@"Groups"];
[self saveGroups];
}
else
if (_fGroups == nil)
{
//default groups
NSMutableDictionary* red = [NSMutableDictionary
Expand Down
10 changes: 9 additions & 1 deletion macosx/GroupsPrefsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ - (BOOL)tableView:(NSTableView*)tableView
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)
Expand Down
18 changes: 14 additions & 4 deletions macosx/TorrentTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,22 @@ - (instancetype)initWithCoder:(NSCoder*)decoder

_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];
}
Expand Down Expand Up @@ -139,7 +149,7 @@ - (void)removeAllCollapsedGroups

- (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
Expand Down

0 comments on commit fa1da2b

Please sign in to comment.