optimize: more friendly prompt and accurate judge for the asset path

This commit is contained in:
mzz2017 committed 2021-04-30 12:55:44 +08:00
1 parent 8985975ba7
commit 293fb8a0db
2 files changed
+26 -4

No files matched your search

+25 -3
View File
@@ -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()
+1 -1
View File
@@ -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)
}