1
mirror of https://github.com/revanced/revanced-patcher synced 2025-09-06 16:38:50 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
semantic-release-bot
c1fbd8cf8c chore(release): 2.1.0 [skip ci]
# [2.1.0](https://github.com/revanced/revanced-patcher/compare/v2.0.4...v2.1.0) (2022-06-28)

### Features

* log failed patches due to failed dependencies ([a467fbb](a467fbb704))
2022-06-28 01:27:05 +00:00
oSumAtrIX
a467fbb704 feat: log failed patches due to failed dependencies 2022-06-28 03:25:49 +02:00
3 changed files with 24 additions and 10 deletions

View File

@@ -1,3 +1,10 @@
# [2.1.0](https://github.com/revanced/revanced-patcher/compare/v2.0.4...v2.1.0) (2022-06-28)
### Features
* log failed patches due to failed dependencies ([a467fbb](https://github.com/revanced/revanced-patcher/commit/a467fbb704eebe812cdec14025398dab2af43959))
## [2.0.4](https://github.com/revanced/revanced-patcher/compare/v2.0.3...v2.0.4) (2022-06-27)
## [2.0.3](https://github.com/revanced/revanced-patcher/compare/v2.0.2...v2.0.3) (2022-06-27)

View File

@@ -1,2 +1,2 @@
kotlin.code.style = official
version = 2.0.4
version = 2.1.0

View File

@@ -241,31 +241,35 @@ class Patcher(private val options: PatcherOptions) {
/**
* Apply a [patch] and its dependencies recursively.
* @param patch The [patch] to apply.
* @param appliedPatches A list of [patch] names, to prevent applying [patch]es twice.
* @param appliedPatches A map of [patch]es paired to a boolean indicating their success, to prevent infinite recursion.
* @return The result of executing the [patch].
*/
private fun applyPatch(
patch: Class<out Patch<Data>>, appliedPatches: MutableList<String>
patch: Class<out Patch<Data>>,
appliedPatches: MutableMap<String, Boolean>
): PatchResult {
val patchName = patch.patchName
// if the patch has already applied silently skip it
if (appliedPatches.contains(patchName)) {
logger.trace("Skipping patch $patchName because it has already been applied")
if (!appliedPatches[patchName]!!)
return PatchResultError("'$patchName' did not succeed previously")
logger.trace("Skipping '$patchName' because it has already been applied")
return PatchResultSuccess()
}
appliedPatches.add(patchName)
// recursively apply all dependency patches
patch.dependencies?.forEach {
val patchDependency = it.java
val result = applyPatch(patchDependency, appliedPatches)
if (result.isSuccess()) return@forEach
val errorMessage = result.error()!!.message
return PatchResultError("$patchName depends on ${patchDependency.patchName} but the following error was raised: $errorMessage")
return PatchResultError("'$patchName' depends on '${patchDependency.patchName}' but the following error was raised: $errorMessage")
}
val patchInstance = patch.getDeclaredConstructor().newInstance()
@@ -273,7 +277,7 @@ class Patcher(private val options: PatcherOptions) {
// if the current patch is a resource patch but resource patching is disabled, return an error
val isResourcePatch = patchInstance is ResourcePatch
if (!options.patchResources && isResourcePatch) {
return PatchResultError("$patchName is a resource patch, but resource patching is disabled.")
return PatchResultError("'$patchName' is a resource patch, but resource patching is disabled")
}
// TODO: find a solution for this
@@ -285,11 +289,14 @@ class Patcher(private val options: PatcherOptions) {
bytecodeData
}
logger.trace("Executing patch $patchName of type: ${if (isResourcePatch) "resource" else "bytecode"}")
logger.trace("Executing '$patchName' of type: ${if (isResourcePatch) "resource" else "bytecode"}")
return try {
patchInstance.execute(data)
val result = patchInstance.execute(data)
appliedPatches[patchName] = result.isSuccess()
result
} catch (e: Exception) {
appliedPatches[patchName] = false
PatchResultError(e)
}
}
@@ -301,7 +308,7 @@ class Patcher(private val options: PatcherOptions) {
*/
fun applyPatches(stopOnError: Boolean = false) = sequence {
logger.trace("Applying all patches")
val appliedPatches = mutableListOf<String>()
val appliedPatches = mutableMapOf<String, Boolean>() // first is success, second is name
for (patch in data.patches) {
val patchResult = applyPatch(patch, appliedPatches)