11package app.revanced.patches.shared.layout.branding
22
3- import app.revanced.patcher.patch.PatchException
43import app.revanced.patcher.patch.ResourcePatch
54import app.revanced.patcher.patch.ResourcePatchBuilder
65import app.revanced.patcher.patch.ResourcePatchContext
@@ -15,7 +14,7 @@ import java.util.logging.Logger
1514
1615private const val REVANCED_ICON = " ReVanced*Logo" // Can never be a valid path.
1716
18- internal val mipmapDirectories = arrayOf(
17+ private val mipmapDirectories = arrayOf(
1918 // Target app does not have ldpi icons.
2019 " mdpi" ,
2120 " hdpi" ,
@@ -84,13 +83,16 @@ internal fun baseCustomBrandingPatch(
8483 description = """
8584 The icon to apply to the app.
8685
87- If a path to a folder is provided, the folder must contain one or more of the following folders:
86+ If a path to a folder is provided, the folder must contain the following folders:
87+
8888 ${formatResourceFileList(mipmapDirectories)}
8989
9090 Each of these folders must contain the following files:
91+
9192 ${formatResourceFileList((iconResourceFileNamesPng + legacyIconResourceFileNamesPng))}
9293
9394 Optionally, a 'drawable' folder with the monochrome icon files:
95+
9496 ${formatResourceFileList(monochromeIconFileNames)}
9597 """ .trimIndentMultiline(),
9698 )
@@ -125,48 +127,40 @@ internal fun baseCustomBrandingPatch(
125127 ResourceGroup (" mipmap-anydpi" , * adaptiveIconFileNames)
126128 )
127129 } else {
128- val filePath = File (iconPathTrimmed)
129- val resourceDirectory = get(" res" )
130- var replacedResources = false
131-
132- // Replace mipmap icons.
133- mipmapDirectories.map { directory ->
130+ val mipmapIconResourceGroups = mipmapDirectories.map { directory ->
134131 ResourceGroup (
135132 directory,
136133 * iconResourceFileNamesPng,
137134 )
138- }.forEach { groupResources ->
135+ }
136+
137+ val filePath = File (iconPathTrimmed)
138+ val resourceDirectory = get(" res" )
139+
140+ // Replace mipmap icons.
141+ mipmapIconResourceGroups.forEach { groupResources ->
139142 val groupResourceDirectoryName = groupResources.resourceDirectoryName
140143 val fromDirectory = filePath.resolve(groupResourceDirectoryName)
141144 val toDirectory = resourceDirectory.resolve(groupResourceDirectoryName)
142145
143146 groupResources.resources.forEach { iconFileName ->
144- val replacement = fromDirectory.resolve(iconFileName)
145- if (replacement.exists()) {
146- Files .write(
147- toDirectory.resolve(iconFileName).toPath(),
148- replacement.readBytes(),
149- )
150- replacedResources = true
151- }
147+ Files .write(
148+ toDirectory.resolve(iconFileName).toPath(),
149+ fromDirectory.resolve(iconFileName).readBytes(),
150+ )
152151 }
153152 }
154153
155154 // Replace monochrome icons if provided.
156- monochromeIconFileNames.forEach { iconFileName ->
157- val replacement = filePath.resolve(" drawable" ).resolve(iconFileName )
158- if (replacement .exists()) {
155+ monochromeIconFileNames.forEach { fileName ->
156+ val replacementMonochrome = filePath.resolve(" drawable" ).resolve(fileName )
157+ if (replacementMonochrome .exists()) {
159158 Files .write(
160- resourceDirectory.resolve(" drawable" ).resolve(iconFileName ).toPath(),
161- replacement .readBytes(),
159+ resourceDirectory.resolve(" drawable" ).resolve(fileName ).toPath(),
160+ replacementMonochrome .readBytes(),
162161 )
163- replacedResources = true
164162 }
165163 }
166-
167- if (! replacedResources) {
168- throw PatchException (" Could not find any replacement images in patch option path: $iconPathTrimmed " )
169- }
170164 }
171165
172166 // Change the app name.
0 commit comments