Skip to content

Commit

Permalink
fix: migrate from PatchLoader.load(...) to `JarPatchBundle(...).loa…
Browse files Browse the repository at this point in the history
…dPatches()`

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
oSumAtrIX committed May 25, 2022
1 parent 61235d7 commit cabd32f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/app/revanced/cli/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app.revanced.cli

import app.revanced.patcher.annotation.Name
import app.revanced.patcher.extensions.findAnnotationRecursively
import app.revanced.patcher.util.patch.PatchLoader
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
import app.revanced.utils.adb.Adb
import app.revanced.utils.patcher.addPatchesFiltered
import app.revanced.utils.signature.Signature
Expand All @@ -20,7 +20,7 @@ internal object MainCommand : Runnable {
internal var includedPatches = arrayOf<String>()

@Option(names = ["-p", "--patches"], description = ["One or more bundles of patches"])
internal var patchBundles = arrayOf<File>()
internal var patchBundles = arrayOf<String>()

@Option(names = ["-t", "--temp-dir"], description = ["Temporal resource cache directory"], required = true)
internal lateinit var cacheDirectory: String
Expand Down Expand Up @@ -54,8 +54,8 @@ internal object MainCommand : Runnable {

override fun run() {
if (listOnly) {
for (patchBundle in patchBundles)
for (it in PatchLoader.loadFromFile(patchBundle))
for (patchBundlePath in patchBundles)
for (it in JarPatchBundle(patchBundlePath).loadPatches())
println(
"[available] ${
it.javaClass.findAnnotationRecursively(
Expand Down Expand Up @@ -90,7 +90,7 @@ internal object MainCommand : Runnable {
if (clean) File(cacheDirectory).deleteRecursively()

adb?.deploy()

if (clean) outputFile.delete()
}
}
17 changes: 11 additions & 6 deletions src/main/kotlin/app/revanced/utils/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import app.revanced.patcher.annotation.Name
import app.revanced.patcher.data.base.Data
import app.revanced.patcher.extensions.findAnnotationRecursively
import app.revanced.patcher.patch.base.Patch
import app.revanced.patcher.util.patch.PatchLoader
import app.revanced.patcher.util.patch.implementation.JarPatchBundle

fun Patcher.addPatchesFiltered(
packageCompatibilityFilter: Boolean = true,
Expand All @@ -19,7 +19,7 @@ fun Patcher.addPatchesFiltered(

MainCommand.patchBundles.forEach { bundle ->
val includedPatches = mutableListOf<Patch<Data>>()
PatchLoader.loadFromFile(bundle).forEach patch@{ p ->
JarPatchBundle(bundle).loadPatches().forEach patch@{ p ->
val patch = p.getDeclaredConstructor().newInstance()

val compatibilityAnnotation = patch.javaClass.findAnnotationRecursively(Compatibility::class.java)
Expand All @@ -41,13 +41,13 @@ fun Patcher.addPatchesFiltered(
}


for (compatiblePackage in compatibilityAnnotation.compatiblePackages) {
compatibilityAnnotation.compatiblePackages.forEach { compatiblePackage ->
if (packageCompatibilityFilter && compatiblePackage.name != packageName) {
println("$prefix: Package name not matching ${compatiblePackage.name}.")
return@patch
}

if (!packageVersionCompatibilityFilter || compatiblePackage.versions.any { it == packageVersion }) continue
if (!packageVersionCompatibilityFilter || compatiblePackage.versions.any { it == packageVersion }) return@patch
println("$prefix: Unsupported version.")
return@patch
}
Expand All @@ -61,8 +61,13 @@ fun Patcher.addPatchesFiltered(
}

fun Patcher.applyPatchesPrint() {
for ((patch, result) in this.applyPatches()) {
println("[${if (result.isFailure) "error" else "success"}] $patch")
this.applyPatches().forEach { (patch, result) ->
if (result.isSuccess) {
println("[success] $patch")
return@forEach
}
println("[error] $patch:")
result.exceptionOrNull()!!.printStackTrace()
}
}

Expand Down

0 comments on commit cabd32f

Please sign in to comment.