feat: 支持多APK与渠道变体,增加自动定位的服务管理CLI

This commit is contained in:
tongtong committed 2026-11-25 16:10:05 +08:00
1 parent 7984785610
commit 87652364bc
33 files changed
+1110 -42

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
)
func accessCandidates(executable, platform, programData string) []string {
paths := []string{}
if platform == "windows" {
if programData == "" {
programData = `C:\ProgramData`
}
paths = append(paths, filepath.Join(programData, "VibeCodingRemoteCompilation", "data", "access.json"))
} else if platform == "linux" {
paths = append(paths, "/var/lib/remotecompile/data/access.json")
}
base := filepath.Dir(executable)
paths = append(paths, filepath.Join(base, "data", "access.json"))
if strings.EqualFold(filepath.Base(base), "bin") {
paths = append(paths, filepath.Join(filepath.Dir(base), "data", "access.json"))
}
return paths
}
func discoverAccessFile(candidates []string) (string, error) {
found := []string{}
for _, candidate := range candidates {
path, e := filepath.Abs(candidate)
if e != nil {
return "", e
}
info, e := os.Stat(path)
if os.IsNotExist(e) {
continue
}
if e != nil {
return "", fmt.Errorf("不能检查本机服务配置 %s:%w;请在服务器本机以管理员权限运行,或显式指定 --data/--access-file", path, e)
}
if !info.Mode().IsRegular() {
return "", fmt.Errorf("本机服务配置不是普通文件:%s", path)
}
duplicate := false
for _, previous := range found {
old, e := os.Stat(previous)
if e == nil && os.SameFile(info, old) {
duplicate = true
break
}
}
if !duplicate {
found = append(found, path)
}
}
if len(found) == 0 {
return "", fmt.Errorf("未找到本机服务配置;请先启动新版服务,或为自定义部署显式指定 --data <服务数据目录> / --access-file <配置文件>。不会使用当前目录下的 data")
}
if len(found) > 1 {
return "", fmt.Errorf("找到多套本机服务配置,无法唯一确定目标:\n%s\n请使用 --data 或 --access-file 明确指定,未修改任何配置", strings.Join(found, "\n"))
}
return found[0], nil
}
func localAccessFile() (string, error) {
executable, e := os.Executable()
if e != nil {
return "", e
}
return discoverAccessFile(accessCandidates(executable, runtime.GOOS, os.Getenv("ProgramData")))
}