From 4c98c241edee76d3958a48424685dbd61f270f62 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sun, 14 Sep 2025 22:34:11 +0200 Subject: [PATCH] fix windows db folder --- config/config.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index e3fe1709..7c7cdb3d 100644 --- a/config/config.go +++ b/config/config.go @@ -4,6 +4,8 @@ import ( _ "embed" "fmt" "os" + "path/filepath" + "runtime" "strings" ) @@ -53,12 +55,32 @@ func GetBinFolderPath() string { return binFolderPath } +func getBaseDir() string { + exePath, err := os.Executable() + if err != nil { + return "." + } + exeDir := filepath.Dir(exePath) + exeDirLower := strings.ToLower(filepath.ToSlash(exeDir)) + if strings.Contains(exeDirLower, "/appdata/local/temp/") || strings.Contains(exeDirLower, "/go-build") { + wd, err := os.Getwd() + if err != nil { + return "." + } + return wd + } + return exeDir +} + func GetDBFolderPath() string { dbFolderPath := os.Getenv("XUI_DB_FOLDER") - if dbFolderPath == "" { - dbFolderPath = "/etc/x-ui" + if dbFolderPath != "" { + return dbFolderPath } - return dbFolderPath + if runtime.GOOS == "windows" { + return getBaseDir() + } + return "/etc/x-ui" } func GetDBPath() string {