others.go 1.0 KB

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