ソースを参照

feat(camera): 默认Smart Shooter 6缺失时自动回退到Smart Shooter 5

- 新增 findSmartShooter5Dir 函数在配置和默认目录中查找 Smart Shooter 5
- 新增 sameDir 和 isDefaultSmartShooter6Dir 用于判断是否为出厂默认目录
- 仅在默认目录下未找到程序时触发回退,手动修改过安装路径的保持原选择
- 回退仅影响本次启动,不回写配置文件
- 更新 SmartShooter6 控制类型的提示信息,提示用户可安装 6 或 5
panqiuyao 3 日 前
親
コミット
ccfd31e8ba
2 ファイル変更、42 行追加、2 行削除
  1. 1 1
      electron/controller/camera.js
  2. 41 1
      electron/utils/camera.js

+ 1 - 1
electron/controller/camera.js

@@ -128,7 +128,7 @@ class CameraController extends Controller {
       const controlType = readConfigFile().controlType
       let msg = '请安装 Smart Shooter 5 或 Smart Shooter 6'
       if(controlType === 'SmartShooter') msg = '请安装 Smart Shooter 5'
-      if(controlType === 'SmartShooter6') msg = '请安装 Smart Shooter 6'
+      if(controlType === 'SmartShooter6') msg = '请安装 Smart Shooter 6 或 Smart Shooter 5'
       if(controlType === 'digiCamControl') msg = '请安装digiCamControl软件,并打开digiCamControl软件的web服务,端口为5513'
       return {
         status:-1,

+ 41 - 1
electron/utils/camera.js

@@ -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,
   }
 }