mirror of
https://github.com/revanced/revanced-patcher
synced 2024-11-27 18:13:37 +01:00
refactor: Properly abstract Patch#execute
function
This commit is contained in:
parent
29adcd5aad
commit
8e1117ed3f
@ -3,7 +3,6 @@ package app.revanced.patcher
|
||||
import app.revanced.patcher.PatchBundleLoader.Utils.getInstance
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.fingerprint.LookupMap
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint.Companion.resolveUsingLookupMap
|
||||
import app.revanced.patcher.patch.*
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import java.io.Closeable
|
||||
@ -166,19 +165,7 @@ class Patcher(
|
||||
}
|
||||
|
||||
return try {
|
||||
// TODO: Implement this in a more polymorphic way.
|
||||
when (patch) {
|
||||
is BytecodePatch -> {
|
||||
patch.fingerprints.resolveUsingLookupMap(context.bytecodeContext)
|
||||
patch.execute(context.bytecodeContext)
|
||||
}
|
||||
is RawResourcePatch -> {
|
||||
patch.execute(context.resourceContext)
|
||||
}
|
||||
is ResourcePatch -> {
|
||||
patch.execute(context.resourceContext)
|
||||
}
|
||||
}
|
||||
patch.execute(context)
|
||||
|
||||
PatchResult(patch)
|
||||
} catch (exception: PatchException) {
|
||||
|
@ -2,8 +2,10 @@ package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.PatchClass
|
||||
import app.revanced.patcher.Patcher
|
||||
import app.revanced.patcher.PatcherContext
|
||||
import app.revanced.patcher.data.BytecodeContext
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint.Companion.resolveUsingLookupMap
|
||||
import java.io.Closeable
|
||||
|
||||
/**
|
||||
@ -58,4 +60,9 @@ abstract class BytecodePatch : Patch<BytecodeContext> {
|
||||
ReplaceWith("BytecodePatch(emptySet())"),
|
||||
)
|
||||
constructor() : this(emptySet())
|
||||
|
||||
override fun execute(context: PatcherContext) {
|
||||
fingerprints.resolveUsingLookupMap(context.bytecodeContext)
|
||||
execute(context.bytecodeContext)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.PatchClass
|
||||
import app.revanced.patcher.Patcher
|
||||
import app.revanced.patcher.PatcherContext
|
||||
import app.revanced.patcher.data.Context
|
||||
import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively
|
||||
import app.revanced.patcher.patch.options.PatchOptions
|
||||
@ -90,6 +91,14 @@ sealed class Patch<out T : Context<*>> {
|
||||
*/
|
||||
val options = PatchOptions()
|
||||
|
||||
/**
|
||||
* The execution function of the patch.
|
||||
* This function is called by [Patcher].
|
||||
*
|
||||
* @param context The [PatcherContext] the patch will work on.
|
||||
*/
|
||||
internal abstract fun execute(context: PatcherContext)
|
||||
|
||||
/**
|
||||
* The execution function of the patch.
|
||||
*
|
||||
|
@ -2,6 +2,7 @@ package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.PatchClass
|
||||
import app.revanced.patcher.Patcher
|
||||
import app.revanced.patcher.PatcherContext
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import java.io.Closeable
|
||||
|
||||
@ -40,4 +41,6 @@ abstract class RawResourcePatch : Patch<ResourceContext> {
|
||||
use: Boolean = true,
|
||||
requiresIntegrations: Boolean = false,
|
||||
) : super(name, description, compatiblePackages, dependencies, use, requiresIntegrations)
|
||||
|
||||
override fun execute(context: PatcherContext) = execute(context.resourceContext)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package app.revanced.patcher.patch
|
||||
|
||||
import app.revanced.patcher.PatchClass
|
||||
import app.revanced.patcher.Patcher
|
||||
import app.revanced.patcher.PatcherContext
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import java.io.Closeable
|
||||
|
||||
@ -40,4 +41,6 @@ abstract class ResourcePatch : Patch<ResourceContext> {
|
||||
use: Boolean = true,
|
||||
requiresIntegrations: Boolean = false,
|
||||
) : super(name, description, compatiblePackages, dependencies, use, requiresIntegrations)
|
||||
|
||||
override fun execute(context: PatcherContext) = execute(context.resourceContext)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user