diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift index dda57dc6..3ce948c4 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift @@ -136,7 +136,7 @@ public extension AppDelegate { let url = URL(fileURLWithPath: LMMgr.dataFolderPath(isDefaultFolder: true)) FileOpenMethod.finder.open(url: url) Uninstaller.uninstall( - isSudo: false, selfKill: true, defaultDataFolderPath: LMMgr.dataFolderPath(isDefaultFolder: true) + selfKill: true, defaultDataFolderPath: LMMgr.dataFolderPath(isDefaultFolder: true) ) } diff --git a/Packages/vChewing_Uninstaller/Sources/Uninstaller/Uninstaller.swift b/Packages/vChewing_Uninstaller/Sources/Uninstaller/Uninstaller.swift index 4dfbfd9c..76066292 100644 --- a/Packages/vChewing_Uninstaller/Sources/Uninstaller/Uninstaller.swift +++ b/Packages/vChewing_Uninstaller/Sources/Uninstaller/Uninstaller.swift @@ -13,8 +13,11 @@ public enum Uninstaller { // MARK: - Uninstall the input method. @discardableResult public static func uninstall( - isSudo: Bool = false, selfKill: Bool = true, defaultDataFolderPath: String + selfKill: Bool = true, + defaultDataFolderPath: String, + removeAll: Bool = false ) -> Int32 { + let isSudo = NSApplication.isSudoMode let realHomeDir = URL( fileURLWithFileSystemRepresentation: getpwuid(getuid()).pointee.pw_dir, isDirectory: true, relativeTo: nil ) @@ -53,9 +56,7 @@ public enum Uninstaller { let objFullPath = pathLibrary + pathUnitKeyboardLayouts + objPath if !FileManager.trashTargetIfExists(objFullPath) { return -1 } } - if CommandLine.arguments.count > 2, CommandLine.arguments[2] == "--all", - CommandLine.arguments[1] == "uninstall" - { + if removeAll { // 再處理是否需要移除放在預設使用者資料夾內的檔案的情況。 // 如果使用者有在輸入法偏好設定內將該目錄改到別的地方(而不是用 symbol link)的話,則不處理。 // 目前暫時無法應對 symbol link 的情況。 diff --git a/Source/Modules/main.swift b/Source/Modules/main.swift index f30e2a61..c05cc061 100644 --- a/Source/Modules/main.swift +++ b/Source/Modules/main.swift @@ -12,10 +12,12 @@ import InputMethodKit import MainAssembly import Uninstaller -switch max(CommandLine.arguments.count - 1, 0) { +let cmdParameters = CommandLine.arguments.dropFirst(1) + +switch cmdParameters.count { case 0: break -case 1, 2: - switch CommandLine.arguments[1] { +case 1: + switch cmdParameters.first?.lowercased() { case "--dump-prefs": if let strDumpedPrefs = PrefMgr.shared.dumpShellScriptBackup() { print(strDumpedPrefs) @@ -26,12 +28,36 @@ case 1, 2: exit(exitCode) case "uninstall": let exitCode = Uninstaller.uninstall( - isSudo: NSApplication.isSudoMode, defaultDataFolderPath: LMMgr.dataFolderPath(isDefaultFolder: true) + defaultDataFolderPath: LMMgr.dataFolderPath(isDefaultFolder: true), + removeAll: false ) exit(exitCode) default: break } exit(0) +case 2: + switch cmdParameters.first?.lowercased() { + case "uninstall" where cmdParameters.last?.lowercased() == "--all": + let exitCode = Uninstaller.uninstall( + defaultDataFolderPath: LMMgr.dataFolderPath(isDefaultFolder: true), + removeAll: true + ) + exit(exitCode) + case "--import-kimo": + guard let path = cmdParameters.last else { + exit(1) + } + let url = URL(fileURLWithPath: path) + guard var rawString = try? String(contentsOf: url) else { + print("[Kimo Import] Given file path is either invalid or not accessible. Read access is needed for this operation.") + exit(1) + } + let count = LMMgr.importYahooKeyKeyUserDictionary(text: &rawString) + let msg = String(format: "i18n:settings.importFromKimoTxt.finishedCount:%@".localized, count.description) + print("[Kimo Import] \(msg)") + exit(0) + default: break + } default: exit(0) }