From 1748d1e5badf61213d793ff7ae1d090ea2ea82f0 Mon Sep 17 00:00:00 2001 From: Sculas Date: Tue, 2 Aug 2022 23:48:51 +0200 Subject: [PATCH] feat: add "Application Icon Path" option to branding --- .../icon/patch/CustomBrandingPatch.kt | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt index 6c16d32f..e6f09c99 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/branding/icon/patch/CustomBrandingPatch.kt @@ -10,6 +10,9 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patches.youtube.layout.branding.icon.annotations.CustomBrandingCompatibility import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch +import java.io.File +import java.io.FileInputStream +import java.io.InputStream import java.nio.file.Files @Patch @@ -39,7 +42,7 @@ class CustomBrandingPatch : ResourcePatch() { "mdpi" to 48 ).forEach { (iconDirectory, size) -> iconNames.forEach iconLoop@{ iconName -> - val iconFile = this.javaClass.classLoader.getResourceAsStream("branding/$size/$iconName.png") + val iconFile = getIconStream("branding/$size/$iconName.png") ?: return PatchResultError("The icon $iconName can not be found.") Files.write( @@ -50,7 +53,7 @@ class CustomBrandingPatch : ResourcePatch() { } // Name branding - val appName = options[keyAppName].value + val appName: String by options[keyAppName] val manifest = data["AndroidManifest.xml"] manifest.writeText( @@ -71,10 +74,27 @@ class CustomBrandingPatch : ResourcePatch() { title = "Application Name", description = "The name of the application it will show on your home screen.", required = true + ), + PatchOption.StringOption( + key = keyAppIconPath, + default = null, + title = "Application Icon Path", + description = "A path to the icon of the application." ) ) + private fun getIconStream(iconPath: String): InputStream? { + val appIconPath: String? by options[keyAppIconPath] + if (appIconPath == null) { + return this.javaClass.classLoader.getResourceAsStream(iconPath) + } + val file = File(appIconPath!!).resolve(iconPath) + if (!file.exists()) return null + return FileInputStream(file) + } + private companion object { private const val keyAppName = "appName" + private const val keyAppIconPath = "appIconPath" } }