mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-03 14:14:26 +02:00
feat: yield the patch result
This commit is contained in:
parent
930768dfb3
commit
dde5385232
@ -302,29 +302,23 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
/**
|
/**
|
||||||
* Apply patches loaded into the patcher.
|
* Apply patches loaded into the patcher.
|
||||||
* @param stopOnError If true, the patches will stop on the first error.
|
* @param stopOnError If true, the patches will stop on the first error.
|
||||||
* @return A map of [PatchResultSuccess]. If the [Patch] was successfully applied,
|
* @return A pair of the name of the [Patch] and its [PatchResult].
|
||||||
* [PatchResultSuccess] will always be returned to the wrapping Result object.
|
|
||||||
* If the [Patch] failed to apply, an Exception will always be returned to the wrapping Result object.
|
|
||||||
*/
|
*/
|
||||||
fun applyPatches(
|
fun applyPatches(stopOnError: Boolean = false) = sequence {
|
||||||
stopOnError: Boolean = false, callback: (Class<out Patch<Data>>, Boolean) -> Unit = { _, _ -> }
|
|
||||||
): Map<String, Result<PatchResultSuccess>> {
|
|
||||||
logger.trace("Applying all patches")
|
logger.trace("Applying all patches")
|
||||||
val appliedPatches = mutableListOf<String>()
|
val appliedPatches = mutableListOf<String>()
|
||||||
|
|
||||||
return buildMap {
|
for (patch in data.patches) {
|
||||||
for (patch in data.patches) {
|
val patchResult = applyPatch(patch, appliedPatches)
|
||||||
val result = applyPatch(patch, appliedPatches)
|
|
||||||
|
|
||||||
this[patch.patchName] = if (result.isSuccess()) {
|
val result = if (patchResult.isSuccess()) {
|
||||||
Result.success(result.success()!!)
|
Result.success(patchResult.success()!!)
|
||||||
} else {
|
} else {
|
||||||
Result.failure(result.error()!!)
|
Result.failure(patchResult.error()!!)
|
||||||
}
|
|
||||||
|
|
||||||
callback(patch, result.isSuccess())
|
|
||||||
if (stopOnError && result.isError()) break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yield(patch.name to result)
|
||||||
|
if (stopOnError && patchResult.isError()) break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user