Skip to content

Commit

Permalink
release assets at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejohnson7 committed Oct 29, 2023
1 parent 2dfb95b commit ec41029
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/src/main/java/com/github/kr328/clash/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -20,6 +26,7 @@ class MainApplication : Application() {
super.onCreate()

val processName = currentProcessName
extractGeoFiles()

Log.d("Process $processName started")

Expand All @@ -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()
}
Expand Down

0 comments on commit ec41029

Please sign in to comment.