Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 1994531

Browse files
committed
perf: set all path format type to bash
1 parent ca063ce commit 1994531

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

InjectGUI/Backend/Injector.swift

+14-13
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Injector: ObservableObject {
132132
guard let injectDetail = injectConfiguration.injectDetail(package: package) else {
133133
return
134134
}
135+
print("[*] Start inject \(package)")
135136
self.injectDetail = injectDetail
136137
self.appDetail = appDetail
137138
self.shouldShowStatusSheet = true
@@ -326,7 +327,7 @@ class Injector: ObservableObject {
326327
case .none:
327328
return path.replacingOccurrences(of: "%20", with: " ")
328329
case .appleScript:
329-
return path.replacingOccurrences(of: "%20", with: " ").replacingOccurrences(of: " ", with: "\\\\ ")
330+
return path.replacingOccurrences(of: "%20", with: " ").replacingOccurrences(of: " ", with: "\\\\ ")
330331
case .bash:
331332
return path.replacingOccurrences(of: "%20", with: " ").replacingOccurrences(of: " ", with: "\\ ")
332333
}
@@ -340,29 +341,29 @@ class Injector: ObservableObject {
340341

341342
if !FileManager.default.fileExists(atPath: source) {
342343
print("Source file not found: \(source)")
343-
return [("echo Source file not found: \(source.transformTo(to: .appleScript)) && exit 1", true)] // 借用一下 AppleScript 来弹窗
344+
return [("echo Source file not found: \(source.transformTo(to: .bash)) && exit 1", true)] // 借用一下 AppleScript 来弹窗
344345
}
345346
if FileManager.default.fileExists(atPath: destination) {
346347
print("Destination file already exists: \(destination)")
347348
return []
348349
}
349350
return [
350-
("sudo cp \(source.transformTo(to: .appleScript)) \(destination.transformTo(to: .appleScript))", true)
351+
("sudo cp \(source.transformTo(to: .bash)) \(destination.transformTo(to: .bash))", true)
351352
]
352353
}
353354

354355
// MARK: - 注入原神之 权限与运行检查
355356

356357
func checkPermissionAndRunCommands() -> [(command: String, isAdmin: Bool)] {
357358
var shells: [(command: String, isAdmin: Bool)] = []
358-
let source = self.genSourcePath(for: .appleScript)
359+
let source = self.genSourcePath(for: .bash)
359360
shells.append(("sudo xattr -cr \(source)", true))
360361
shells.append(("sudo chmod -R 777 \(source)", true))
361362

362363
// 检查是否运行中, 如果运行中则杀掉进程
363364
let isRunning = NSRunningApplication.runningApplications(withBundleIdentifier: self.appDetail?.identifier ?? "").count > 0
364365
if isRunning {
365-
shells.append(("sudo pkill -f \(self.genSourcePath(for: .appleScript, executable: true))", true))
366+
shells.append(("sudo pkill -f \(self.genSourcePath(for: .bash, executable: true))", true))
366367
}
367368
return shells
368369
}
@@ -410,12 +411,12 @@ class Injector: ObservableObject {
410411
let componentApp = componentAppList.map { appBaseLocate + $0 }
411412
let componentAppExecutable = componentApp.map { $0 + "/Contents/MacOS/" + (self.readExecutableFile(app: URL(fileURLWithPath: $0)) ?? "") }
412413
let desireAppList = desireApp + componentAppExecutable
413-
let insert_dylib_commands = desireAppList.map { "sudo \(self.genSourcePath(for: .appleScript, path: insert_dylib_URL!)) '\(copyedQiuchenly_URL)' '\(destination.transformTo(to: .none))' '\($0)'" }
414+
let insert_dylib_commands = desireAppList.map { "sudo \(self.genSourcePath(for: .bash, path: insert_dylib_URL!)) '\(copyedQiuchenly_URL)' '\(destination.transformTo(to: .none))' '\($0)'" }
414415

415416
return [softLink] + insert_dylib_commands.map { ($0, true) }
416417
}
417418

418-
return [("sudo \(self.genSourcePath(for: .appleScript, path: insert_dylib_URL!)) '\(QiuchenlyDylib_URL!)' '\(source.transformTo(to: .none))' '\(destination.transformTo(to: .none))'", true)]
419+
return [("sudo \(self.genSourcePath(for: .bash, path: insert_dylib_URL!)) '\(QiuchenlyDylib_URL!)' '\(source.transformTo(to: .none))' '\(destination.transformTo(to: .none))'", true)]
419420
}
420421

421422
// MARK: - 注入原神之 DeepCodeSign
@@ -483,29 +484,29 @@ class Injector: ObservableObject {
483484
let downloadPath = downloadIntoTmpPath.appendingPathComponent(extraShell).path
484485
let downloadCommand = "curl -L -o \(downloadPath) \(getToolDownloadURL)"
485486

486-
let dest = self.genSourcePath(for: .appleScript)
487+
let dest = self.genSourcePath(for: .bash)
487488

488489
// MARK: - Sub: 对某些 shell 脚本进行内容替换
489490

490491
var replaceSpecialShell: [(String, String)] = [] // (from, to)
491492

492493
// tool/optool
493-
let optoolPath = self.genSourcePath(for: .appleScript, path: injectConfiguration.getInjecToolPath(name: "optool")?.pathWithFallback())
494+
let optoolPath = self.genSourcePath(for: .bash, path: injectConfiguration.getInjecToolPath(name: "optool")?.pathWithFallback())
494495
replaceSpecialShell.append(("tool/optool", optoolPath))
495496
replaceSpecialShell.append(("./tool/optool", optoolPath))
496497

497498
// tool/insert_dylib
498-
let insert_dylibPath = self.genSourcePath(for: .appleScript, path: injectConfiguration.getInjecToolPath(name: "insert_dylib")?.pathWithFallback())
499+
let insert_dylibPath = self.genSourcePath(for: .bash, path: injectConfiguration.getInjecToolPath(name: "insert_dylib")?.pathWithFallback())
499500
replaceSpecialShell.append(("tool/insert_dylib", insert_dylibPath))
500501
replaceSpecialShell.append(("./tool/insert_dylib", insert_dylibPath))
501502

502503
// tool/91QiuChenly.dylib
503-
let dylibPath = self.genSourcePath(for: .appleScript, path: injectConfiguration.getInjecToolPath(name: "91Qiuchenly.dylib")?.pathWithFallback())
504+
let dylibPath = self.genSourcePath(for: .bash, path: injectConfiguration.getInjecToolPath(name: "91Qiuchenly.dylib")?.pathWithFallback())
504505
replaceSpecialShell.append(("tool/91QiuChenly.dylib", dylibPath))
505506
replaceSpecialShell.append(("./tool/91QiuChenly.dylib", dylibPath))
506507

507508
// tool/GenShineImpactStarter
508-
let genShineImpactStarterPath = self.genSourcePath(for: .appleScript, path: injectConfiguration.getInjecToolPath(name: "GenShineImpactStarter")?.pathWithFallback())
509+
let genShineImpactStarterPath = self.genSourcePath(for: .bash, path: injectConfiguration.getInjecToolPath(name: "GenShineImpactStarter")?.pathWithFallback())
509510
replaceSpecialShell.append(("tool/GenShineImpactStarter", genShineImpactStarterPath))
510511
replaceSpecialShell.append(("./tool/GenShineImpactStarter", genShineImpactStarterPath))
511512

@@ -541,7 +542,7 @@ class Injector: ObservableObject {
541542
let bridgeFile = (self.appDetail?.path ?? "") + (self.getBridgeDir())
542543
let insertDylibURL = self.genSourcePath(for: .bash, path: injectConfiguration.getInjecToolPath(name: "insert_dylib")?.pathWithFallback())
543544
let helperName = targetHelper.split(separator: "/").last
544-
let target = self.genSourcePath(for: .appleScript, path: "/Library/LaunchDaemons/\(helperName!).plist")
545+
let target = self.genSourcePath(for: .bash, path: "/Library/LaunchDaemons/\(helperName!).plist")
545546

546547
var srcInfo = [(self.appDetail?.path ?? "").replacingOccurrences(of: "/Contents", with: "") + "/Contents/Info.plist"]
547548
if let componentApps = self.injectDetail?.componentApp {

0 commit comments

Comments
 (0)