34 lines
731 B
Go
34 lines
731 B
Go
package paths
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
// Dir 是当前用户的本机数据目录。测试可设置 TAPREMLY_HOME。
|
|
func Dir() (string, error) {
|
|
if d := os.Getenv("TAPREMLY_HOME"); d != "" {
|
|
return d, nil
|
|
}
|
|
if runtime.GOOS == "windows" {
|
|
local := os.Getenv("LOCALAPPDATA")
|
|
if local == "" {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
local = filepath.Join(home, "AppData", "Local")
|
|
}
|
|
return filepath.Join(local, "TapRemly"), nil
|
|
}
|
|
if x := os.Getenv("XDG_DATA_HOME"); x != "" {
|
|
return filepath.Join(x, "tapremly"), nil
|
|
}
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return filepath.Join(home, ".local", "share", "tapremly"), nil
|
|
}
|