From 562e6f99f1a46e85408078f19e292a78bd6f24df Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 6 Jul 2022 17:59:34 +0800 Subject: [PATCH] AppInstaller // Introducing readonlyAccessCheckGPR(). - This is a new way to detect whether the app bundle is translocated by GateKeeper. --- Installer/AppDelegate.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Installer/AppDelegate.swift b/Installer/AppDelegate.swift index b4f084d1..efcae665 100644 --- a/Installer/AppDelegate.swift +++ b/Installer/AppDelegate.swift @@ -144,7 +144,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { if elapsed >= kTranslocationRemovalDeadline { timer.invalidate() window?.endSheet(progressSheet, returnCode: .cancel) - } else if appBundleChronoshiftedToARandomizedPath(kTargetPartialPath) == false { + } else if readonlyAccessCheckGPR(kTargetPartialPath) == false { progressIndicator.doubleValue = 1.0 timer.invalidate() window?.endSheet(progressSheet, returnCode: .continue) @@ -163,7 +163,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { } let shouldWaitForTranslocationRemoval = - appBundleChronoshiftedToARandomizedPath(kTargetPartialPath) + readonlyAccessCheckGPR(kTargetPartialPath) && (window?.responds(to: #selector(NSWindow.beginSheet(_:completionHandler:))) ?? false) // 將既存輸入法扔到垃圾桶內 @@ -358,4 +358,11 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { func windowWillClose(_: Notification) { NSApp.terminate(self) } + + // Determines if an app is translocated by Gatekeeper to a randomized path + // See https://weblog.rogueamoeba.com/2016/06/29/sierra-and-gatekeeper-path-randomization/ + // Theoretically, if the path is a randomized path then it cannot be writable to FileManager. + func readonlyAccessCheckGPR(_ bundle: String) -> Bool { + !FileManager.default.isWritableFile(atPath: (bundle as NSString).expandingTildeInPath) + } }