mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-18 08:20:53 +00:00
feat: support specify cache file name
This commit is contained in:
parent
9fd63fe938
commit
c8eb626e00
2 changed files with 20 additions and 2 deletions
|
@ -37,12 +37,13 @@ var Path = func() *path {
|
|||
}
|
||||
}
|
||||
|
||||
return &path{homeDir: homeDir, configFile: "config.yaml", allowUnsafePath: allowUnsafePath}
|
||||
return &path{homeDir: homeDir, configFile: "config.yaml", cacheFile: "cache.db", allowUnsafePath: allowUnsafePath}
|
||||
}()
|
||||
|
||||
type path struct {
|
||||
homeDir string
|
||||
configFile string
|
||||
cacheFile string
|
||||
allowUnsafePath bool
|
||||
}
|
||||
|
||||
|
@ -51,6 +52,11 @@ func SetHomeDir(root string) {
|
|||
Path.homeDir = root
|
||||
}
|
||||
|
||||
// SetCache is used to set the cache file path
|
||||
func SetCache(file string) {
|
||||
Path.cacheFile = file
|
||||
}
|
||||
|
||||
// SetConfig is used to set the configuration file
|
||||
func SetConfig(file string) {
|
||||
Path.configFile = file
|
||||
|
@ -138,7 +144,7 @@ func (p *path) OldCache() string {
|
|||
}
|
||||
|
||||
func (p *path) Cache() string {
|
||||
return P.Join(p.homeDir, "cache.db")
|
||||
return p.cacheFile
|
||||
}
|
||||
|
||||
func (p *path) GeoIP() string {
|
||||
|
|
12
main.go
12
main.go
|
@ -31,6 +31,7 @@ var (
|
|||
testConfig bool
|
||||
geodataMode bool
|
||||
homeDir string
|
||||
cacheFile string
|
||||
configFile string
|
||||
configString string
|
||||
configBytes []byte
|
||||
|
@ -45,6 +46,7 @@ func init() {
|
|||
flag.StringVar(&homeDir, "d", os.Getenv("CLASH_HOME_DIR"), "set configuration directory")
|
||||
flag.StringVar(&configFile, "f", os.Getenv("CLASH_CONFIG_FILE"), "specify configuration file")
|
||||
flag.StringVar(&configString, "config", os.Getenv("CLASH_CONFIG_STRING"), "specify base64-encoded configuration string")
|
||||
flag.StringVar(&cacheFile, "cache", os.Getenv("CLASH_CACHE_FILE"), "specify cache file")
|
||||
flag.StringVar(&externalUI, "ext-ui", os.Getenv("CLASH_OVERRIDE_EXTERNAL_UI_DIR"), "override external ui directory")
|
||||
flag.StringVar(&externalController, "ext-ctl", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER"), "override external controller address")
|
||||
flag.StringVar(&externalControllerUnix, "ext-ctl-unix", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER_UNIX"), "override external controller unix address")
|
||||
|
@ -88,6 +90,16 @@ func main() {
|
|||
C.SetHomeDir(homeDir)
|
||||
}
|
||||
|
||||
if cacheFile != "" {
|
||||
if !filepath.IsAbs(cacheFile) {
|
||||
currentDir, _ := os.Getwd()
|
||||
cacheFile = filepath.Join(currentDir, cacheFile)
|
||||
}
|
||||
} else {
|
||||
cacheFile = filepath.Join(C.Path.HomeDir(), C.Path.Cache())
|
||||
}
|
||||
C.SetCache(cacheFile)
|
||||
|
||||
if geodataMode {
|
||||
geodata.SetGeodataMode(true)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue