From 6aaeda6caf34c2aed4f98bf0c65b090346580639 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 11 Oct 2022 11:25:00 +0800 Subject: [PATCH] AppInstaller // Deprecating ArchiveUtil. - vChewing handles the notarized app-style installer differently. --- Installer/AppDelegate.swift | 6 +- Installer/ArchiveUtil.swift | 119 -------------------------- Installer/NotarizedArchives/README.md | 1 - vChewing.xcodeproj/project.pbxproj | 8 -- 4 files changed, 1 insertion(+), 133 deletions(-) delete mode 100644 Installer/ArchiveUtil.swift delete mode 100644 Installer/NotarizedArchives/README.md diff --git a/Installer/AppDelegate.swift b/Installer/AppDelegate.swift index 9858caaf..e18516fd 100644 --- a/Installer/AppDelegate.swift +++ b/Installer/AppDelegate.swift @@ -43,7 +43,6 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { @IBOutlet private var appCopyrightLabel: NSTextField! @IBOutlet private var appEULAContent: NSTextView! - private var archiveUtil: ArchiveUtil? private var installingVersion = "" private var upgrading = false private var translocationRemovalStartTime: Date? @@ -79,8 +78,6 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { return } self.installingVersion = installingVersion - archiveUtil = ArchiveUtil(appName: kTargetBin, targetAppBundleName: kTargetBundle) - _ = archiveUtil?.validateIfNotarizedArchiveExists() cancelButton.nextKeyView = installButton installButton.nextKeyView = cancelButton @@ -221,8 +218,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { previousExists _: Bool, previousVersionNotFullyDeactivatedWarning warning: Bool ) { guard - let targetBundle = archiveUtil?.unzipNotarizedArchive() - ?? Bundle.main.path(forResource: kTargetBin, ofType: kTargetType) + let targetBundle = Bundle.main.path(forResource: kTargetBin, ofType: kTargetType) else { return } diff --git a/Installer/ArchiveUtil.swift b/Installer/ArchiveUtil.swift deleted file mode 100644 index 1371049b..00000000 --- a/Installer/ArchiveUtil.swift +++ /dev/null @@ -1,119 +0,0 @@ -// (c) 2011 and onwards The OpenVanilla Project (MIT License). -// All possible vChewing-specific modifications are of: -// (c) 2021 and onwards The vChewing Project (MIT-NTL License). -// ==================== -// This code is released under the MIT license (SPDX-License-Identifier: MIT) -// ... with NTL restriction stating that: -// No trademark license is granted to use the trade names, trademarks, service -// marks, or product names of Contributor, except as required to fulfill notice -// requirements defined in MIT License. - -import Cocoa - -struct ArchiveUtil { - var appName: String - var targetAppBundleName: String - - init(appName: String, targetAppBundleName: String) { - self.appName = appName - self.targetAppBundleName = targetAppBundleName - } - - // Returns YES if (1) a zip file under - // Resources/NotarizedArchives/$_appName-$bundleVersion.zip exists, and (2) if - // Resources/$_invalidAppBundleName does not exist. - func validateIfNotarizedArchiveExists() -> Bool { - guard let resourePath = Bundle.main.resourcePath, - let notarizedArchivesPath = notarizedArchivesPath, - let notarizedArchive = notarizedArchive, - let notarizedArchivesContent: [String] = try? FileManager.default.subpathsOfDirectory( - atPath: notarizedArchivesPath) - else { - return false - } - - let devModeAppBundlePath = (resourePath as NSString).appendingPathComponent(targetAppBundleName) - let count = notarizedArchivesContent.count - let notarizedArchiveExists = FileManager.default.fileExists(atPath: notarizedArchive) - let devModeAppBundleExists = FileManager.default.fileExists(atPath: devModeAppBundlePath) - - if !notarizedArchivesContent.isEmpty { - // 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。 - if count != 1 || !notarizedArchiveExists || devModeAppBundleExists { - let alert = NSAlert() - alert.alertStyle = .informational - alert.messageText = "Internal Error" - alert.informativeText = - "devMode installer, expected archive name: \(notarizedArchive), " - + "archive exists: \(notarizedArchiveExists), devMode app bundle exists: \(devModeAppBundleExists)" - alert.addButton(withTitle: "Terminate") - alert.runModal() - NSApp.terminate(nil) - } else { - return true - } - } - - if !devModeAppBundleExists { - let alert = NSAlert() - alert.alertStyle = .informational - alert.messageText = "Internal Error" - alert.informativeText = "Dev target bundle does not exist: \(devModeAppBundlePath)" - alert.addButton(withTitle: "Terminate") - alert.runModal() - NSApp.terminate(nil) - } - - return false - } - - func unzipNotarizedArchive() -> String? { - if !validateIfNotarizedArchiveExists() { - return nil - } - guard let notarizedArchive = notarizedArchive, - let resourcePath = Bundle.main.resourcePath - else { - return nil - } - let tempFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent( - UUID().uuidString) - let arguments: [String] = [notarizedArchive, "-d", tempFilePath] - let unzipTask = Process() - unzipTask.launchPath = "/usr/bin/unzip" - unzipTask.currentDirectoryPath = resourcePath - unzipTask.arguments = arguments - unzipTask.launch() - unzipTask.waitUntilExit() - - assert(unzipTask.terminationStatus == 0, "Must successfully unzipped") - let result = (tempFilePath as NSString).appendingPathComponent(targetAppBundleName) - assert( - FileManager.default.fileExists(atPath: result), - "App bundle must be unzipped at \(result)." - ) - return result - } - - private var notarizedArchivesPath: String? { - guard let resourePath = Bundle.main.resourcePath else { - return nil - } - let notarizedArchivesPath = (resourePath as NSString).appendingPathComponent( - "NotarizedArchives") - return notarizedArchivesPath - } - - private var notarizedArchive: String? { - guard let notarizedArchivesPath = notarizedArchivesPath, - let bundleVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] - as? String - else { - return nil - } - let notarizedArchiveBasename = "\(appName)-r\(bundleVersion).zip" - let notarizedArchive = (notarizedArchivesPath as NSString).appendingPathComponent( - notarizedArchiveBasename) - return notarizedArchive - } -} diff --git a/Installer/NotarizedArchives/README.md b/Installer/NotarizedArchives/README.md deleted file mode 100644 index a2f530c8..00000000 --- a/Installer/NotarizedArchives/README.md +++ /dev/null @@ -1 +0,0 @@ -Place the notarized archive here for producing the release installer. diff --git a/vChewing.xcodeproj/project.pbxproj b/vChewing.xcodeproj/project.pbxproj index 1843981b..7eca0098 100644 --- a/vChewing.xcodeproj/project.pbxproj +++ b/vChewing.xcodeproj/project.pbxproj @@ -101,7 +101,6 @@ 5BFC63D128D4B9F7004A77B7 /* IMKUtils in Frameworks */ = {isa = PBXBuildFile; productRef = 5BFC63D028D4B9F7004A77B7 /* IMKUtils */; }; 5BFDF011289635C100417BBC /* IMKCandidatesImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFDF010289635C100417BBC /* IMKCandidatesImpl.swift */; }; 6A187E2616004C5900466B2E /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6A187E2816004C5900466B2E /* MainMenu.xib */; }; - 6A225A1F23679F2600F685C6 /* NotarizedArchives in Resources */ = {isa = PBXBuildFile; fileRef = 6A225A1E23679F2600F685C6 /* NotarizedArchives */; }; 6A2E40F6253A69DA00D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; }; 6A2E40F9253A6AA000D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; }; 6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */; }; @@ -114,7 +113,6 @@ D4A13D5A27A59F0B003BE359 /* SessionCtl_Core.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4A13D5927A59D5C003BE359 /* SessionCtl_Core.swift */; }; D4E33D8A27A838CF006DB1CF /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8827A838CF006DB1CF /* Localizable.strings */; }; D4E33D8F27A838F0006DB1CF /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D4E33D8D27A838F0006DB1CF /* InfoPlist.strings */; }; - D4F0BBDF279AF1AF0071253C /* ArchiveUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F0BBDE279AF1AF0071253C /* ArchiveUtil.swift */; }; D4F0BBE1279AF8B30071253C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4F0BBE0279AF8B30071253C /* AppDelegate.swift */; }; /* End PBXBuildFile section */ @@ -307,7 +305,6 @@ 6A0D4EF515FC0DA600ABF4B3 /* IME-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "IME-Info.plist"; sourceTree = ""; }; 6A15B32421A51F2300B92CD3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 6A15B32521A51F2300B92CD3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; - 6A225A1E23679F2600F685C6 /* NotarizedArchives */ = {isa = PBXFileReference; lastKnownFileType = folder; path = NotarizedArchives; sourceTree = ""; }; 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 6ACA41CB15FC1D7500935EF6 /* vChewingInstaller.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = vChewingInstaller.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6ACA41EB15FC1D9000935EF6 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -319,7 +316,6 @@ D4A13D5927A59D5C003BE359 /* SessionCtl_Core.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = SessionCtl_Core.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; D4E33D8927A838CF006DB1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = ""; }; D4E33D8E27A838F0006DB1CF /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = ""; }; - D4F0BBDE279AF1AF0071253C /* ArchiveUtil.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = ArchiveUtil.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; D4F0BBE0279AF8B30071253C /* AppDelegate.swift */ = {isa = PBXFileReference; explicitFileType = sourcecode.swift; fileEncoding = 4; indentWidth = 2; lineEnding = 0; path = AppDelegate.swift; sourceTree = ""; tabWidth = 2; usesTabs = 0; }; /* End PBXFileReference section */ @@ -693,10 +689,8 @@ isa = PBXGroup; children = ( 5B44B97C28D2F283004508BF /* PKGRoot */, - 6A225A1E23679F2600F685C6 /* NotarizedArchives */, 5BBBB77827AEDB330023B93A /* Resources */, D4F0BBE0279AF8B30071253C /* AppDelegate.swift */, - D4F0BBDE279AF1AF0071253C /* ArchiveUtil.swift */, 6ACA41F215FC1D9000935EF6 /* Installer-Info.plist */, 5BC0AACA27F58472002D33E9 /* pkgPostInstall.sh */, 5BC0AAC927F58472002D33E9 /* pkgPreInstall.sh */, @@ -938,7 +932,6 @@ 6ACA420215FC1E5200935EF6 /* vChewing.app in Resources */, 6A2E40F9253A6AA000D1AE1D /* Images.xcassets in Resources */, 6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */, - 6A225A1F23679F2600F685C6 /* NotarizedArchives in Resources */, 6ACA41FC15FC1D9000935EF6 /* Localizable.strings in Resources */, 6ACA41FD15FC1D9000935EF6 /* MainMenu.xib in Resources */, ); @@ -1093,7 +1086,6 @@ buildActionMask = 2147483647; files = ( D4F0BBE1279AF8B30071253C /* AppDelegate.swift in Sources */, - D4F0BBDF279AF1AF0071253C /* ArchiveUtil.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };