忽略geosite文件大小写

This commit is contained in:
Clash-Mini 2022-02-06 00:51:37 +08:00
parent 7ff48ea42d
commit 0a180eeb40
2 changed files with 42 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package geodata
import (
"errors"
"fmt"
C "github.com/Dreamacro/clash/constant"
"strings"
"github.com/Dreamacro/clash/component/geodata/router"
@ -14,7 +15,7 @@ type loader struct {
}
func (l *loader) LoadGeoSite(list string) ([]*router.Domain, error) {
return l.LoadGeoSiteWithAttr("geosite.dat", list)
return l.LoadGeoSiteWithAttr(C.GeositeName, list)
}
func (l *loader) LoadGeoSiteWithAttr(file string, siteWithAttr string) ([]*router.Domain, error) {
@ -58,7 +59,7 @@ func (l *loader) LoadGeoSiteWithAttr(file string, siteWithAttr string) ([]*route
}
func (l *loader) LoadGeoIP(country string) ([]*router.CIDR, error) {
return l.LoadIP("geoip.dat", country)
return l.LoadIP(C.GeoipName, country)
}
var loaders map[string]func() LoaderImplementation

View File

@ -1,13 +1,20 @@
package constant
import (
"io/ioutil"
"os"
P "path"
"path/filepath"
"strings"
)
const Name = "clash"
var (
GeositeName = "GeoSite.dat"
GeoipName = "GeoIP.dat"
)
// Path is used to get the configuration path
var Path = func() *path {
homeDir, err := os.UserHomeDir()
@ -48,7 +55,6 @@ func (p *path) Resolve(path string) string {
if !filepath.IsAbs(path) {
return filepath.Join(p.HomeDir(), path)
}
return path
}
@ -65,11 +71,41 @@ func (p *path) Cache() string {
}
func (p *path) GeoIP() string {
return P.Join(p.homeDir, "geoip.dat")
files, err := ioutil.ReadDir(p.homeDir)
if err != nil {
return ""
}
for _, fi := range files {
if fi.IsDir() {
// 目录则直接跳过
continue
} else {
if strings.EqualFold(fi.Name(), "GeoIP.dat") {
GeoipName = fi.Name()
return P.Join(p.homeDir, fi.Name())
}
}
}
return P.Join(p.homeDir, "GeoIP.dat")
}
func (p *path) GeoSite() string {
return P.Join(p.homeDir, "geosite.dat")
files, err := ioutil.ReadDir(p.homeDir)
if err != nil {
return ""
}
for _, fi := range files {
if fi.IsDir() {
// 目录则直接跳过
continue
} else {
if strings.EqualFold(fi.Name(), "GeoSite.dat") {
GeositeName = fi.Name()
return P.Join(p.homeDir, fi.Name())
}
}
}
return P.Join(p.homeDir, "GeoSite.dat")
}
func (p *path) ScriptDir() string {