0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-04-28 14:21:25 +03:00

51 lines
1.2 KiB
Go
Raw Permalink Normal View History

2021-09-20 21:00:55 +08:00
//go:build !windows
2020-11-25 19:01:53 +08:00
// +build !windows
package platform
import (
"os"
"path/filepath"
)
func ExpandEnv(s string) string {
return os.ExpandEnv(s)
}
func LineSeparator() string {
return "\n"
}
func GetToolLocation(file string) string {
toolPath := NewEnvFlag(ToolLocation).GetValue(getExecutableDir)
2020-11-25 19:01:53 +08:00
return filepath.Join(toolPath, file)
}
// GetAssetLocation searches for `file` in the env dir, the executable dir, and certain locations
2020-11-25 19:01:53 +08:00
func GetAssetLocation(file string) string {
assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir)
2020-11-25 19:01:53 +08:00
defPath := filepath.Join(assetPath, file)
for _, p := range []string{
defPath,
filepath.Join("/usr/local/share/xray/", file),
filepath.Join("/usr/share/xray/", file),
2021-02-27 23:09:44 +08:00
filepath.Join("/opt/share/xray/", file),
2020-11-25 19:01:53 +08:00
} {
if _, err := os.Stat(p); os.IsNotExist(err) {
continue
}
// asset found
return p
}
// asset not found, let the caller throw out the error
return defPath
}
// GetCertLocation searches for `file` in the env dir and the executable dir
func GetCertLocation(file string) string {
certPath := NewEnvFlag(CertLocation).GetValue(getExecutableDir)
return filepath.Join(certPath, file)
}