@@ -10,9 +10,6 @@ import com.github.kr328.clash.service.util.sendServiceRecreated
1010import com.github.kr328.clash.util.clashDir
1111import java.io.File
1212import java.io.FileOutputStream
13- import java.io.IOException
14- import java.io.InputStream
15- import java.io.OutputStream
1613
1714
1815@Suppress(" unused" )
@@ -39,31 +36,41 @@ class MainApplication : Application() {
3936 }
4037
4138 private fun extractGeoFiles () {
42- clashDir.mkdirs();
39+ clashDir.mkdirs()
4340
41+ val updateDate = packageManager.getPackageInfo(packageName, 0 ).lastUpdateTime
4442 val geoipFile = File (clashDir, " geoip.metadb" )
45- if (! geoipFile.exists()) {
43+ if (geoipFile.exists() && geoipFile.lastModified() < updateDate) {
44+ geoipFile.delete()
45+ }
46+ if (! geoipFile.exists()) {
4647 FileOutputStream (geoipFile).use {
47- assets.open(" geoip.metadb" ).copyTo(it);
48+ assets.open(" geoip.metadb" ).copyTo(it)
4849 }
4950 }
5051
5152 val geositeFile = File (clashDir, " geosite.dat" )
52- if (! geositeFile.exists()) {
53+ if (geositeFile.exists() && geositeFile.lastModified() < updateDate) {
54+ geositeFile.delete()
55+ }
56+ if (! geositeFile.exists()) {
5357 FileOutputStream (geositeFile).use {
54- assets.open(" geosite.dat" ).copyTo(it);
58+ assets.open(" geosite.dat" ).copyTo(it)
5559 }
5660 }
57-
58- val ASNFile = File (clashDir, " ASN.mmdb" )
59- if (! ASNFile .exists()) {
60- FileOutputStream (ASNFile ).use {
61- assets.open(" ASN.mmdb" ).copyTo(it);
61+
62+ val asnFile = File (clashDir, " ASN.mmdb" )
63+ if (asnFile.exists() && asnFile.lastModified() < updateDate) {
64+ asnFile.delete()
65+ }
66+ if (! asnFile.exists()) {
67+ FileOutputStream (asnFile).use {
68+ assets.open(" ASN.mmdb" ).copyTo(it)
6269 }
6370 }
6471 }
6572
6673 fun finalize () {
6774 Global .destroy()
6875 }
69- }
76+ }
0 commit comments