feat: clear old version caches

This commit is contained in:
Diamond 2022-11-05 14:15:39 -07:00
parent 33ad23fb01
commit 9fbf465648
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420

View file

@ -111,6 +111,14 @@ class InstallViewModel(
}
}
private fun clearOldCache(targetVersion: Int) {
externalCacheDir.listFiles { f -> f.isDirectory }
?.map { it.name.toIntOrNull() to it }
?.filter { it.first != null }
?.filter { it.first!! in (126021 + 1) until targetVersion }
?.forEach { it.second.deleteRecursively() }
}
override fun onCleared() {
if (installationRunning.getAndSet(false)) {
installJob.cancel("ViewModel cleared")
@ -141,6 +149,8 @@ class InstallViewModel(
val discordCacheDir = externalCacheDir.resolve(supportedVersion)
val patchedDir = discordCacheDir.resolve("patched").also { it.deleteRecursively() }
clearOldCache(supportedVersion.toInt())
// Download base.apk
val baseApkFile = step(InstallStep.DL_BASE_APK) {
discordCacheDir.resolve("base-${supportedVersion}.apk").let { file ->