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:
oSumAtrIX 2022-05-24 02:02:39 +02:00
parent 44e6145474
commit 7bc60943cb
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 30 additions and 29 deletions

View File

@ -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) {

View File

@ -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)