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) {
|
if (instruction.opcode == Opcode.CONST_STRING) {
|
||||||
val stringValue = ((instruction as Instruction21c).reference as StringReference).string
|
val stringValue = ((instruction as Instruction21c).reference as StringReference).string
|
||||||
|
|
||||||
val replaceMode =
|
val replaceMode = if (stringValue == "com.google" || stringValue.startsWithAny(
|
||||||
if (stringValue.startsWith("com.google.android.gms.chimera.container")) // https://github.com/TeamVanced/VancedMicroG/pull/139/file
|
"com.google.android.gms.auth.accounts",
|
||||||
StringReplaceMode.DO_NOT_REPLACE
|
"com.google.android.gms.chimera",
|
||||||
else if (stringValue == "com.google" || stringValue.startsWithAny(
|
"com.google.android.c2dm",
|
||||||
"com.google.android.gms.auth.accounts",
|
"com.google.android.c2dm",
|
||||||
"com.google.android.gms.chimera",
|
"com.google.android.gsf",
|
||||||
"com.google.android.c2dm",
|
"com.google.android.c2dm",
|
||||||
"com.google.android.c2dm",
|
"com.google.iid",
|
||||||
"com.google.android.gsf",
|
"content://com.google.settings"
|
||||||
"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
|
||||||
StringReplaceMode.REPLACE_WITH_MICROG
|
else if (stringValue.startsWithAny(
|
||||||
} else if (stringValue.startsWithAny(
|
"com.google.android.youtube.SuggestionsProvider",
|
||||||
"com.google.android.youtube.SuggestionsProvider",
|
"com.google.android.youtube.fileprovider"
|
||||||
"com.google.android.youtube.fileprovider"
|
)
|
||||||
)
|
) {
|
||||||
) {
|
StringReplaceMode.REPLACE_WITH_REVANCED
|
||||||
StringReplaceMode.REPLACE_WITH_REVANCED
|
} else {
|
||||||
} else {
|
StringReplaceMode.DO_NOT_REPLACE
|
||||||
StringReplaceMode.DO_NOT_REPLACE
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (replaceMode != 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")
|
@Version("0.0.1")
|
||||||
class MicroGResourcePatch : ResourcePatch() {
|
class MicroGResourcePatch : ResourcePatch() {
|
||||||
override fun execute(data: ResourceData): PatchResult {
|
override fun execute(data: ResourceData): PatchResult {
|
||||||
data.writer("AndroidManifest.xml").write(
|
val manifest = data.get("AndroidManifest.xml").readText()
|
||||||
data.reader("AndroidManifest.xml").readText().replace(
|
|
||||||
|
data.get("AndroidManifest.xml").writeText(
|
||||||
|
manifest.replace(
|
||||||
"package=\"com.google.android.youtube\"", "package=\"$REVANCED_PACKAGE_NAME\""
|
"package=\"com.google.android.youtube\"", "package=\"$REVANCED_PACKAGE_NAME\""
|
||||||
).replace(
|
).replace(
|
||||||
" android:label=\"@string/application_name\" ", " android:label=\"{APP_NAME}\" "
|
" android:label=\"@string/application_name\" ", " android:label=\"{APP_NAME}\" "
|
||||||
|
@ -47,15 +49,15 @@ class MicroGResourcePatch : ResourcePatch() {
|
||||||
val replacement = arrayOf(
|
val replacement = arrayOf(
|
||||||
Pair(
|
Pair(
|
||||||
"com.google.android.youtube.SuggestionProvider", "$REVANCED_PACKAGE_NAME.SuggestionProvider"
|
"com.google.android.youtube.SuggestionProvider", "$REVANCED_PACKAGE_NAME.SuggestionProvider"
|
||||||
),
|
), Pair(
|
||||||
Pair(
|
|
||||||
"com.google.android.youtube.fileprovider", "$REVANCED_PACKAGE_NAME.fileprovider"
|
"com.google.android.youtube.fileprovider", "$REVANCED_PACKAGE_NAME.fileprovider"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
data.forEach {
|
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()
|
var content = it.readText()
|
||||||
replacement.filter { translation -> content.contains(translation.first) }.forEach { translation ->
|
replacement.filter { translation -> content.contains(translation.first) }.forEach { translation ->
|
||||||
content = content.replace(translation.first, translation.second)
|
content = content.replace(translation.first, translation.second)
|
||||||
|
|
Loading…
Reference in a new issue