This commit is contained in:
mrFq1 2022-06-12 12:04:29 +08:00
parent 116b6720a7
commit 28dae09424
4 changed files with 52 additions and 11 deletions

4
.gitignore vendored
View File

@ -1,5 +1,7 @@
Pods/
Country.mmdb
geoip.dat
geosite.dat
Carthage
ClashX.a
ClashX.h
@ -16,4 +18,6 @@ ClashX/goClash/goClash.h
ClashX/goClash/goClash.a
fastlane/report.xml
ClashX/Resources/Country.mmdb.gz
ClashX/Resources/geoip.dat.gz
ClashX/Resources/geosite.dat.gz
.bundle/config

View File

@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
01B009AE2854533300B93618 /* geoip.dat.gz in Resources */ = {isa = PBXBuildFile; fileRef = 01B009AC2854533200B93618 /* geoip.dat.gz */; };
01B009AF2854533300B93618 /* geosite.dat.gz in Resources */ = {isa = PBXBuildFile; fileRef = 01B009AD2854533300B93618 /* geosite.dat.gz */; };
4913C82321157D0200F6B87C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4913C82221157D0200F6B87C /* Notification.swift */; };
491E6203258A424D00313AEF /* CommonUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 491E61FD258A424500313AEF /* CommonUtils.m */; };
49228457270AADE20027A4B6 /* RemoteConfigUpdateIntervalSettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49228456270AADE20027A4B6 /* RemoteConfigUpdateIntervalSettingView.swift */; };
@ -126,6 +128,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
01B009AC2854533200B93618 /* geoip.dat.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = geoip.dat.gz; sourceTree = "<group>"; };
01B009AD2854533300B93618 /* geosite.dat.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = geosite.dat.gz; sourceTree = "<group>"; };
4913C82221157D0200F6B87C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
491E61FC258A424500313AEF /* CommonUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonUtils.h; sourceTree = "<group>"; };
491E61FD258A424500313AEF /* CommonUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUtils.m; sourceTree = "<group>"; };
@ -375,6 +379,8 @@
isa = PBXGroup;
children = (
4929F676258CD89B00A435F6 /* Country.mmdb.gz */,
01B009AC2854533200B93618 /* geoip.dat.gz */,
01B009AD2854533300B93618 /* geosite.dat.gz */,
4929F60F258CD22E00A435F6 /* menu_icon@2x.png */,
49761DA621C9497000AE13EF /* dashboard */,
4989F98D20D0AE990001E564 /* sampleConfig.yaml */,
@ -605,12 +611,14 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
01B009AF2854533300B93618 /* geosite.dat.gz in Resources */,
49761DA721C9497000AE13EF /* dashboard in Resources */,
4929F677258CD89B00A435F6 /* Country.mmdb.gz in Resources */,
4981C88B216BAE4A008CC14A /* Localizable.strings in Resources */,
8A2BBEA727A03ACB0081EBEF /* ProxySetting.sdef in Resources */,
F9FAB31E262BE04800DE02A6 /* Images.xcassets in Resources */,
495340B020DE5F7200B0D3FF /* StatusItemView.xib in Resources */,
01B009AE2854533300B93618 /* geoip.dat.gz in Resources */,
49CF3B2820CD7465001EBF94 /* Main.storyboard in Resources */,
499A485A22ED781100F6C675 /* RemoteConfigAddView.xib in Resources */,
4929F610258CD22E00A435F6 /* menu_icon@2x.png in Resources */,

View File

@ -5,6 +5,12 @@ import Foundation
import Gzip
class ClashResourceManager {
enum RuleFiles: String {
case mmdb = "Country.mmdb"
case geosite = "geosite.dat"
case geoip = "geoip.dat"
}
static func check() -> Bool {
checkConfigDir()
checkMMDB()
@ -25,26 +31,39 @@ class ClashResourceManager {
}
static func checkMMDB() {
checkRule(.mmdb)
checkRule(.geoip)
checkRule(.geosite)
}
static func checkRule(_ file: RuleFiles) {
let fileManage = FileManager.default
let destMMDBPath = "\(kConfigFolderPath)/Country.mmdb"
let destPath = "\(kConfigFolderPath)/\(file.rawValue)"
// Remove old mmdb file after version update.
if fileManage.fileExists(atPath: destMMDBPath) {
let vaild = verifyGEOIPDataBase().toBool()
if fileManage.fileExists(atPath: destPath) {
let versionChange = AppVersionUtil.hasVersionChanged || AppVersionUtil.isFirstLaunch
let customMMDBSet = !Settings.mmdbDownloadUrl.isEmpty
if !vaild || (versionChange && customMMDBSet) {
try? fileManage.removeItem(atPath: destMMDBPath)
switch file {
case .mmdb:
let vaild = verifyGEOIPDataBase().toBool()
let customMMDBSet = !Settings.mmdbDownloadUrl.isEmpty
if !vaild || (versionChange && customMMDBSet) {
try? fileManage.removeItem(atPath: destPath)
}
case .geosite, .geoip:
if versionChange {
try? fileManage.removeItem(atPath: destPath)
}
}
}
if !fileManage.fileExists(atPath: destMMDBPath) {
if let mmdbUrl = Bundle.main.url(forResource: "Country.mmdb", withExtension: "gz") {
if !fileManage.fileExists(atPath: destPath) {
if let gzUrl = Bundle.main.url(forResource: file.rawValue, withExtension: "gz") {
do {
let data = try Data(contentsOf: mmdbUrl).gunzipped()
try data.write(to: URL(fileURLWithPath: destMMDBPath))
let data = try Data(contentsOf: gzUrl).gunzipped()
try data.write(to: URL(fileURLWithPath: destPath))
} catch let err {
Logger.log("add mmdb fail:\(err)", level: .error)
Logger.log("add \(file.rawValue) fail:\(err)", level: .error)
}
}
}

View File

@ -11,12 +11,22 @@ bundle install --jobs 4
bundle exec pod install
echo "delete old files"
rm -f ./ClashX/Resources/Country.mmdb
rm -f ./ClashX/Resources/geosite.dat
rm -f ./ClashX/Resources/geoip.dat
rm -rf ./ClashX/Resources/dashboard
rm -f GeoLite2-Country.*
echo "install mmdb"
curl -LO https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb
gzip Country.mmdb
mv Country.mmdb.gz ./ClashX/Resources/Country.mmdb.gz
echo "install geosite"
curl -LO https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
gzip geosite.dat
mv geosite.dat.gz ./ClashX/Resources/geosite.dat.gz
echo "install geoip"
curl -LO https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
gzip geoip.dat
mv geoip.dat.gz ./ClashX/Resources/geoip.dat.gz
echo "install dashboard"
cd ClashX/Resources
git clone -b gh-pages https://github.com/MetaCubeX/yacd.git dashboard