From ba1f3af99be58edc44ed1b8f1875508d5034efd8 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 28 Jun 2022 00:39:51 +0200 Subject: [PATCH] fix: check if resource files exist --- .../branding/header/patch/PremiumHeadingPatch.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/patch/PremiumHeadingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/patch/PremiumHeadingPatch.kt index d852bd84..5173dcb7 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/patch/PremiumHeadingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/patch/PremiumHeadingPatch.kt @@ -4,16 +4,17 @@ import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.impl.ResourceData -import app.revanced.patcher.patch.annotations.Dependencies -import app.revanced.patcher.patch.annotations.Patch -import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Dependencies +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patches.youtube.layout.branding.header.annotations.PremiumHeadingCompatibility import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch import java.nio.file.Files import java.nio.file.StandardCopyOption +import kotlin.io.path.exists @Patch @Dependencies( @@ -34,9 +35,14 @@ class PremiumHeadingPatch : ResourcePatch() { arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi").forEach { size -> val headingDirectory = resDirectory.resolve("drawable-$size") modes.forEach {mode -> + val fromPath = headingDirectory.resolve("${original}_$mode.png").toPath() + val toPath = headingDirectory.resolve("${replacement}_$mode.png").toPath() + + if (!fromPath.exists()) + return PatchResultError("The file $fromPath does not exist in the resources. Therefore, this patch can not succeed.") Files.copy( - headingDirectory.resolve("${original}_$mode.png").toPath(), - headingDirectory.resolve("${replacement}_$mode.png").toPath(), + fromPath, + toPath, StandardCopyOption.REPLACE_EXISTING ) }