From b89462016f2550e0ef93005fcadc0c325adc9393 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 23 Nov 2022 19:26:06 -0600 Subject: [PATCH] Fixes refreshing tweaked apps with removed app extensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In addition to removing the app extensions themselves, we also need to remove references to them from SC_Info/Manifest.plist in the app bundle (if the file exists). Otherwise, subsequent installations (resigning, (de)-activating, etc.) will fail due to “missing” app extensions. --- AltStore/My Apps/MyAppsViewController.swift | 34 +++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index 162909a9..eed02b79 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -1021,6 +1021,25 @@ private extension MyAppsViewController { guard !application.appExtensions.isEmpty else { return completion(.success(())) } + func removeAppExtensions() throws + { + for appExtension in application.appExtensions + { + try FileManager.default.removeItem(at: appExtension.fileURL) + } + + let scInfoURL = application.fileURL.appendingPathComponent("SC_Info") + let manifestPlistURL = scInfoURL.appendingPathComponent("Manifest.plist") + + if let manifestPlist = NSMutableDictionary(contentsOf: manifestPlistURL), + let sinfReplicationPaths = manifestPlist["SinfReplicationPaths"] as? [String] + { + let replacementPaths = sinfReplicationPaths.filter { !$0.starts(with: "PlugIns/") } // Filter out app extension paths. + manifestPlist["SinfReplicationPaths"] = replacementPaths + try manifestPlist.write(to: manifestPlistURL) + } + } + let firstSentence: String if UserDefaults.standard.activeAppLimitIncludesExtensions @@ -1042,19 +1061,8 @@ private extension MyAppsViewController completion(.success(())) }) alertController.addAction(UIAlertAction(title: NSLocalizedString("Remove App Extensions", comment: ""), style: .destructive) { (action) in - do - { - for appExtension in application.appExtensions - { - try FileManager.default.removeItem(at: appExtension.fileURL) - } - - completion(.success(())) - } - catch - { - completion(.failure(error)) - } + let result = Result { try removeAppExtensions() } + completion(result) }) self.present(alertController, animated: true, completion: nil)