Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address deprecations with NSKeyedUnarchiver #2973

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion macosx/Controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3566,7 +3566,16 @@ - (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
18 changes: 16 additions & 2 deletions macosx/GroupsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,29 @@ - (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
11 changes: 10 additions & 1 deletion macosx/GroupsPrefsController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,16 @@ - (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
21 changes: 17 additions & 4 deletions macosx/TorrentTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,25 @@ - (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 @@ -141,7 +154,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