mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-20 18:04:00 +00:00
add: resource patcher
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
25
src/main/kotlin/app/revanced/patch/PatchLoader.kt
Normal file
25
src/main/kotlin/app/revanced/patch/PatchLoader.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package app.revanced.patch
|
||||
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
|
||||
internal class PatchLoader {
|
||||
internal companion object {
|
||||
internal fun injectPatches(file: File) {
|
||||
// This function will fail on Java 9 and above.
|
||||
try {
|
||||
val url = file.toURI().toURL()
|
||||
val classLoader = Thread.currentThread().contextClassLoader as URLClassLoader
|
||||
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
|
||||
method.isAccessible = true
|
||||
method.invoke(classLoader, url)
|
||||
} catch (e: Exception) {
|
||||
throw Exception(
|
||||
"Failed to inject patches! The CLI does NOT work on Java 9 and above, please use Java 8!",
|
||||
e // propagate exception
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
src/main/kotlin/app/revanced/patch/Patches.kt
Normal file
15
src/main/kotlin/app/revanced/patch/Patches.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package app.revanced.patch
|
||||
|
||||
import app.revanced.patches.Index
|
||||
|
||||
internal class Patches {
|
||||
internal companion object {
|
||||
// You may ask yourself, "why do this?".
|
||||
// We do it like this, because we don't want the Index class
|
||||
// to be loaded while the dependency hasn't been injected yet.
|
||||
// You can see this as "controlled class loading".
|
||||
// Whenever this class is loaded (because it is invoked), all the imports
|
||||
// will be loaded too. We don't want to do this until we've injected the class.
|
||||
internal fun loadPatches() = Index.patches
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user