From e6cb0696d45d1348e34545f1af61f1f658f499c9 Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Wed, 9 Apr 2025 20:22:15 -0700 Subject: [PATCH] feat(PatchingScreen): only clear incomplete `DownloadStep`s when cancelling patching early --- .../ui/screens/patching/PatchingScreen.kt | 4 ++-- .../ui/screens/patching/PatchingScreenModel.kt | 16 +++++++++++----- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreen.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreen.kt index 0432346..2c73b46 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreen.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreen.kt @@ -109,7 +109,7 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable { onDismiss = { showAbortWarning = false }, onConfirm = { navigator.back(currentActivity = null) - model.clearCache() + model.cancelInstall() }, ) } else { @@ -265,7 +265,7 @@ class PatchingScreen(private val data: PatchOptions) : Screen, Parcelable { ), onClick = { cacheCleared = true - model.clearCache() + model.cancelInstall() }, ) } diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreenModel.kt b/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreenModel.kt index c3df323..8b1b7cd 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreenModel.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/screens/patching/PatchingScreenModel.kt @@ -14,12 +14,12 @@ import com.aliucord.manager.manager.* import com.aliucord.manager.patcher.KotlinPatchRunner import com.aliucord.manager.patcher.StepRunner import com.aliucord.manager.patcher.steps.StepGroup -import com.aliucord.manager.patcher.steps.base.Step -import com.aliucord.manager.patcher.steps.base.StepState +import com.aliucord.manager.patcher.steps.base.* import com.aliucord.manager.patcher.steps.install.InstallStep import com.aliucord.manager.ui.screens.log.LogScreen import com.aliucord.manager.ui.screens.patchopts.PatchOptions import com.aliucord.manager.ui.util.toUnsafeImmutable +import com.aliucord.manager.util.launchBlock import com.aliucord.manager.util.showToast import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableMap @@ -76,9 +76,15 @@ class PatchingScreenModel( } } - fun clearCache() { - screenModelScope.launch { paths.clearCache() } - application.showToast(R.string.action_cleared_cache) + fun cancelInstall() = screenModelScope.launchBlock(Dispatchers.IO) { + runnerJob?.cancel("Manual cancellation") + + val incompleteDownloadStep = stepRunner?.steps + ?.filterIsInstance() + ?.lastOrNull { it.state == StepState.Running } + + incompleteDownloadStep?.targetFile?.delete() + paths.patchingWorkingDir().deleteRecursively() } fun install() = screenModelScope.launch { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9327a41..1a1d270 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -140,7 +140,7 @@ Failed Really exit? - Are you sure you really want to abort an in-progress installation? Cached files will be cleared to avoid corruption. + Are you sure you really want to abort an in-progress installation? A new update has been released for Aliucord Manager! It may be required in order to function properly. Would you like to update? Update to %1$s