add asn import (#333)

This commit is contained in:
ForestL 2024-09-11 22:21:39 +08:00 committed by GitHub
parent 3cc77c7c95
commit fb1c6a2cc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 1 deletions

View File

@ -38,6 +38,7 @@ task("downloadGeoFiles") {
"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb" to "geoip.metadb",
"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat" to "geosite.dat",
// "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb" to "country.mmdb",
"https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb" to "ASN.mmdb",
)
doLast {

View File

@ -54,6 +54,13 @@ class MainApplication : Application() {
assets.open("geosite.dat").copyTo(it);
}
}
val ASNFile = File(clashDir, "ASN.mmdb")
if(!ASNFile.exists()) {
FileOutputStream(ASNFile).use {
assets.open("ASN.mmdb").copyTo(it);
}
}
}
fun finalize() {

View File

@ -70,6 +70,12 @@ class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
"*/*")
importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportCountry)
}
MetaFeatureSettingsDesign.Request.ImportASN -> {
val uri = startActivityForResult(
ActivityResultContracts.GetContent(),
"*/*")
importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportASN)
}
}
}
}
@ -107,6 +113,8 @@ class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
"geosite$ext"
MetaFeatureSettingsDesign.Request.ImportCountry ->
"country$ext"
MetaFeatureSettingsDesign.Request.ImportASN ->
"ASN$ext"
else -> ""
}

View File

@ -15,7 +15,7 @@ class MetaFeatureSettingsDesign(
configuration: ConfigurationOverride
) : Design<MetaFeatureSettingsDesign.Request>(context) {
enum class Request {
ResetOverride, ImportGeoIp, ImportGeoSite, ImportCountry
ResetOverride, ImportGeoIp, ImportGeoSite, ImportCountry, ImportASN
}
private val binding = DesignSettingsMetaFeatureBinding
@ -255,6 +255,15 @@ class MetaFeatureSettingsDesign(
requests.trySend(Request.ImportCountry)
}
}
clickable (
title = R.string.import_asn_file,
summary = R.string.press_to_import,
){
clicked {
requests.trySend(Request.ImportASN)
}
}
}
binding.content.addView(screen.root)

View File

@ -316,6 +316,7 @@
<string name="press_to_import">Press to import...</string>
<string name="import_geosite_file">Import GeoSite Database</string>
<string name="import_country_file">Import Country Database</string>
<string name="import_asn_file">Import ASN Database</string>
<string name="geofile_import_failed">Import failed</string>
<string name="geofile_unknown_db_format">Unknown Database format</string>
<string name="geofile_unknown_db_format_message">Only %1$s are supported</string>