Installer // Use FileManager to trash old bundle.
This commit is contained in:
parent
69ae056003
commit
46c9384925
|
@ -117,12 +117,25 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
|
||||||
|
|
||||||
let shouldWaitForTranslocationRemoval = appBundleChronoshiftedToARandomizedPath(kTargetPartialPath) && (window?.responds(to: #selector(NSWindow.beginSheet(_:completionHandler:))) ?? false)
|
let shouldWaitForTranslocationRemoval = appBundleChronoshiftedToARandomizedPath(kTargetPartialPath) && (window?.responds(to: #selector(NSWindow.beginSheet(_:completionHandler:))) ?? false)
|
||||||
|
|
||||||
// http://www.cocoadev.com/index.pl?MoveToTrash
|
// 將既存輸入法扔到垃圾桶內
|
||||||
let sourceDir = (kDestinationPartial as NSString).expandingTildeInPath
|
do {
|
||||||
let trashDir = (NSHomeDirectory() as NSString).appendingPathComponent(".Trash")
|
let sourceDir = (kDestinationPartial as NSString).expandingTildeInPath
|
||||||
var tag = 0
|
let fileManager = FileManager.default
|
||||||
|
let fileURLString = String(format: "%@/%@", sourceDir, kTargetBundle)
|
||||||
NSWorkspace.shared.performFileOperation(.recycleOperation, source: sourceDir, destination: trashDir, files: [kTargetBundle], tag: &tag)
|
let fileURL = URL(fileURLWithPath: fileURLString)
|
||||||
|
|
||||||
|
// 檢查檔案是否存在
|
||||||
|
if fileManager.fileExists(atPath: fileURLString) {
|
||||||
|
// 塞入垃圾桶
|
||||||
|
try fileManager.trashItem(at: fileURL, resultingItemURL: nil)
|
||||||
|
} else {
|
||||||
|
NSLog("File does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch let error as NSError {
|
||||||
|
NSLog("An error took place: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
let killTask = Process()
|
let killTask = Process()
|
||||||
killTask.launchPath = "/usr/bin/killall"
|
killTask.launchPath = "/usr/bin/killall"
|
||||||
|
|
Loading…
Reference in New Issue