mirror of
https://github.com/revanced/revanced-patches
synced 2024-09-02 12:35:16 +02:00
fix: write while reading resources and remove checking for "." in resource extensions
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
44e6145474
commit
7bc60943cb
@ -59,30 +59,29 @@ class MicroGBytecodePatch : BytecodePatch(
|
||||
if (instruction.opcode == Opcode.CONST_STRING) {
|
||||
val stringValue = ((instruction as Instruction21c).reference as StringReference).string
|
||||
|
||||
val replaceMode =
|
||||
if (stringValue.startsWith("com.google.android.gms.chimera.container")) // https://github.com/TeamVanced/VancedMicroG/pull/139/file
|
||||
StringReplaceMode.DO_NOT_REPLACE
|
||||
else if (stringValue == "com.google" || stringValue.startsWithAny(
|
||||
"com.google.android.gms.auth.accounts",
|
||||
"com.google.android.gms.chimera",
|
||||
"com.google.android.c2dm",
|
||||
"com.google.android.c2dm",
|
||||
"com.google.android.gsf",
|
||||
"com.google.android.c2dm",
|
||||
"com.google.iid",
|
||||
"content://com.google.settings"
|
||||
)
|
||||
) {
|
||||
StringReplaceMode.REPLACE_WITH_MICROG
|
||||
} else if (stringValue.startsWithAny(
|
||||
"com.google.android.youtube.SuggestionsProvider",
|
||||
"com.google.android.youtube.fileprovider"
|
||||
)
|
||||
) {
|
||||
StringReplaceMode.REPLACE_WITH_REVANCED
|
||||
} else {
|
||||
StringReplaceMode.DO_NOT_REPLACE
|
||||
}
|
||||
val replaceMode = if (stringValue == "com.google" || stringValue.startsWithAny(
|
||||
"com.google.android.gms.auth.accounts",
|
||||
"com.google.android.gms.chimera",
|
||||
"com.google.android.c2dm",
|
||||
"com.google.android.c2dm",
|
||||
"com.google.android.gsf",
|
||||
"com.google.android.c2dm",
|
||||
"com.google.iid",
|
||||
"content://com.google.settings"
|
||||
)
|
||||
) {
|
||||
StringReplaceMode.REPLACE_WITH_MICROG
|
||||
} else if (stringValue.startsWith("com.google.android.gms.chimera.container")) // https://github.com/TeamVanced/VancedMicroG/pull/139/file
|
||||
StringReplaceMode.DO_NOT_REPLACE
|
||||
else if (stringValue.startsWithAny(
|
||||
"com.google.android.youtube.SuggestionsProvider",
|
||||
"com.google.android.youtube.fileprovider"
|
||||
)
|
||||
) {
|
||||
StringReplaceMode.REPLACE_WITH_REVANCED
|
||||
} else {
|
||||
StringReplaceMode.DO_NOT_REPLACE
|
||||
}
|
||||
|
||||
|
||||
if (replaceMode != StringReplaceMode.DO_NOT_REPLACE) {
|
||||
|
@ -19,8 +19,10 @@ import app.revanced.patches.youtube.misc.microg.shared.Constants.REVANCED_PACKAG
|
||||
@Version("0.0.1")
|
||||
class MicroGResourcePatch : ResourcePatch() {
|
||||
override fun execute(data: ResourceData): PatchResult {
|
||||
data.writer("AndroidManifest.xml").write(
|
||||
data.reader("AndroidManifest.xml").readText().replace(
|
||||
val manifest = data.get("AndroidManifest.xml").readText()
|
||||
|
||||
data.get("AndroidManifest.xml").writeText(
|
||||
manifest.replace(
|
||||
"package=\"com.google.android.youtube\"", "package=\"$REVANCED_PACKAGE_NAME\""
|
||||
).replace(
|
||||
" android:label=\"@string/application_name\" ", " android:label=\"{APP_NAME}\" "
|
||||
@ -47,15 +49,15 @@ class MicroGResourcePatch : ResourcePatch() {
|
||||
val replacement = arrayOf(
|
||||
Pair(
|
||||
"com.google.android.youtube.SuggestionProvider", "$REVANCED_PACKAGE_NAME.SuggestionProvider"
|
||||
),
|
||||
Pair(
|
||||
), Pair(
|
||||
"com.google.android.youtube.fileprovider", "$REVANCED_PACKAGE_NAME.fileprovider"
|
||||
)
|
||||
)
|
||||
|
||||
data.forEach {
|
||||
if (it.extension != ".xml") return@forEach
|
||||
if (it.extension != "xml") return@forEach
|
||||
|
||||
// TODO: use a reader and only replace strings where needed instead of reading & writing the entire file
|
||||
var content = it.readText()
|
||||
replacement.filter { translation -> content.contains(translation.first) }.forEach { translation ->
|
||||
content = content.replace(translation.first, translation.second)
|
||||
|
Loading…
Reference in New Issue
Block a user