others.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. 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. }