use external config converter first, and then fallback to the internal one

This commit is contained in:
Darien Raymond
2017-11-11 22:29:00 +01:00
parent 901d13ca76
commit 268d7264e8
4 changed files with 63 additions and 10 deletions
+7
View File
@@ -4,6 +4,7 @@ package platform
import (
"os"
"path/filepath"
)
func ExpandEnv(s string) string {
@@ -13,3 +14,9 @@ func ExpandEnv(s string) string {
func LineSeparator() string {
return "\n"
}
func GetToolLocation(file string) string {
const name = "v2ray.location.tool"
toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
return filepath.Join(toolPath, file)
}
+9 -7
View File
@@ -45,14 +45,16 @@ func NormalizeEnvName(name string) string {
return strings.Replace(strings.ToUpper(strings.TrimSpace(name)), ".", "_", -1)
}
func getExecutableDir() string {
exec, err := os.Executable()
if err != nil {
return ""
}
return filepath.Dir(exec)
}
func GetAssetLocation(file string) string {
const name = "v2ray.location.asset"
assetPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(func() string {
exec, err := os.Executable()
if err != nil {
return ""
}
return filepath.Dir(exec)
})
assetPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
return filepath.Join(assetPath, file)
}
+8
View File
@@ -2,6 +2,8 @@
package platform
import "path/filepath"
func ExpandEnv(s string) string {
// TODO
return s
@@ -10,3 +12,9 @@ func ExpandEnv(s string) string {
func LineSeparator() string {
return "\r\n"
}
func GetToolLocation(file string) string {
const name = "v2ray.location.tool"
toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
return filepath.Join(toolPath, file+".exe")
}