瀏覽代碼

get asset location

Darien Raymond 8 年之前
父節點
當前提交
1d2c624062
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      common/platform/platform.go

+ 17 - 0
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)
+}