Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorfgsfds <4870330+fgsfds@users.noreply.github.com>2025-08-14 00:19:59 +0300
committerGitHub <noreply@github.com>2025-08-14 00:19:59 +0300
commit6879a8fbcba33dc56afa0ef0a172d506e1f874f3 (patch)
treece994c97818d4fb5f3297f4c8c654f7dc75a02c5 /config
parent72588414911075f1aa38f82dd5f4b9edd9d0d215 (diff)
Moved DB to same app folder on Windows (#3340)
* moved db to user folder on windows * moved db to local appdata * made getDBFolderPath func private * added getWindowsDbPath() func * fix --------- Co-authored-by: mhsanaei <ho3ein.sanaei@gmail.com>
Diffstat (limited to 'config')
-rw-r--r--config/config.go81
1 files changed, 75 insertions, 6 deletions
diff --git a/config/config.go b/config/config.go
index 70be5ae6..32d83055 100644
--- a/config/config.go
+++ b/config/config.go
@@ -3,7 +3,10 @@ package config
import (
_ "embed"
"fmt"
+ "io"
"os"
+ "path/filepath"
+ "runtime"
"strings"
)
@@ -54,12 +57,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
+ }
+ if runtime.GOOS == "windows" {
+ return getBaseDir()
}
- return dbFolderPath
+ return "/etc/x-ui"
}
func GetDBPath() string {
@@ -68,8 +91,54 @@ func GetDBPath() string {
func GetLogFolder() string {
logFolderPath := os.Getenv("XUI_LOG_FOLDER")
- if logFolderPath == "" {
- logFolderPath = "/var/log"
+ if logFolderPath != "" {
+ return logFolderPath
+ }
+ if runtime.GOOS == "windows" {
+ return getBaseDir()
+ }
+ return "/var/log"
+}
+
+func copyFile(src, dst string) error {
+ in, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ out, err := os.Create(dst)
+ if err != nil {
+ return err
+ }
+ defer out.Close()
+
+ _, err = io.Copy(out, in)
+ if err != nil {
+ return err
+ }
+
+ return out.Sync()
+}
+
+func init() {
+ if runtime.GOOS != "windows" {
+ return
+ }
+ if os.Getenv("XUI_DB_FOLDER") != "" {
+ return
+ }
+ oldDBFolder := "/etc/x-ui"
+ oldDBPath := fmt.Sprintf("%s/%s.db", oldDBFolder, GetName())
+ newDBFolder := GetDBFolderPath()
+ newDBPath := fmt.Sprintf("%s/%s.db", newDBFolder, GetName())
+ _, err := os.Stat(newDBPath)
+ if err == nil {
+ return // new exists
+ }
+ _, err = os.Stat(oldDBPath)
+ if os.IsNotExist(err) {
+ return // old does not exist
}
- return logFolderPath
+ _ = copyFile(oldDBPath, newDBPath) // ignore error
}