mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-29 05:10:20 +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(
|
copyResources(
|
||||||
"$youtubeMusicIconResourcePath/splash",
|
"$youtubeMusicIconResourcePath/splash",
|
||||||
it,
|
it,
|
||||||
createDirectoryIfNotExist = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import app.revanced.patches.youtube.utils.settings.settingsPatch
|
|||||||
import app.revanced.util.ResourceGroup
|
import app.revanced.util.ResourceGroup
|
||||||
import app.revanced.util.Utils.printInfo
|
import app.revanced.util.Utils.printInfo
|
||||||
import app.revanced.util.copyResources
|
import app.revanced.util.copyResources
|
||||||
import app.revanced.util.inputStreamFromBundledResourceOrThrow
|
import app.revanced.util.inputStreamFromBundledResource
|
||||||
import app.revanced.util.lowerCaseOrThrow
|
import app.revanced.util.lowerCaseOrThrow
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
@ -78,18 +78,25 @@ val shortsActionButtonsPatch = resourcePatch(
|
|||||||
fromResourceArray.forEach { fromFileName ->
|
fromResourceArray.forEach { fromFileName ->
|
||||||
drawableDirectories.forEach { drawableDirectory ->
|
drawableDirectories.forEach { drawableDirectory ->
|
||||||
val fromFile = "$drawableDirectory/$fromFileName.webp"
|
val fromFile = "$drawableDirectory/$fromFileName.webp"
|
||||||
val fromPath = res.resolve(fromFile).toPath()
|
val fromFileResolved = res.resolve(fromFile)
|
||||||
val toFile = "$drawableDirectory/$toFileName.webp"
|
val toFile = "$drawableDirectory/$toFileName.webp"
|
||||||
val toPath = res.resolve(toFile).toPath()
|
val toFileResolved = res.resolve(toFile)
|
||||||
val inputStreamForLegacy =
|
val inputStreamForLegacy =
|
||||||
inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
|
inputStreamFromBundledResource(sourceResourceDirectory, fromFile)
|
||||||
val inputStreamForNew =
|
|
||||||
inputStreamFromBundledResourceOrThrow(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) {
|
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(
|
fun ResourcePatchContext.copyResources(
|
||||||
sourceResourceDirectory: String,
|
sourceResourceDirectory: String,
|
||||||
vararg resources: ResourceGroup,
|
vararg resources: ResourceGroup,
|
||||||
createDirectoryIfNotExist: Boolean = false,
|
|
||||||
) {
|
) {
|
||||||
val resourceDirectory = get("res")
|
val resourceDirectory = get("res")
|
||||||
|
|
||||||
for (resourceGroup in resources) {
|
for (resourceGroup in resources) {
|
||||||
resourceGroup.resources.forEach { resource ->
|
resourceGroup.resources.forEach { resource ->
|
||||||
val resourceDirectoryName = resourceGroup.resourceDirectoryName
|
val resourceDirectoryName = resourceGroup.resourceDirectoryName
|
||||||
if (createDirectoryIfNotExist) {
|
val targetDirectory = resourceDirectory.resolve(resourceDirectoryName)
|
||||||
val targetDirectory = resourceDirectory.resolve(resourceDirectoryName)
|
if (!targetDirectory.isDirectory) Files.createDirectories(targetDirectory.toPath())
|
||||||
if (!targetDirectory.isDirectory) Files.createDirectories(targetDirectory.toPath())
|
|
||||||
}
|
|
||||||
val resourceFile = "$resourceDirectoryName/$resource"
|
val resourceFile = "$resourceDirectoryName/$resource"
|
||||||
inputStreamFromBundledResource(
|
inputStreamFromBundledResource(
|
||||||
sourceResourceDirectory,
|
sourceResourceDirectory,
|
||||||
@ -355,11 +352,14 @@ fun ResourcePatchContext.copyXmlNode(
|
|||||||
resourceDirectory,
|
resourceDirectory,
|
||||||
targetResource
|
targetResource
|
||||||
)?.let { inputStream ->
|
)?.let { inputStream ->
|
||||||
// Copy nodes from the resources node to the real resource node
|
val outputPath = "res/$targetResource"
|
||||||
elementTag.copyXmlNode(
|
if (get(outputPath).exists()) {
|
||||||
document(inputStream),
|
// Copy nodes from the resources node to the real resource node
|
||||||
document("res/$targetResource"),
|
elementTag.copyXmlNode(
|
||||||
).close()
|
document(inputStream),
|
||||||
|
document(outputPath),
|
||||||
|
).close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user