From 293fb8a0db60db2b567a1c082acdc7aa28b48c8a Mon Sep 17 00:00:00 2001 From: mzz2017 Date: Fri, 30 Apr 2021 12:55:44 +0800 Subject: [PATCH] optimize: more friendly prompt and accurate judge for the asset path --- service/core/v2ray/asset/asset.go | 28 +++++++++++++++++++++++++--- service/core/v2ray/status.go | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/service/core/v2ray/asset/asset.go b/service/core/v2ray/asset/asset.go index 872b0a64..d0d4dcf9 100644 --- a/service/core/v2ray/asset/asset.go +++ b/service/core/v2ray/asset/asset.go @@ -18,20 +18,42 @@ import ( "v2ray.com/core/common/strmatcher" ) +type assetCandidate struct { + path string + v2rayCore bool +} + func GetV2rayLocationAsset() (s string) { - var candidates = []string{`/usr/local/share/v2ray`, `/usr/share/v2ray`, `/usr/local/share/xray`, `/usr/share/xray`} + var candidates = []assetCandidate{ + {`/usr/local/share/v2ray`, true}, + {`/usr/share/v2ray`, true}, + {`/usr/local/share/xray`, false}, + {`/usr/share/xray`, false}, + } var is bool if ver, err := where.GetV2rayServiceVersion(); err == nil { if is, err = common.VersionGreaterEqual(ver, "4.27.1"); is { for _, c := range candidates { - if _, err := os.Stat(c); os.IsNotExist(err) { + if ver == "UnknownClient" { + // xray, etc. + if c.v2rayCore { + continue + } + } else { + // v2ray + if !c.v2rayCore { + continue + } + } + if _, err := os.Stat(c.path); os.IsNotExist(err) { continue } - s = c + s = c.path break } } } + // old version of v2ray if s == "" { //maybe v2ray working directory v2rayPath, err := where.GetV2rayBinPath() diff --git a/service/core/v2ray/status.go b/service/core/v2ray/status.go index fb6a15e6..68cacd52 100644 --- a/service/core/v2ray/status.go +++ b/service/core/v2ray/status.go @@ -112,7 +112,7 @@ func RestartV2rayService() (err error) { } if time.Since(startTime) > 15*time.Second { - return newError("v2ray-core does not start normally, there may be a problem of the configuration file or the required port is occupied") + return newError("v2ray-core does not start normally, check the log for more information") } time.Sleep(1000 * time.Millisecond) }