Installer // Use FileManager to trash old bundle.

This commit is contained in:
ShikiSuen 2022-01-25 20:52:53 +08:00
parent 69ae056003
commit 46c9384925
1 changed files with 19 additions and 6 deletions

View File

@ -117,12 +117,25 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
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
let trashDir = (NSHomeDirectory() as NSString).appendingPathComponent(".Trash")
var tag = 0
NSWorkspace.shared.performFileOperation(.recycleOperation, source: sourceDir, destination: trashDir, files: [kTargetBundle], tag: &tag)
//
do {
let sourceDir = (kDestinationPartial as NSString).expandingTildeInPath
let fileManager = FileManager.default
let fileURLString = String(format: "%@/%@", sourceDir, kTargetBundle)
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()
killTask.launchPath = "/usr/bin/killall"