mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-10 17:14:25 +02:00
refactor: simplify loading patches (#172)
This commit is contained in:
parent
7f02b8df48
commit
239ea0bcaa
@ -54,17 +54,6 @@ class BytecodeContext internal constructor(classes: MutableList<ClassDef>) : Con
|
|||||||
}
|
}
|
||||||
return proxy
|
return proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
|
||||||
inline fun <reified T> Iterable<T>.find(predicate: (T) -> Boolean): T? {
|
|
||||||
for (element in this) {
|
|
||||||
if (predicate(element)) {
|
|
||||||
return element
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,18 +41,13 @@ sealed class PatchBundle(path: String) : File(path) {
|
|||||||
arrayOf(this.toURI().toURL()),
|
arrayOf(this.toURI().toURL()),
|
||||||
Thread.currentThread().contextClassLoader // TODO: find out why this is required
|
Thread.currentThread().contextClassLoader // TODO: find out why this is required
|
||||||
),
|
),
|
||||||
StringIterator(
|
JarFile(this)
|
||||||
JarFile(this)
|
.stream()
|
||||||
.entries()
|
.filter {it.name.endsWith(".class") && !it.name.contains("$")}
|
||||||
.toList() // TODO: find a cleaner solution than that to filter non class files
|
.map({it -> it.realName.replace('/', '.').replace(".class", "")}).iterator()
|
||||||
.filter {
|
)
|
||||||
it.name.endsWith(".class") && !it.name.contains("$")
|
|
||||||
}
|
|
||||||
.iterator()
|
|
||||||
) {
|
|
||||||
it.realName.replace('/', '.').replace(".class", "")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,8 +63,8 @@ sealed class PatchBundle(path: String) : File(path) {
|
|||||||
* Patches will be loaded to the provided [dexClassLoader].
|
* Patches will be loaded to the provided [dexClassLoader].
|
||||||
*/
|
*/
|
||||||
fun loadPatches() = loadPatches(dexClassLoader,
|
fun loadPatches() = loadPatches(dexClassLoader,
|
||||||
StringIterator(DexFileFactory.loadDexFile(path, null).classes.iterator()) { classDef ->
|
DexFileFactory.loadDexFile(path, null).classes.asSequence().map({ classDef ->
|
||||||
classDef.type.substring(1, classDef.length - 1).replace('/', '.')
|
classDef.type.substring(1, classDef.length - 1).replace('/', '.')
|
||||||
})
|
}).iterator())
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +0,0 @@
|
|||||||
package app.revanced.patcher.util.patch
|
|
||||||
|
|
||||||
internal class StringIterator<T, I : Iterator<T>>(
|
|
||||||
private val iterator: I,
|
|
||||||
private val _next: (T) -> String
|
|
||||||
) : Iterator<String> {
|
|
||||||
override fun hasNext() = iterator.hasNext()
|
|
||||||
|
|
||||||
override fun next() = _next(iterator.next())
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user