Skip to content

Commit

Permalink
misc: replace invalid core
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFq1 committed Mar 31, 2023
1 parent 90ad362 commit 156bb49
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
updateAlphaVersion(nil)
}

let fm = FileManager.default

// unzip internal core
if !FileManager.default.fileExists(atPath: corePath.path) {
if !fm.fileExists(atPath: corePath.path) {
if let msg = unzipMetaCore() {
return (nil, msg)
}
} else if !validateDefaultCore() {
try? fm.removeItem(at: corePath)
if let msg = unzipMetaCore() {
return (nil, msg)
}
}

// -v test, chmod +x
if !chmodX(corePath.path) {
return (nil, "chmod +x failed.")
}

if let msg = testMetaCore(corePath.path) {
Logger.log("version: \(msg.version)")
}
Expand Down Expand Up @@ -599,10 +609,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func testMetaCore(_ path: String) -> (version: String, date: Date?)? {
guard FileManager.default.fileExists(atPath: path),
chmodX(path) else {
return nil
}

let proc = Process()
proc.executableURL = .init(fileURLWithPath: path)
Expand Down

0 comments on commit 156bb49

Please sign in to comment.