mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
fix(Patch options): some patch options in RVX Manager are marked with custom value
This commit is contained in:
@ -3,15 +3,27 @@
|
||||
package app.revanced.util
|
||||
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.options.PatchOption
|
||||
import app.revanced.patcher.util.DomFileEditor
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.Node
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
|
||||
val classLoader: ClassLoader = object {}.javaClass.classLoader
|
||||
|
||||
fun PatchOption<String>.valueOrThrow() = value
|
||||
?: throw PatchException("Invalid patch option: $title.")
|
||||
|
||||
fun PatchOption<String>.lowerCaseOrThrow() = valueOrThrow()
|
||||
.lowercase()
|
||||
|
||||
fun PatchOption<String>.underBarOrThrow() = lowerCaseOrThrow()
|
||||
.replace(" ", "_")
|
||||
|
||||
fun Node.adoptChild(tagName: String, block: Element.() -> Unit) {
|
||||
val child = ownerDocument.createElement(tagName)
|
||||
child.block()
|
||||
@ -48,6 +60,36 @@ fun String.startsWithAny(vararg prefixes: String): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun ResourceContext.copyFile(
|
||||
resourceGroup: List<ResourceGroup>,
|
||||
path: String,
|
||||
warning: String
|
||||
): Boolean {
|
||||
resourceGroup.let { resourceGroups ->
|
||||
try {
|
||||
val filePath = File(path)
|
||||
val resourceDirectory = this["res"]
|
||||
|
||||
resourceGroups.forEach { group ->
|
||||
val fromDirectory = filePath.resolve(group.resourceDirectoryName)
|
||||
val toDirectory = resourceDirectory.resolve(group.resourceDirectoryName)
|
||||
|
||||
group.resources.forEach { iconFileName ->
|
||||
Files.write(
|
||||
toDirectory.resolve(iconFileName).toPath(),
|
||||
fromDirectory.resolve(iconFileName).readBytes()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (_: Exception) {
|
||||
println(warning)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy resources from the current class loader to the resource directory.
|
||||
*
|
||||
|
Reference in New Issue
Block a user