others.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build !windows
  2. package platform
  3. import (
  4. "errors"
  5. "io/fs"
  6. "os"
  7. "path/filepath"
  8. )
  9. func ExpandEnv(s string) string {
  10. return os.ExpandEnv(s)
  11. }
  12. func LineSeparator() string {
  13. return "\n"
  14. }
  15. func GetToolLocation(file string) string {
  16. const name = "v2ray.location.tool"
  17. toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
  18. return filepath.Join(toolPath, file)
  19. }
  20. // GetAssetLocation search for `file` in certain locations
  21. func GetAssetLocation(file string) string {
  22. const name = "v2ray.location.asset"
  23. assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
  24. defPath := filepath.Join(assetPath, file)
  25. for _, p := range []string{
  26. defPath,
  27. filepath.Join("/usr/local/share/v2ray/", file),
  28. filepath.Join("/usr/share/v2ray/", file),
  29. filepath.Join("/opt/share/v2ray/", file),
  30. } {
  31. if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) {
  32. continue
  33. }
  34. // asset found
  35. return p
  36. }
  37. // asset not found, let the caller throw out the error
  38. return defPath
  39. }