From 874be3051702ae42ec03c8faca746a00d75167e9 Mon Sep 17 00:00:00 2001 From: pcong Date: Sat, 11 Jan 2025 15:48:29 +0800 Subject: [PATCH] add: get app path --- godo/libs/dir.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/godo/libs/dir.go b/godo/libs/dir.go index 3bf52ff..15e5228 100644 --- a/godo/libs/dir.go +++ b/godo/libs/dir.go @@ -266,3 +266,27 @@ func PathExists(dir string) bool { return false } } + +func GetAppExecDir() string { + // 获取当前用户主目录 + homeDir, err := GetAppDir() + if err != nil { + return ".godoos" + } + return filepath.Join(homeDir, "app") +} + +func GetCmdPath(path string, name string) (string, error) { + // 根据操作系统添加.exe后缀 + binaryExt := "" + if runtime.GOOS == "windows" { + binaryExt = ".exe" + } + scriptName := name + binaryExt + exeDir := GetAppExecDir() // 获取执行程序的目录 + scriptPath := filepath.Join(exeDir, path, scriptName) + if !PathExists(scriptPath) { + return "", fmt.Errorf("script %s not found", scriptPath) + } + return scriptPath, nil +}