|
|
@@ -12,6 +12,7 @@ const CoreWindow = require("ee-core/electron/window");
|
|
|
|
|
|
|
|
|
const { readConfigFile, writeConfigFile } = require('../utils/config');
|
|
|
+const defaultConfig = require('./config.default');
|
|
|
|
|
|
// 进程状态管理
|
|
|
let cameraProcess = null; // 子进程引用
|
|
|
@@ -47,14 +48,53 @@ function isSmartShooterType(type) {
|
|
|
return type === "SmartShooter" || type === "SmartShooter6"
|
|
|
}
|
|
|
|
|
|
+function sameDir(a, b) {
|
|
|
+ if (!a || !b) return false
|
|
|
+ const norm = (p) => path.normalize(String(p)).replace(/[\\/]+$/, "").toLowerCase()
|
|
|
+ return norm(a) === norm(b)
|
|
|
+}
|
|
|
+
|
|
|
+// 只在仍使用出厂的 Smart Shooter 6 目录时回退,手动改过安装目录的保持原选择
|
|
|
+function isDefaultSmartShooter6Dir(dir) {
|
|
|
+ return sameDir(dir, defaultConfig.SmartShooter6Path) || sameDir(dir, defaultConfig.controlPath)
|
|
|
+}
|
|
|
+
|
|
|
+function findSmartShooter5Dir(config) {
|
|
|
+ const candidates = [config.SmartShooterPath, defaultConfig.SmartShooterPath]
|
|
|
+ const seen = new Set()
|
|
|
+ for (const dir of candidates) {
|
|
|
+ if (!dir) continue
|
|
|
+ const key = path.normalize(String(dir)).replace(/[\\/]+$/, "").toLowerCase()
|
|
|
+ if (seen.has(key)) continue
|
|
|
+ seen.add(key)
|
|
|
+ if (fs.existsSync(path.join(dir, CONTROLLERS.SmartShooter.exe))) return dir
|
|
|
+ }
|
|
|
+ return ""
|
|
|
+}
|
|
|
+
|
|
|
function getController() {
|
|
|
const config = readConfigFile() || {}
|
|
|
const type = normalizeControlType(config.controlType)
|
|
|
const spec = CONTROLLERS[type]
|
|
|
+ const dir = config.controlPath || config[spec.pathKey] || ""
|
|
|
+
|
|
|
+ // 默认 Smart Shooter 6 目录下没有程序时,再找 Smart Shooter 5。只影响本次启动,不回写配置。
|
|
|
+ if (type === "SmartShooter6" && isDefaultSmartShooter6Dir(dir) && !fs.existsSync(path.join(dir, spec.exe))) {
|
|
|
+ const ss5Dir = findSmartShooter5Dir(config)
|
|
|
+ if (ss5Dir) {
|
|
|
+ Log.info(`默认目录未找到 SmartShooter6.exe,改用 Smart Shooter 5: ${ss5Dir}`)
|
|
|
+ return {
|
|
|
+ type: "SmartShooter",
|
|
|
+ ...CONTROLLERS.SmartShooter,
|
|
|
+ dir: ss5Dir,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
type,
|
|
|
...spec,
|
|
|
- dir: config.controlPath || config[spec.pathKey] || "",
|
|
|
+ dir,
|
|
|
}
|
|
|
}
|
|
|
|