From 1d2c62406257d1983a1664a5461e271157d3a833 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sat, 4 Nov 2017 21:33:09 +0100 Subject: [PATCH] get asset location --- common/platform/platform.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/common/platform/platform.go b/common/platform/platform.go index 2327ad665..85126b701 100644 --- a/common/platform/platform.go +++ b/common/platform/platform.go @@ -2,6 +2,7 @@ package platform import ( "os" + "path/filepath" "strconv" "strings" ) @@ -40,3 +41,19 @@ func (f EnvFlag) GetValueAsInt(defaultValue int) int { func NormalizeEnvName(name string) string { return strings.Replace(strings.ToUpper(strings.TrimSpace(name)), ".", "_", -1) } + +var assetPath = "/" + +func init() { + defAssetLocation, err := os.Executable() + if err == nil { + defAssetLocation = filepath.Dir(defAssetLocation) + assetPath = (EnvFlag{ + Name: "v2ray.location.asset", + }).GetValue(defAssetLocation) + } +} + +func GetAssetLocation(file string) string { + return filepath.Join(assetPath, file) +}