github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/common/platform/others.go (about)

     1  // +build !windows
     2  
     3  package platform
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  )
     9  
    10  func ExpandEnv(s string) string {
    11  	return os.ExpandEnv(s)
    12  }
    13  
    14  func LineSeparator() string {
    15  	return "\n"
    16  }
    17  
    18  func GetToolLocation(file string) string {
    19  	const name = "v2ray.location.tool"
    20  	toolPath := EnvFlag{Name: name, AltName: NormalizeEnvName(name)}.GetValue(getExecutableDir)
    21  	return filepath.Join(toolPath, file)
    22  }
    23  
    24  // GetAssetLocation search for `file` in certain locations
    25  func GetAssetLocation(file string) string {
    26  	const name = "v2ray.location.asset"
    27  	assetPath := NewEnvFlag(name).GetValue(getExecutableDir)
    28  	defPath := filepath.Join(assetPath, file)
    29  	for _, p := range []string{
    30  		defPath,
    31  		filepath.Join("/usr/local/share/v2ray/", file),
    32  		filepath.Join("/usr/share/v2ray/", file),
    33  	} {
    34  		if _, err := os.Stat(p); os.IsNotExist(err) {
    35  			continue
    36  		}
    37  
    38  		// asset found
    39  		return p
    40  	}
    41  
    42  	// asset not found, let the caller throw out the error
    43  	return defPath
    44  }