From b81392a2d4e96df53708761bf17613d8c32561fe Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:52:06 +0900 Subject: [PATCH] fix(Custom branding icon): displays an appropriate error if the path to patch options is invalid --- .../branding/icon/CustomBrandingIconPatch.kt | 24 ++++++++++------- .../branding/icon/CustomBrandingIconPatch.kt | 26 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/music/general/branding/icon/CustomBrandingIconPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/branding/icon/CustomBrandingIconPatch.kt index 99d6d1443..4678b8aa6 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/branding/icon/CustomBrandingIconPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/branding/icon/CustomBrandingIconPatch.kt @@ -68,19 +68,23 @@ object CustomBrandingIconPatch : ResourcePatch() { directory, *mipmapIconResourceFileNames ) }.let { resourceGroups -> - val path = File(appIcon) - val resourceDirectory = context["res"] + try { + val path = File(appIcon) + val resourceDirectory = context["res"] - resourceGroups.forEach { group -> - val fromDirectory = path.resolve(group.resourceDirectoryName) - val toDirectory = resourceDirectory.resolve(group.resourceDirectoryName) + resourceGroups.forEach { group -> + val fromDirectory = path.resolve(group.resourceDirectoryName) + val toDirectory = resourceDirectory.resolve(group.resourceDirectoryName) - group.resources.forEach { iconFileName -> - Files.write( - toDirectory.resolve(iconFileName).toPath(), - fromDirectory.resolve(iconFileName).readBytes() - ) + group.resources.forEach { iconFileName -> + Files.write( + toDirectory.resolve(iconFileName).toPath(), + fromDirectory.resolve(iconFileName).readBytes() + ) + } } + } catch (_: Exception) { + throw PatchException("Invalid app icon path: $appIcon") } } } else { diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt index c1208f924..05eb6b8fb 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/CustomBrandingIconPatch.kt @@ -113,21 +113,25 @@ object CustomBrandingIconPatch : ResourcePatch() { directory, *mipmapIconResourceFileNames ) }.let { resourceGroups -> - val path = File(appIcon) - val resourceDirectory = context["res"] + try { + val path = File(appIcon) + val resourceDirectory = context["res"] - resourceGroups.forEach { group -> - val fromDirectory = path.resolve(group.resourceDirectoryName) - val toDirectory = resourceDirectory.resolve(group.resourceDirectoryName) + resourceGroups.forEach { group -> + val fromDirectory = path.resolve(group.resourceDirectoryName) + val toDirectory = resourceDirectory.resolve(group.resourceDirectoryName) - group.resources.forEach { iconFileName -> - Files.write( - toDirectory.resolve(iconFileName).toPath(), - fromDirectory.resolve(iconFileName).readBytes() - ) + group.resources.forEach { iconFileName -> + Files.write( + toDirectory.resolve(iconFileName).toPath(), + fromDirectory.resolve(iconFileName).readBytes() + ) + } } + context.updatePatchStatusIcon("custom") + } catch (_: Exception) { + throw PatchException("Invalid app icon path: $appIcon") } - context.updatePatchStatusIcon("custom") } } else { val resourcePath = "youtube/branding/$appIconValue"