mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-27 20:30:19 +02:00
fix(YouTube - Custom Shorts action buttons): Exception is thrown when patching with Revancify https://github.com/inotia00/ReVanced_Extended/issues/2773
This commit is contained in:
parent
d2ea46a613
commit
3eb3674e81
@ -215,7 +215,6 @@ val customBrandingIconPatch = resourcePatch(
|
||||
copyResources(
|
||||
"$youtubeMusicIconResourcePath/splash",
|
||||
it,
|
||||
createDirectoryIfNotExist = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import app.revanced.patches.youtube.utils.settings.settingsPatch
|
||||
import app.revanced.util.ResourceGroup
|
||||
import app.revanced.util.Utils.printInfo
|
||||
import app.revanced.util.copyResources
|
||||
import app.revanced.util.inputStreamFromBundledResourceOrThrow
|
||||
import app.revanced.util.inputStreamFromBundledResource
|
||||
import app.revanced.util.lowerCaseOrThrow
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
@ -78,18 +78,25 @@ val shortsActionButtonsPatch = resourcePatch(
|
||||
fromResourceArray.forEach { fromFileName ->
|
||||
drawableDirectories.forEach { drawableDirectory ->
|
||||
val fromFile = "$drawableDirectory/$fromFileName.webp"
|
||||
val fromPath = res.resolve(fromFile).toPath()
|
||||
val fromFileResolved = res.resolve(fromFile)
|
||||
val toFile = "$drawableDirectory/$toFileName.webp"
|
||||
val toPath = res.resolve(toFile).toPath()
|
||||
val toFileResolved = res.resolve(toFile)
|
||||
val inputStreamForLegacy =
|
||||
inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
|
||||
val inputStreamForNew =
|
||||
inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
|
||||
inputStreamFromBundledResource(sourceResourceDirectory, fromFile)
|
||||
|
||||
Files.copy(inputStreamForLegacy, fromPath, StandardCopyOption.REPLACE_EXISTING)
|
||||
// Some directory is missing in the bundles.
|
||||
if (inputStreamForLegacy != null && fromFileResolved.exists()) {
|
||||
Files.copy(inputStreamForLegacy, fromFileResolved.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
|
||||
if (is_19_36_or_greater) {
|
||||
Files.copy(inputStreamForNew, toPath, StandardCopyOption.REPLACE_EXISTING)
|
||||
val inputStreamForNew =
|
||||
inputStreamFromBundledResource(sourceResourceDirectory, fromFile)
|
||||
|
||||
// Some directory is missing in the bundles.
|
||||
if (inputStreamForNew != null && toFileResolved.exists()) {
|
||||
Files.copy(inputStreamForNew, toFileResolved.toPath(), StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -297,17 +297,14 @@ fun Node.insertNode(tagName: String, targetNode: Node, block: Element.() -> Unit
|
||||
fun ResourcePatchContext.copyResources(
|
||||
sourceResourceDirectory: String,
|
||||
vararg resources: ResourceGroup,
|
||||
createDirectoryIfNotExist: Boolean = false,
|
||||
) {
|
||||
val resourceDirectory = get("res")
|
||||
|
||||
for (resourceGroup in resources) {
|
||||
resourceGroup.resources.forEach { resource ->
|
||||
val resourceDirectoryName = resourceGroup.resourceDirectoryName
|
||||
if (createDirectoryIfNotExist) {
|
||||
val targetDirectory = resourceDirectory.resolve(resourceDirectoryName)
|
||||
if (!targetDirectory.isDirectory) Files.createDirectories(targetDirectory.toPath())
|
||||
}
|
||||
val targetDirectory = resourceDirectory.resolve(resourceDirectoryName)
|
||||
if (!targetDirectory.isDirectory) Files.createDirectories(targetDirectory.toPath())
|
||||
val resourceFile = "$resourceDirectoryName/$resource"
|
||||
inputStreamFromBundledResource(
|
||||
sourceResourceDirectory,
|
||||
@ -355,11 +352,14 @@ fun ResourcePatchContext.copyXmlNode(
|
||||
resourceDirectory,
|
||||
targetResource
|
||||
)?.let { inputStream ->
|
||||
// Copy nodes from the resources node to the real resource node
|
||||
elementTag.copyXmlNode(
|
||||
document(inputStream),
|
||||
document("res/$targetResource"),
|
||||
).close()
|
||||
val outputPath = "res/$targetResource"
|
||||
if (get(outputPath).exists()) {
|
||||
// Copy nodes from the resources node to the real resource node
|
||||
elementTag.copyXmlNode(
|
||||
document(inputStream),
|
||||
document(outputPath),
|
||||
).close()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user