Skip to content

Commit b34a1ab

Browse files
Revert commit until it's fixed
This reverts commit 5f2f61a.
1 parent 5f2f61a commit b34a1ab

File tree

2 files changed

+32
-56
lines changed

2 files changed

+32
-56
lines changed

patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package app.revanced.patches.shared.layout.branding
22

3-
import app.revanced.patcher.patch.PatchException
43
import app.revanced.patcher.patch.ResourcePatch
54
import app.revanced.patcher.patch.ResourcePatchBuilder
65
import app.revanced.patcher.patch.ResourcePatchContext
@@ -15,7 +14,7 @@ import java.util.logging.Logger
1514

1615
private 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.
Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package app.revanced.patches.youtube.layout.branding
22

33
import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch
4-
import app.revanced.patches.shared.layout.branding.mipmapDirectories
54
import java.nio.file.Files
65

76
private const val APP_NAME = "YouTube ReVanced"
87

9-
private const val ADAPTIVE_BACKGROUND_RESOURCE_NAME = "adaptiveproduct_youtube_background_color_108"
10-
private const val ADAPTIVE_FOREGROUND_RESOURCE_NAME = "adaptiveproduct_youtube_foreground_color_108"
8+
private const val ADAPTIVE_BACKGROUND_RESOURCE_FILE_NAME = "adaptiveproduct_youtube_background_color_108.xml"
9+
private const val ADAPTIVE_FOREGROUND_RESOURCE_FILE_NAME = "adaptiveproduct_youtube_foreground_color_108.xml"
1110

1211
@Suppress("unused")
1312
val customBrandingPatch = baseCustomBrandingPatch(
@@ -30,8 +29,8 @@ val customBrandingPatch = baseCustomBrandingPatch(
3029
"ringo2_adaptive_monochrome_ic_youtube_launcher.xml"
3130
),
3231
adaptiveIconFileNames = arrayOf(
33-
ADAPTIVE_BACKGROUND_RESOURCE_NAME,
34-
ADAPTIVE_FOREGROUND_RESOURCE_NAME,
32+
ADAPTIVE_BACKGROUND_RESOURCE_FILE_NAME,
33+
ADAPTIVE_FOREGROUND_RESOURCE_FILE_NAME,
3534
),
3635
legacyIconResourceFileNames = arrayOf(
3736
"ic_launcher",
@@ -50,34 +49,17 @@ val customBrandingPatch = baseCustomBrandingPatch(
5049
},
5150

5251
executeBlock = {
53-
val resourceDirectory = get("res")
52+
val resourceDirectory = get("res/mipmap-anydpi")
5453

5554
// Copy adaptive icon to secondary adaptive file.
5655
arrayOf(
57-
ADAPTIVE_BACKGROUND_RESOURCE_NAME to "adaptiveproduct_youtube_2024_q4_background_color_108",
58-
ADAPTIVE_FOREGROUND_RESOURCE_NAME to "adaptiveproduct_youtube_2024_q4_foreground_color_108",
56+
ADAPTIVE_BACKGROUND_RESOURCE_FILE_NAME to "adaptiveproduct_youtube_2024_q4_background_color_108.xml",
57+
ADAPTIVE_FOREGROUND_RESOURCE_FILE_NAME to "adaptiveproduct_youtube_2024_q4_foreground_color_108.xml",
5958
).forEach { (old, new) ->
60-
val newFile = resourceDirectory.resolve("/mipmap-anydpi/$new.xml")
61-
if (newFile.exists()) {
62-
val oldFile = resourceDirectory.resolve("$old.xml")
63-
Files.write(oldFile.toPath(), newFile.readBytes())
64-
}
65-
}
66-
67-
// Copy mipmaps to secondary files.
68-
mipmapDirectories.forEach { directory ->
69-
val targetDirectory = resourceDirectory.resolve(directory)
59+
val oldFile = resourceDirectory.resolve(old)
60+
val newFile = resourceDirectory.resolve(new)
7061

71-
arrayOf(
72-
ADAPTIVE_BACKGROUND_RESOURCE_NAME to "adaptiveproduct_youtube_2024_q4_background_color_108",
73-
ADAPTIVE_FOREGROUND_RESOURCE_NAME to "adaptiveproduct_youtube_2024_q4_foreground_color_108",
74-
).forEach { (old, new) ->
75-
val newFile = targetDirectory.resolve("$new.png")
76-
if (newFile.exists()) {
77-
val oldFile = targetDirectory.resolve("$old.png")
78-
Files.write(newFile.toPath(), oldFile.readBytes())
79-
}
80-
}
62+
Files.write(newFile.toPath(), oldFile.readBytes())
8163
}
8264
}
8365
)

0 commit comments

Comments
 (0)