github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/common/platform/others.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package platform 5 6 import ( 7 "os" 8 "path/filepath" 9 ) 10 11 func ExpandEnv(s string) string { 12 return os.ExpandEnv(s) 13 } 14 15 func LineSeparator() string { 16 return "\n" 17 } 18 19 func GetToolLocation(file string) string { 20 toolPath := NewEnvFlag(ToolLocation).GetValue(getExecutableDir) 21 return filepath.Join(toolPath, file) 22 } 23 24 // GetAssetLocation searches for `file` in certain locations 25 func GetAssetLocation(file string) string { 26 assetPath := NewEnvFlag(AssetLocation).GetValue(getExecutableDir) 27 defPath := filepath.Join(assetPath, file) 28 for _, p := range []string{ 29 defPath, 30 filepath.Join("/usr/local/share/xray/", file), 31 filepath.Join("/usr/share/xray/", file), 32 filepath.Join("/opt/share/xray/", file), 33 } { 34 if _, err := os.Stat(p); os.IsNotExist(err) { 35 continue 36 } 37 38 // asset found 39 return p 40 } 41 42 // asset not found, let the caller throw out the error 43 return defPath 44 }