2023-10-25 16:01:34 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Shelley Vohr <shelley.vohr@gmail.com>
|
|
|
|
Date: Thu, 22 Jun 2023 12:26:24 +0200
|
|
|
|
Subject: refactor: use non-deprecated NSKeyedArchiver APIs
|
|
|
|
|
|
|
|
Refs https://chromium-review.googlesource.com/c/chromium/src/+/4628901
|
|
|
|
|
|
|
|
Several NSKeyedArchiver methods have been deprecated and replaced as of macOS 10.13:
|
|
|
|
|
|
|
|
- unarchiveObjectWithData -> unarchivedObjectOfClass:fromData:error:
|
|
|
|
- archivedDataWithRootObject -> archivedDataWithRootObject:requiringSecureCoding:error:
|
|
|
|
|
|
|
|
diff --git a/Squirrel/SQRLInstaller.m b/Squirrel/SQRLInstaller.m
|
2024-02-14 03:08:03 +00:00
|
|
|
index f502df2f88424ea902a061adfeb30358daf212e4..40f55812bf5795dc60bb8a4cd19c62cb37f40359 100644
|
2023-10-25 16:01:34 +00:00
|
|
|
--- a/Squirrel/SQRLInstaller.m
|
|
|
|
+++ b/Squirrel/SQRLInstaller.m
|
2024-02-14 03:08:03 +00:00
|
|
|
@@ -182,14 +182,40 @@ - (SQRLInstallerOwnedBundle *)ownedBundle {
|
2023-10-25 16:01:34 +00:00
|
|
|
id archiveData = CFBridgingRelease(CFPreferencesCopyValue((__bridge CFStringRef)SQRLInstallerOwnedBundleKey, (__bridge CFStringRef)self.applicationIdentifier, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost));
|
|
|
|
if (![archiveData isKindOfClass:NSData.class]) return nil;
|
|
|
|
|
|
|
|
- SQRLInstallerOwnedBundle *ownedBundle = [NSKeyedUnarchiver unarchiveObjectWithData:archiveData];
|
|
|
|
- if (![ownedBundle isKindOfClass:SQRLInstallerOwnedBundle.class]) return nil;
|
2024-02-14 03:08:03 +00:00
|
|
|
+ // unarchivedObjectOfClass:fromData:error: sets secureCoding to true and we don't
|
|
|
|
+ // archive data with secureCoding enabled - use our own unarchiver to work around that.
|
2023-10-25 16:01:34 +00:00
|
|
|
+ NSError *error;
|
2024-02-14 03:08:03 +00:00
|
|
|
+ NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:archiveData
|
|
|
|
+ error:&error];
|
|
|
|
+ unarchiver.requiresSecureCoding = NO;
|
|
|
|
+ SQRLInstallerOwnedBundle *ownedBundle = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
|
|
|
|
+ [unarchiver finishDecoding];
|
|
|
|
+
|
2023-10-25 16:01:34 +00:00
|
|
|
+ if (error) {
|
2024-02-14 03:08:03 +00:00
|
|
|
+ NSLog(@"Error while unarchiving ownedBundle - %@", error.localizedDescription);
|
2023-10-25 16:01:34 +00:00
|
|
|
+ return nil;
|
|
|
|
+ }
|
2024-02-14 03:08:03 +00:00
|
|
|
+
|
|
|
|
+ if (!ownedBundle || ![ownedBundle isKindOfClass:SQRLInstallerOwnedBundle.class]) {
|
|
|
|
+ NSLog(@"Unknown error while unarchiving ownedBundle - did not conform to SQRLInstallerOwnedBundle");
|
|
|
|
+ return nil;
|
|
|
|
+ }
|
2023-10-25 16:01:34 +00:00
|
|
|
|
|
|
|
return ownedBundle;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setOwnedBundle:(SQRLInstallerOwnedBundle *)ownedBundle {
|
|
|
|
- NSData *archiveData = (ownedBundle == nil ? nil : [NSKeyedArchiver archivedDataWithRootObject:ownedBundle]);
|
|
|
|
+ NSData *archiveData = nil;
|
|
|
|
+ if (ownedBundle != nil) {
|
|
|
|
+ NSError *error;
|
|
|
|
+ archiveData = [NSKeyedArchiver archivedDataWithRootObject:ownedBundle
|
|
|
|
+ requiringSecureCoding:NO
|
|
|
|
+ error:&error];
|
|
|
|
+
|
|
|
|
+ if (error)
|
|
|
|
+ NSLog(@"Couldn't archive ownedBundle - %@", error.localizedDescription);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
CFPreferencesSetValue((__bridge CFStringRef)SQRLInstallerOwnedBundleKey, (__bridge CFPropertyListRef)archiveData, (__bridge CFStringRef)self.applicationIdentifier, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
|
|
|
CFPreferencesSynchronize((__bridge CFStringRef)self.applicationIdentifier, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
|
|
|
}
|