From 9fbf465648e935f611fe7414c0a539fb68a5a559 Mon Sep 17 00:00:00 2001 From: Diamond <33725716+DiamondMiner88@users.noreply.github.com> Date: Sat, 5 Nov 2022 14:15:39 -0700 Subject: [PATCH] feat: clear old version caches --- .../aliucord/manager/ui/viewmodel/InstallViewModel.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/viewmodel/InstallViewModel.kt b/app/src/main/kotlin/com/aliucord/manager/ui/viewmodel/InstallViewModel.kt index 00900be..fb8d646 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/viewmodel/InstallViewModel.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/viewmodel/InstallViewModel.kt @@ -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 ->