Skip to content

Commit

Permalink
fix: check if resource files exist
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jun 27, 2022
1 parent 74a39bf commit ba1f3af
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
}
Expand Down

0 comments on commit ba1f3af

Please sign in to comment.