mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-28 05:31:03 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7debe62738 | ||
|
|
002f84da1a | ||
|
|
aff4968e6f | ||
|
|
1d989abd55 | ||
|
|
f1775f83d0 | ||
|
|
4055939c08 | ||
|
|
85120374d6 | ||
|
|
8b4819faa1 | ||
|
|
d219276298 | ||
|
|
79f91e0e5a | ||
|
|
fadf62f594 | ||
|
|
ad3d332e27 |
1
.idea/.gitignore
generated
vendored
1
.idea/.gitignore
generated
vendored
@@ -6,3 +6,4 @@
|
|||||||
# Datasource local storage ignored files
|
# Datasource local storage ignored files
|
||||||
/dataSources/
|
/dataSources/
|
||||||
/dataSources.local.xml
|
/dataSources.local.xml
|
||||||
|
/kotlinc.xml
|
||||||
|
|||||||
28
CHANGELOG.md
28
CHANGELOG.md
@@ -1,3 +1,31 @@
|
|||||||
|
## [4.1.4](https://github.com/revanced/revanced-patcher/compare/v4.1.3...v4.1.4) (2022-09-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* handle option types and nulls properly ([aff4968](https://github.com/revanced/revanced-patcher/commit/aff4968e6f67239afa3b5c02cc133a17d9c3cbeb))
|
||||||
|
|
||||||
|
## [4.1.3](https://github.com/revanced/revanced-patcher/compare/v4.1.2...v4.1.3) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* only run list option check if not null ([4055939](https://github.com/revanced/revanced-patcher/commit/4055939c089e3c396c308c980215d93a1dea5954))
|
||||||
|
|
||||||
|
## [4.1.2](https://github.com/revanced/revanced-patcher/compare/v4.1.1...v4.1.2) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* invalid types for example options ([79f91e0](https://github.com/revanced/revanced-patcher/commit/79f91e0e5a6d99828f30aae55339ce0d897394c7))
|
||||||
|
|
||||||
|
## [4.1.1](https://github.com/revanced/revanced-patcher/compare/v4.1.0...v4.1.1) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* handle private companion objects ([ad3d332](https://github.com/revanced/revanced-patcher/commit/ad3d332e27d07e9d074bbaaf51af7eb2f9bfc7d5))
|
||||||
|
|
||||||
# [4.1.0](https://github.com/revanced/revanced-patcher/compare/v4.0.0...v4.1.0) (2022-09-07)
|
# [4.1.0](https://github.com/revanced/revanced-patcher/compare/v4.0.0...v4.1.0) (2022-09-07)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 4.1.0
|
version = 4.1.4
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import app.revanced.patcher.data.Data
|
|||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patcher.patch.OptionsContainer
|
import app.revanced.patcher.patch.OptionsContainer
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
|
import app.revanced.patcher.patch.PatchOptions
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
import kotlin.reflect.KVisibility
|
||||||
|
import kotlin.reflect.full.companionObject
|
||||||
import kotlin.reflect.full.companionObjectInstance
|
import kotlin.reflect.full.companionObjectInstance
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,9 +45,12 @@ object PatchExtensions {
|
|||||||
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
|
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
|
||||||
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.DependsOn::class)?.dependencies
|
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.DependsOn::class)?.dependencies
|
||||||
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
||||||
val Class<out Patch<Data>>.options
|
val Class<out Patch<Data>>.options: PatchOptions?
|
||||||
get() = kotlin.companionObjectInstance?.let {
|
get() = kotlin.companionObject?.let { cl ->
|
||||||
(it as? OptionsContainer)?.options
|
if (cl.visibility != KVisibility.PUBLIC) return null
|
||||||
|
kotlin.companionObjectInstance?.let {
|
||||||
|
(it as? OptionsContainer)?.options
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val Class<out Patch<Data>>.deprecated: Pair<String, KClass<out Patch<Data>>?>?
|
val Class<out Patch<Data>>.deprecated: Pair<String, KClass<out Patch<Data>>?>?
|
||||||
get() = recursiveAnnotation(PatchDeprecated::class)?.let {
|
get() = recursiveAnnotation(PatchDeprecated::class)?.let {
|
||||||
|
|||||||
@@ -81,6 +81,12 @@ sealed class PatchOption<T>(
|
|||||||
val validator: (T?) -> Boolean
|
val validator: (T?) -> Boolean
|
||||||
) {
|
) {
|
||||||
var value: T? = default
|
var value: T? = default
|
||||||
|
get() {
|
||||||
|
if (field == null && required) {
|
||||||
|
throw RequirementNotMetException
|
||||||
|
}
|
||||||
|
return field
|
||||||
|
}
|
||||||
set(value) {
|
set(value) {
|
||||||
if (value == null && required) {
|
if (value == null && required) {
|
||||||
throw RequirementNotMetException
|
throw RequirementNotMetException
|
||||||
@@ -95,7 +101,11 @@ sealed class PatchOption<T>(
|
|||||||
* Gets the value of the option.
|
* Gets the value of the option.
|
||||||
* Please note that using the wrong value type results in a runtime error.
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
*/
|
*/
|
||||||
operator fun <T> getValue(thisRef: Any?, property: KProperty<*>) = value as T
|
inline operator fun <reified V> getValue(thisRef: Any?, property: KProperty<*>) =
|
||||||
|
value as? V ?: throw InvalidTypeException(
|
||||||
|
V::class.java.canonicalName,
|
||||||
|
value?.let { it::class.java.canonicalName } ?: "null"
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value of the option.
|
* Gets the value of the option.
|
||||||
@@ -158,7 +168,7 @@ sealed class PatchOption<T>(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
if (default !in options) {
|
if (default != null && default !in options) {
|
||||||
throw IllegalStateException("Default option must be an allowed option")
|
throw IllegalStateException("Default option must be an allowed option")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,4 +237,4 @@ sealed class PatchOption<T>(
|
|||||||
validator(it?.toFile())
|
validator(it?.toFile())
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,9 +85,16 @@ internal class PatchOptionsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `should fail because of the requirement is not met`() {
|
fun `should fail because the requirement is not met`() {
|
||||||
assertThrows<RequirementNotMetException> {
|
assertThrows<RequirementNotMetException> {
|
||||||
options.nullify("key1")
|
options.nullify("key1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should fail because getting a non-initialized option is illegal`() {
|
||||||
|
assertThrows<RequirementNotMetException> {
|
||||||
|
println(options["key6"].value)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -181,12 +181,12 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
"key2", true, "title", "description" // required defaults to false
|
"key2", true, "title", "description" // required defaults to false
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
private var key3: List<String> by option(
|
private var key3: String by option(
|
||||||
PatchOption.StringListOption(
|
PatchOption.StringListOption(
|
||||||
"key3", "TEST", listOf("TEST", "TEST1", "TEST2"), "title", "description"
|
"key3", "TEST", listOf("TEST", "TEST1", "TEST2"), "title", "description"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
private var key4: List<Int> by option(
|
private var key4: Int by option(
|
||||||
PatchOption.IntListOption(
|
PatchOption.IntListOption(
|
||||||
"key4", 1, listOf(1, 2, 3), "title", "description"
|
"key4", 1, listOf(1, 2, 3), "title", "description"
|
||||||
)
|
)
|
||||||
@@ -196,5 +196,10 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
"key5", File("test.txt").toPath(), "title", "description"
|
"key5", File("test.txt").toPath(), "title", "description"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
private var key6: String by option(
|
||||||
|
PatchOption.StringOption(
|
||||||
|
"key6", null, "title", "description", true
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user