mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-18 00:43:58 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecd5147590 | ||
|
|
ca255c9e1b | ||
|
|
e9aa490355 | ||
|
|
69fe59f97b | ||
|
|
995e1712bc | ||
|
|
a236f10bb0 | ||
|
|
4a6134ea60 | ||
|
|
b084024742 | ||
|
|
2ef48af1b3 | ||
|
|
da2c91874d | ||
|
|
379687c814 | ||
|
|
2f5577e464 | ||
|
|
6962fc2f4c | ||
|
|
a6cef26210 | ||
|
|
b4892c4413 | ||
|
|
90368405ad | ||
|
|
26967959e2 | ||
|
|
eac6f6fbe3 | ||
|
|
af4ec43352 | ||
|
|
4f5644b62c | ||
|
|
31fb3166d9 | ||
|
|
a76bd0ad35 | ||
|
|
ba07ab1ac2 | ||
|
|
92bf57f279 |
2
.github/config.yml
vendored
Normal file
2
.github/config.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
firstPRMergeComment: >
|
||||||
|
Thank you for contributing to ReVanced. Join us on [Discord](https://revanced.app/discord) if you want to receive a contributor role.
|
||||||
1
.github/workflows/update-documentation.yml
vendored
1
.github/workflows/update-documentation.yml
vendored
@@ -9,6 +9,7 @@ jobs:
|
|||||||
trigger:
|
trigger:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Dispatch event to documentation repository
|
name: Dispatch event to documentation repository
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: peter-evans/repository-dispatch@v2
|
- uses: peter-evans/repository-dispatch@v2
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -7,7 +7,13 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"@semantic-release/commit-analyzer",
|
[
|
||||||
|
"@semantic-release/commit-analyzer", {
|
||||||
|
"releaseRules": [
|
||||||
|
{ "type": "build", "scope": "revanced-patcher", "release": "patch" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"@semantic-release/release-notes-generator",
|
"@semantic-release/release-notes-generator",
|
||||||
"@semantic-release/changelog",
|
"@semantic-release/changelog",
|
||||||
"gradle-semantic-release-plugin",
|
"gradle-semantic-release-plugin",
|
||||||
|
|||||||
44
CHANGELOG.md
44
CHANGELOG.md
@@ -1,3 +1,47 @@
|
|||||||
|
## [2.21.1](https://github.com/revanced/revanced-cli/compare/v2.21.0...v2.21.1) (2023-05-06)
|
||||||
|
|
||||||
|
## [2.21.1-dev.1](https://github.com/revanced/revanced-cli/compare/v2.21.0...v2.21.1-dev.1) (2023-05-06)
|
||||||
|
|
||||||
|
# [2.21.0](https://github.com/revanced/revanced-cli/compare/v2.20.2...v2.21.0) (2023-05-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **tests:** set order of tests ([2ef48af](https://github.com/revanced/revanced-cli/commit/2ef48af1b339ab729a05d69cb0c8c1ee1e3ab486))
|
||||||
|
* use working JADB dependency version ([#222](https://github.com/revanced/revanced-cli/issues/222)) ([da2c918](https://github.com/revanced/revanced-cli/commit/da2c91874d5623402febfcc0677ada3d648565e1))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add appreciation message for new contributors ([6962fc2](https://github.com/revanced/revanced-cli/commit/6962fc2f4c0f0c96e88a823be64f8ebd1312ee17))
|
||||||
|
|
||||||
|
# [2.21.0-dev.1](https://github.com/revanced/revanced-cli/compare/v2.20.2...v2.21.0-dev.1) (2023-05-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **tests:** set order of tests ([2ef48af](https://github.com/revanced/revanced-cli/commit/2ef48af1b339ab729a05d69cb0c8c1ee1e3ab486))
|
||||||
|
* use working JADB dependency version ([#222](https://github.com/revanced/revanced-cli/issues/222)) ([da2c918](https://github.com/revanced/revanced-cli/commit/da2c91874d5623402febfcc0677ada3d648565e1))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add appreciation message for new contributors ([6962fc2](https://github.com/revanced/revanced-cli/commit/6962fc2f4c0f0c96e88a823be64f8ebd1312ee17))
|
||||||
|
|
||||||
|
## [2.20.2](https://github.com/revanced/revanced-cli/compare/v2.20.1...v2.20.2) (2023-04-30)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* correct spelling mistake ([31fb316](https://github.com/revanced/revanced-cli/commit/31fb3166d922ae1f568f52e44cbe726dd1c891a4))
|
||||||
|
|
||||||
|
## [2.20.2-dev.1](https://github.com/revanced/revanced-cli/compare/v2.20.1...v2.20.2-dev.1) (2023-04-03)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* correct spelling mistake ([31fb316](https://github.com/revanced/revanced-cli/commit/31fb3166d922ae1f568f52e44cbe726dd1c891a4))
|
||||||
|
|
||||||
## [2.20.1](https://github.com/revanced/revanced-cli/compare/v2.20.0...v2.20.1) (2023-03-14)
|
## [2.20.1](https://github.com/revanced/revanced-cli/compare/v2.20.0...v2.20.1) (2023-03-14)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.7.0"
|
kotlin("jvm") version "1.8.10"
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.2"
|
id("com.github.johnrengelman.shadow") version "7.1.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,17 +23,24 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("reflect"))
|
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20-RC")
|
||||||
|
|
||||||
implementation("app.revanced:revanced-patcher:7.0.0")
|
implementation("app.revanced:revanced-patcher:7.1.0")
|
||||||
implementation("info.picocli:picocli:4.7.0")
|
implementation("info.picocli:picocli:4.7.1")
|
||||||
implementation("com.github.revanced:jadb:master-SNAPSHOT") // updated fork
|
implementation("com.github.revanced:jadb:2531a28109") // updated fork
|
||||||
implementation("com.android.tools.build:apksig:7.2.2")
|
implementation("com.android.tools.build:apksig:8.1.0-alpha09")
|
||||||
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
|
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
|
||||||
implementation("cc.ekblad:4koma:1.1.0")
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.+")
|
||||||
|
testImplementation("org.jetbrains.kotlin:kotlin-test:1.8.20-RC")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
testLogging {
|
||||||
|
events("PASSED", "SKIPPED", "FAILED")
|
||||||
|
}
|
||||||
|
}
|
||||||
build {
|
build {
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 🛠️ Using the ReVanced CLI
|
# 🛠️ Using the ReVanced CLI
|
||||||
|
|
||||||
Lean how to use the ReVanced CLI.
|
Learn how to use the ReVanced CLI.
|
||||||
|
|
||||||
## ⚡ Setup (optional)
|
## ⚡ Setup (optional)
|
||||||
|
|
||||||
@@ -43,7 +43,6 @@ Lean how to use the ReVanced CLI.
|
|||||||
```bash
|
```bash
|
||||||
java -jar revanced-cli.jar \
|
java -jar revanced-cli.jar \
|
||||||
-a input.apk \
|
-a input.apk \
|
||||||
-c \
|
|
||||||
-o patched-output.apk \
|
-o patched-output.apk \
|
||||||
-b revanced-patches.jar
|
-b revanced-patches.jar
|
||||||
```
|
```
|
||||||
@@ -54,19 +53,18 @@ Lean how to use the ReVanced CLI.
|
|||||||
adb install input.apk # make sure the same version is installed
|
adb install input.apk # make sure the same version is installed
|
||||||
java -jar revanced-cli.jar \
|
java -jar revanced-cli.jar \
|
||||||
-a input.apk \
|
-a input.apk \
|
||||||
-c \
|
|
||||||
-d device-name \
|
-d device-name \
|
||||||
-o patched-output.apk \
|
-o patched-output.apk \
|
||||||
-b revanced-patches.jar \
|
-b revanced-patches.jar \
|
||||||
-e microg-support \
|
-e vanced-microg-support \
|
||||||
--mount
|
--mount
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Note**:
|
> **Note**:
|
||||||
>
|
>
|
||||||
> - If you want to exclude patches, you can use the option `-e`. In the case of YouTube, you can exclude
|
> - If you want to exclude patches, you can use the option `-e`. In the case of YouTube, you can exclude
|
||||||
the `microg-support` patch from [ReVanced Patches](https://github.com/revanced/revanced-patches) with the
|
the `vanced-microg-support` patch from [ReVanced Patches](https://github.com/revanced/revanced-patches) with the
|
||||||
option `-e microg-support` when mounting for example.
|
option `-e vanced-microg-support` when mounting for example.
|
||||||
>
|
>
|
||||||
> - Some patches from [ReVanced Patches](https://github.com/revanced/revanced-patches) also might require
|
> - Some patches from [ReVanced Patches](https://github.com/revanced/revanced-patches) also might require
|
||||||
[ReVanced Integrations](https://github.com/revanced/revanced-integrations). Supply them with the option `-m`.
|
[ReVanced Integrations](https://github.com/revanced/revanced-integrations). Supply them with the option `-m`.
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 2.20.1
|
version = 2.21.1
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -7,16 +7,24 @@ import app.revanced.cli.patcher.logging.impl.PatcherLogger
|
|||||||
import app.revanced.cli.signing.Signing
|
import app.revanced.cli.signing.Signing
|
||||||
import app.revanced.cli.signing.SigningOptions
|
import app.revanced.cli.signing.SigningOptions
|
||||||
import app.revanced.patcher.PatcherOptions
|
import app.revanced.patcher.PatcherOptions
|
||||||
|
import app.revanced.patcher.data.Context
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.description
|
import app.revanced.patcher.extensions.PatchExtensions.description
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
|
import app.revanced.patcher.patch.Patch
|
||||||
import app.revanced.patcher.util.patch.PatchBundle
|
import app.revanced.patcher.util.patch.PatchBundle
|
||||||
import app.revanced.utils.OptionsLoader
|
import app.revanced.utils.Options
|
||||||
|
import app.revanced.utils.Options.setOptions
|
||||||
import app.revanced.utils.adb.Adb
|
import app.revanced.utils.adb.Adb
|
||||||
import picocli.CommandLine.*
|
import picocli.CommandLine.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for return type of [PatchBundle.loadPatches].
|
||||||
|
*/
|
||||||
|
internal typealias PatchList = List<Class<out Patch<Context>>>
|
||||||
|
|
||||||
private class CLIVersionProvider : IVersionProvider {
|
private class CLIVersionProvider : IVersionProvider {
|
||||||
override fun getVersion() = arrayOf(
|
override fun getVersion() = arrayOf(
|
||||||
MainCommand::class.java.`package`.implementationVersion ?: "unknown"
|
MainCommand::class.java.`package`.implementationVersion ?: "unknown"
|
||||||
@@ -55,8 +63,8 @@ internal object MainCommand : Runnable {
|
|||||||
@Option(names = ["-b", "--bundle"], description = ["One or more bundles of patches"], required = true)
|
@Option(names = ["-b", "--bundle"], description = ["One or more bundles of patches"], required = true)
|
||||||
var patchBundles = arrayOf<String>()
|
var patchBundles = arrayOf<String>()
|
||||||
|
|
||||||
@Option(names = ["--options"], description = ["Configuration file for all patch options"])
|
@Option(names = ["--options"], description = ["Path to patch options JSON file"])
|
||||||
var options: File = File("options.toml")
|
var optionsFile: File = File("options.json")
|
||||||
|
|
||||||
@ArgGroup(exclusive = false)
|
@ArgGroup(exclusive = false)
|
||||||
var listingArgs: ListingArgs? = null
|
var listingArgs: ListingArgs? = null
|
||||||
@@ -134,7 +142,10 @@ internal object MainCommand : Runnable {
|
|||||||
PatchBundle.Jar(bundle).loadPatches()
|
PatchBundle.Jar(bundle).loadPatches()
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionsLoader.init(args.patchArgs!!.options, allPatches)
|
args.patchArgs!!.optionsFile.let {
|
||||||
|
if (it.exists()) allPatches.setOptions(it, logger)
|
||||||
|
else Options.serialize(allPatches, prettyPrint = true).let(it::writeText)
|
||||||
|
}
|
||||||
|
|
||||||
val patcher = app.revanced.patcher.Patcher(
|
val patcher = app.revanced.patcher.Patcher(
|
||||||
PatcherOptions(
|
PatcherOptions(
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package app.revanced.cli.patcher
|
package app.revanced.cli.patcher
|
||||||
|
|
||||||
|
import app.revanced.cli.command.PatchList
|
||||||
import app.revanced.patcher.PatcherResult
|
import app.revanced.patcher.PatcherResult
|
||||||
import app.revanced.patcher.data.Context
|
|
||||||
import app.revanced.patcher.patch.Patch
|
|
||||||
import app.revanced.utils.patcher.addPatchesFiltered
|
import app.revanced.utils.patcher.addPatchesFiltered
|
||||||
import app.revanced.utils.patcher.applyPatchesVerbose
|
import app.revanced.utils.patcher.applyPatchesVerbose
|
||||||
import app.revanced.utils.patcher.mergeFiles
|
import app.revanced.utils.patcher.mergeFiles
|
||||||
@@ -10,7 +9,7 @@ import app.revanced.utils.patcher.mergeFiles
|
|||||||
internal object Patcher {
|
internal object Patcher {
|
||||||
internal fun start(
|
internal fun start(
|
||||||
patcher: app.revanced.patcher.Patcher,
|
patcher: app.revanced.patcher.Patcher,
|
||||||
allPatches: List<Class<out Patch<Context>>>
|
allPatches: PatchList
|
||||||
): PatcherResult {
|
): PatcherResult {
|
||||||
// merge files like necessary integrations
|
// merge files like necessary integrations
|
||||||
patcher.mergeFiles()
|
patcher.mergeFiles()
|
||||||
|
|||||||
103
src/main/kotlin/app/revanced/utils/Options.kt
Normal file
103
src/main/kotlin/app/revanced/utils/Options.kt
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package app.revanced.utils
|
||||||
|
|
||||||
|
import app.revanced.cli.command.PatchList
|
||||||
|
import app.revanced.cli.logging.CliLogger
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.options
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
|
import app.revanced.patcher.patch.NoSuchOptionException
|
||||||
|
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
|
internal object Options {
|
||||||
|
private var mapper = jacksonObjectMapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serializes the options for the patches in the list.
|
||||||
|
*
|
||||||
|
* @param patches The list of patches to serialize.
|
||||||
|
* @param prettyPrint Whether to pretty print the JSON.
|
||||||
|
* @return The JSON string containing the options.
|
||||||
|
* @see PatchList
|
||||||
|
*/
|
||||||
|
fun serialize(patches: PatchList, prettyPrint: Boolean = false): String = patches
|
||||||
|
.filter { it.options?.any() == true }
|
||||||
|
.map { patch ->
|
||||||
|
PatchOption(
|
||||||
|
patch.patchName,
|
||||||
|
patch.options!!.map { option -> PatchOption.Option(option.key, option.value) }
|
||||||
|
)
|
||||||
|
}.let {
|
||||||
|
if (prettyPrint)
|
||||||
|
mapper.writerWithDefaultPrettyPrinter().writeValueAsString(it)
|
||||||
|
else
|
||||||
|
mapper.writeValueAsString(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserializes the options for the patches in the list.
|
||||||
|
*
|
||||||
|
* @param json The JSON string containing the options.
|
||||||
|
* @return The list of [PatchOption]s.
|
||||||
|
* @see PatchOption
|
||||||
|
* @see PatchList
|
||||||
|
*/
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate")
|
||||||
|
fun deserialize(json: String): Array<PatchOption> = mapper.readValue(json, Array<PatchOption>::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the options for the patches in the list.
|
||||||
|
*
|
||||||
|
* @param json The JSON string containing the options.
|
||||||
|
* @param logger The logger to use for logging.
|
||||||
|
*/
|
||||||
|
fun PatchList.setOptions(json: String, logger: CliLogger? = null) {
|
||||||
|
filter { it.options?.any() == true }.let { patches ->
|
||||||
|
if (patches.isEmpty()) return
|
||||||
|
|
||||||
|
val patchOptions = deserialize(json)
|
||||||
|
|
||||||
|
patches.forEach { patch ->
|
||||||
|
patchOptions.find { option -> option.patchName == patch.patchName }?.let {
|
||||||
|
it.options.forEach { option ->
|
||||||
|
try {
|
||||||
|
patch.options?.set(option.key, option.value)
|
||||||
|
?: logger?.warn("${patch.patchName} has no options")
|
||||||
|
} catch (e: NoSuchOptionException) {
|
||||||
|
logger?.error(e.message ?: "Unknown error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the options for the patches in the list.
|
||||||
|
*
|
||||||
|
* @param file The file containing the JSON string containing the options.
|
||||||
|
* @param logger The logger to use for logging.
|
||||||
|
* @see setOptions
|
||||||
|
*/
|
||||||
|
fun PatchList.setOptions(file: File, logger: CliLogger? = null) = setOptions(file.readText(), logger)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data class for a patch and its [Option]s.
|
||||||
|
*
|
||||||
|
* @property patchName The name of the patch.
|
||||||
|
* @property options The [Option]s for the patch.
|
||||||
|
*/
|
||||||
|
internal data class PatchOption(
|
||||||
|
val patchName: String,
|
||||||
|
val options: List<Option>
|
||||||
|
) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data class for patch option.
|
||||||
|
*
|
||||||
|
* @property key The name of the option.
|
||||||
|
* @property value The value of the option.
|
||||||
|
*/
|
||||||
|
internal data class Option(val key: String, val value: Any?)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package app.revanced.utils
|
|
||||||
|
|
||||||
import app.revanced.cli.command.MainCommand.logger
|
|
||||||
import app.revanced.patcher.Patcher
|
|
||||||
import app.revanced.patcher.data.Context
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.options
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
|
||||||
import app.revanced.patcher.patch.Patch
|
|
||||||
import cc.ekblad.toml.encodeToString
|
|
||||||
import cc.ekblad.toml.model.TomlValue
|
|
||||||
import cc.ekblad.toml.serialization.from
|
|
||||||
import cc.ekblad.toml.tomlMapper
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
private typealias PatchList = List<Class<out Patch<Context>>>
|
|
||||||
private typealias OptionsMap = MutableMap<String, MutableMap<String, Any>>
|
|
||||||
|
|
||||||
object OptionsLoader {
|
|
||||||
@JvmStatic
|
|
||||||
private val mapper = tomlMapper {}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun init(file: File, patches: PatchList) {
|
|
||||||
if (!file.exists()) file.createNewFile()
|
|
||||||
val map = mapper.decodeWithDefaults(generateDefaults(patches), TomlValue.from(file.toPath()))
|
|
||||||
readAndSet(map, patches)
|
|
||||||
save(map, file)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun readAndSet(map: OptionsMap, patches: PatchList) {
|
|
||||||
for ((patchName, options) in map) {
|
|
||||||
val patch = patches.find { it.patchName == patchName } ?: continue
|
|
||||||
val patchOptions = patch.options ?: continue
|
|
||||||
for ((key, value) in options) {
|
|
||||||
if (value == "null") { // backwards compatibility, subject to removal
|
|
||||||
options.remove(key)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
patchOptions[key] = value
|
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.error("Error while setting option $key for patch $patchName: ${e.message}")
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun save(map: OptionsMap, file: File) {
|
|
||||||
val toml = mapper.encodeToString(map)
|
|
||||||
file.writeText(
|
|
||||||
"""
|
|
||||||
# A list of options for each patch.
|
|
||||||
# This file does not contain all options by default.
|
|
||||||
# Run the CLI with the "--list --with-options" flags to see all available options.
|
|
||||||
# You can also run the CLI with the aforementioned flags and a patch name to see all available options for that patch.
|
|
||||||
# To set an option, add a line with the format "option = value" or set the value if the option already exists.
|
|
||||||
# To reset an option to its default value, delete the line.
|
|
||||||
# To reset all options to their default values, delete this file.
|
|
||||||
#
|
|
||||||
# This file was generated by ReVanced Patcher version ${Patcher.version}.
|
|
||||||
""".trimIndent() + "\n\n$toml"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateDefaults(patches: PatchList) = buildMap {
|
|
||||||
for (patch in patches) {
|
|
||||||
val options = patch.options ?: continue
|
|
||||||
if (!options.iterator().hasNext()) continue
|
|
||||||
put(patch.patchName, buildMap {
|
|
||||||
for (option in options) {
|
|
||||||
put(option.key, option.value ?: continue)
|
|
||||||
}
|
|
||||||
} as MutableMap)
|
|
||||||
}
|
|
||||||
} as MutableMap
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package app.revanced.utils.patcher
|
|||||||
import app.revanced.cli.command.MainCommand
|
import app.revanced.cli.command.MainCommand
|
||||||
import app.revanced.cli.command.MainCommand.args
|
import app.revanced.cli.command.MainCommand.args
|
||||||
import app.revanced.cli.command.MainCommand.logger
|
import app.revanced.cli.command.MainCommand.logger
|
||||||
|
import app.revanced.cli.command.PatchList
|
||||||
import app.revanced.patcher.Patcher
|
import app.revanced.patcher.Patcher
|
||||||
import app.revanced.patcher.data.Context
|
import app.revanced.patcher.data.Context
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||||
@@ -10,7 +11,7 @@ import app.revanced.patcher.extensions.PatchExtensions.include
|
|||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
|
|
||||||
fun Patcher.addPatchesFiltered(allPatches: List<Class<out Patch<Context>>>) {
|
fun Patcher.addPatchesFiltered(allPatches: PatchList) {
|
||||||
val packageName = this.context.packageMetadata.packageName
|
val packageName = this.context.packageMetadata.packageName
|
||||||
val packageVersion = this.context.packageMetadata.packageVersion
|
val packageVersion = this.context.packageMetadata.packageVersion
|
||||||
|
|
||||||
@@ -37,7 +38,7 @@ fun Patcher.addPatchesFiltered(allPatches: List<Class<out Patch<Context>>>) {
|
|||||||
val compatibleWith = compatiblePackages.joinToString(";") { _package ->
|
val compatibleWith = compatiblePackages.joinToString(";") { _package ->
|
||||||
"${_package.name}: ${_package.versions.joinToString(", ")}"
|
"${_package.name}: ${_package.versions.joinToString(", ")}"
|
||||||
}
|
}
|
||||||
logger.warn("$prefix: Incompatible with version $packageVersion. This patch is only compatible with version $compatibleWith")
|
logger.warn("$prefix: Incompatible with version $packageVersion. This patch is only compatible with $compatibleWith")
|
||||||
return@patchLoop
|
return@patchLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package app.revanced.patcher.options
|
||||||
|
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.data.Context
|
||||||
|
import app.revanced.patcher.patch.*
|
||||||
|
import app.revanced.utils.Options
|
||||||
|
import app.revanced.utils.Options.setOptions
|
||||||
|
import org.junit.jupiter.api.MethodOrderer
|
||||||
|
import org.junit.jupiter.api.Order
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder
|
||||||
|
|
||||||
|
class PatchOptionsTestPatch : BytecodePatch() {
|
||||||
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object : OptionsContainer() {
|
||||||
|
var key1 by option(
|
||||||
|
PatchOption.StringOption(
|
||||||
|
"key1", null, "title1", "description1"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
var key2 by option(
|
||||||
|
PatchOption.BooleanOption(
|
||||||
|
"key2", true, "title2", "description2"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
|
||||||
|
internal object PatchOptionOptionsTest {
|
||||||
|
private var patches = listOf(PatchOptionsTestPatch::class.java as Class<out Patch<Context>>)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(1)
|
||||||
|
fun serializeTest() {
|
||||||
|
assert(SERIALIZED_JSON == Options.serialize(patches))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(2)
|
||||||
|
fun loadOptionsTest() {
|
||||||
|
patches.setOptions(CHANGED_JSON)
|
||||||
|
|
||||||
|
assert(PatchOptionsTestPatch.key1 == "test")
|
||||||
|
assert(PatchOptionsTestPatch.key2 == false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val SERIALIZED_JSON =
|
||||||
|
"[{\"patchName\":\"PatchOptionsTestPatch\",\"options\":[{\"key\":\"key1\",\"value\":null},{\"key\":\"key2\",\"value\":true}]}]"
|
||||||
|
|
||||||
|
private const val CHANGED_JSON =
|
||||||
|
"[{\"patchName\":\"PatchOptionsTestPatch\",\"options\":[{\"key\":\"key1\",\"value\":\"test\"},{\"key\":\"key2\",\"value\":false}]}]"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user