diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt index 90780c724..537ee6df4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/branding/icon/CustomBrandingIconPatch.kt @@ -215,7 +215,6 @@ val customBrandingIconPatch = resourcePatch( copyResources( "$youtubeMusicIconResourcePath/splash", it, - createDirectoryIfNotExist = true ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/actionbuttons/ShortsActionButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/actionbuttons/ShortsActionButtonsPatch.kt index a955491e1..af1a960b9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/actionbuttons/ShortsActionButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/actionbuttons/ShortsActionButtonsPatch.kt @@ -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) + } } } } diff --git a/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt b/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt index 9f172b065..3a1912113 100644 --- a/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt +++ b/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt @@ -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() + } } /**