忽略geosite文件大小写
This commit is contained in:
parent
7ff48ea42d
commit
0a180eeb40
2 changed files with 42 additions and 5 deletions
|
@ -3,6 +3,7 @@ package geodata
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/component/geodata/router"
|
"github.com/Dreamacro/clash/component/geodata/router"
|
||||||
|
@ -14,7 +15,7 @@ type loader struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *loader) LoadGeoSite(list string) ([]*router.Domain, error) {
|
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) {
|
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) {
|
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
|
var loaders map[string]func() LoaderImplementation
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
package constant
|
package constant
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
P "path"
|
P "path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "clash"
|
const Name = "clash"
|
||||||
|
|
||||||
|
var (
|
||||||
|
GeositeName = "GeoSite.dat"
|
||||||
|
GeoipName = "GeoIP.dat"
|
||||||
|
)
|
||||||
|
|
||||||
// Path is used to get the configuration path
|
// Path is used to get the configuration path
|
||||||
var Path = func() *path {
|
var Path = func() *path {
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
|
@ -48,7 +55,6 @@ func (p *path) Resolve(path string) string {
|
||||||
if !filepath.IsAbs(path) {
|
if !filepath.IsAbs(path) {
|
||||||
return filepath.Join(p.HomeDir(), path)
|
return filepath.Join(p.HomeDir(), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,11 +71,41 @@ func (p *path) Cache() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *path) GeoIP() 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 {
|
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 {
|
func (p *path) ScriptDir() string {
|
||||||
|
|
Loading…
Reference in a new issue