feat(PatchingScreen): only clear incomplete DownloadSteps when cancelling patching early

This commit is contained in:
rushiiMachine 2025-04-09 20:22:15 -07:00
parent f3547048e3
commit e6cb0696d4
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
3 changed files with 14 additions and 8 deletions

View file

@ -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()
},
)
}

View file

@ -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<DownloadStep>()
?.lastOrNull { it.state == StepState.Running }
incompleteDownloadStep?.targetFile?.delete()
paths.patchingWorkingDir().deleteRecursively()
}
fun install() = screenModelScope.launch {

View file

@ -140,7 +140,7 @@
<string name="status_failed">Failed</string>
<string name="installer_abort_title">Really exit?</string>
<string name="installer_abort_body">Are you sure you really want to abort an in-progress installation? Cached files will be cleared to avoid corruption.</string>
<string name="installer_abort_body">Are you sure you really want to abort an in-progress installation?</string>
<string name="updater_body">A new update has been released for Aliucord Manager! It may be required in order to function properly. Would you like to update?</string>
<string name="updater_title">Update to %1$s</string>