Main // Support "--import-kimo" terminal parameter, etc.

This commit is contained in:
ShikiSuen 2024-02-12 22:20:12 +08:00
parent ae73869a2d
commit 5d8680c4b5
3 changed files with 36 additions and 9 deletions

View File

@ -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)
)
}

View File

@ -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

View File

@ -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)
}