generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
Change version code
patch (#3338)
Co-authored-by: oSumAtrIX <[email protected]>
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package app.revanced.patches.all.misc.versioncode | ||
|
||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.intPatchOption | ||
import app.revanced.util.getNode | ||
import org.w3c.dom.Element | ||
|
||
@Patch( | ||
name = "Change version code", | ||
description = "Changes the version code of the app. By default the highest version code is set. " + | ||
"This allows older versions of an app to be installed " + | ||
"if their version code is set to the same or a higher value and can stop app stores to update the app.", | ||
use = false, | ||
) | ||
@Suppress("unused") | ||
object ChangeVersionCodePatch : ResourcePatch() { | ||
private val versionCode by intPatchOption( | ||
key = "versionCode", | ||
default = Int.MAX_VALUE, | ||
values = mapOf( | ||
"Lowest" to 1, | ||
"Highest" to Int.MAX_VALUE, | ||
), | ||
title = "Version code", | ||
description = "The version code to use", | ||
required = true, | ||
) { | ||
it!! >= 1 | ||
} | ||
|
||
override fun execute(context: ResourceContext) { | ||
context.document["AndroidManifest.xml"].use { document -> | ||
val manifestElement = document.getNode("manifest") as Element | ||
manifestElement.setAttribute("android:versionCode", "$versionCode") | ||
} | ||
} | ||
} |