windows.go 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // TODO
  11. return s
  12. }
  13. func LineSeparator() string {
  14. return "\r\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+".exe")
  20. }
  21. // GetAssetLocation search for `file` in the excutable dir
  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. file,
  29. } {
  30. if _, err := os.Stat(p); err != nil && errors.Is(err, fs.ErrNotExist) {
  31. continue
  32. }
  33. // asset found
  34. return p
  35. }
  36. // asset not found, let the caller throw out the error
  37. return defPath
  38. }