fix: check if resource files exist
This commit is contained in:
parent
74a39bf074
commit
ba1f3af99b
|
@ -4,16 +4,17 @@ import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.impl.ResourceData
|
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.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultError
|
import app.revanced.patcher.patch.PatchResultError
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
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.layout.branding.header.annotations.PremiumHeadingCompatibility
|
||||||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
|
import kotlin.io.path.exists
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Dependencies(
|
@Dependencies(
|
||||||
|
@ -34,9 +35,14 @@ class PremiumHeadingPatch : ResourcePatch() {
|
||||||
arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi").forEach { size ->
|
arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi").forEach { size ->
|
||||||
val headingDirectory = resDirectory.resolve("drawable-$size")
|
val headingDirectory = resDirectory.resolve("drawable-$size")
|
||||||
modes.forEach {mode ->
|
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(
|
Files.copy(
|
||||||
headingDirectory.resolve("${original}_$mode.png").toPath(),
|
fromPath,
|
||||||
headingDirectory.resolve("${replacement}_$mode.png").toPath(),
|
toPath,
|
||||||
StandardCopyOption.REPLACE_EXISTING
|
StandardCopyOption.REPLACE_EXISTING
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue