diff --git a/app/src/main/java/com/github/kr328/clash/MainApplication.kt b/app/src/main/java/com/github/kr328/clash/MainApplication.kt index d885d23252..153a2116cd 100644 --- a/app/src/main/java/com/github/kr328/clash/MainApplication.kt +++ b/app/src/main/java/com/github/kr328/clash/MainApplication.kt @@ -7,6 +7,12 @@ import com.github.kr328.clash.common.compat.currentProcessName import com.github.kr328.clash.common.log.Log import com.github.kr328.clash.remote.Remote import com.github.kr328.clash.service.util.sendServiceRecreated +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.io.InputStream +import java.io.OutputStream + @Suppress("unused") class MainApplication : Application() { @@ -20,6 +26,7 @@ class MainApplication : Application() { super.onCreate() val processName = currentProcessName + extractGeoFiles() Log.d("Process $processName started") @@ -30,6 +37,22 @@ class MainApplication : Application() { } } + private fun extractGeoFiles() { + val geoipFile = File(filesDir, "clash/geoip.metadb") + if(!geoipFile.exists()) { + FileOutputStream(geoipFile).use { + assets.open("geoip.metadb").copyTo(it); + } + } + + val geositeFile = File(filesDir, "clash/geosite.dat") + if(!geositeFile.exists()) { + FileOutputStream(geositeFile).use { + assets.open("geosite.dat").copyTo(it); + } + } + } + fun finalize() { Global.destroy() }