github.com/v2fly/v2ray-core/v4@v4.45.2/common/platform/others.go (about)

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