mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
36 lines
713 B
Go
36 lines
713 B
Go
|
package constant
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
|
||
|
"github.com/sagernet/sing/common/rw"
|
||
|
)
|
||
|
|
||
|
const dirName = "sing-box"
|
||
|
|
||
|
var resourcePaths []string
|
||
|
|
||
|
func Find(name string) (string, bool) {
|
||
|
name = os.ExpandEnv(name)
|
||
|
if rw.FileExists(name) {
|
||
|
return name, true
|
||
|
}
|
||
|
for _, dir := range resourcePaths {
|
||
|
if path := filepath.Join(dir, dirName, name); rw.FileExists(path) {
|
||
|
return path, true
|
||
|
}
|
||
|
}
|
||
|
return name, false
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
resourcePaths = append(resourcePaths, ".")
|
||
|
if userConfigDir, err := os.UserConfigDir(); err == nil {
|
||
|
resourcePaths = append(resourcePaths, userConfigDir)
|
||
|
}
|
||
|
if userCacheDir, err := os.UserCacheDir(); err == nil {
|
||
|
resourcePaths = append(resourcePaths, userCacheDir)
|
||
|
}
|
||
|
}
|