You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-06 16:38:50 +02:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7761d5b85e | ||
![]() |
62aa295e73 | ||
![]() |
596ede1b12 | ||
![]() |
7debe62738 | ||
![]() |
002f84da1a | ||
![]() |
aff4968e6f | ||
![]() |
1d989abd55 | ||
![]() |
f1775f83d0 | ||
![]() |
4055939c08 | ||
![]() |
85120374d6 | ||
![]() |
8b4819faa1 | ||
![]() |
79f91e0e5a |
1
.idea/.gitignore
generated
vendored
1
.idea/.gitignore
generated
vendored
@@ -6,3 +6,4 @@
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
/kotlinc.xml
|
||||
|
28
CHANGELOG.md
28
CHANGELOG.md
@@ -1,3 +1,31 @@
|
||||
## [4.1.5](https://github.com/revanced/revanced-patcher/compare/v4.1.4...v4.1.5) (2022-09-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* broken deprecation message ([62aa295](https://github.com/revanced/revanced-patcher/commit/62aa295e7372014238415af36d902a4e88e2acbc))
|
||||
|
||||
## [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)
|
||||
|
||||
|
||||
|
@@ -1,2 +1,2 @@
|
||||
kotlin.code.style = official
|
||||
version = 4.1.1
|
||||
version = 4.1.5
|
||||
|
@@ -291,7 +291,8 @@ class Patcher(private val options: PatcherOptions) {
|
||||
}
|
||||
|
||||
patch.deprecated?.let { (reason, replacement) ->
|
||||
logger.warn("'$patchName' is deprecated: '$reason'" + if (replacement != null) ". Use '$replacement' instead." else "")
|
||||
logger.warn("'$patchName' is deprecated: $reason")
|
||||
if (replacement != null) logger.warn("Use '${replacement.java.patchName}' instead")
|
||||
}
|
||||
|
||||
// TODO: find a solution for this
|
||||
|
@@ -38,7 +38,7 @@ private fun <T : Annotation> Class<*>.findAnnotationRecursively(
|
||||
}
|
||||
|
||||
object PatchExtensions {
|
||||
val Class<out Patch<Data>>.patchName: String
|
||||
val Class<*>.patchName: String
|
||||
get() = recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName
|
||||
val Class<out Patch<Data>>.version get() = recursiveAnnotation(Version::class)?.version
|
||||
val Class<out Patch<Data>>.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include
|
||||
|
@@ -81,6 +81,12 @@ sealed class PatchOption<T>(
|
||||
val validator: (T?) -> Boolean
|
||||
) {
|
||||
var value: T? = default
|
||||
get() {
|
||||
if (field == null && required) {
|
||||
throw RequirementNotMetException
|
||||
}
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
if (value == null && required) {
|
||||
throw RequirementNotMetException
|
||||
@@ -95,7 +101,11 @@ sealed class PatchOption<T>(
|
||||
* Gets the value of the option.
|
||||
* 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.
|
||||
@@ -158,7 +168,7 @@ sealed class PatchOption<T>(
|
||||
}
|
||||
) {
|
||||
init {
|
||||
if (default !in options) {
|
||||
if (default != null && default !in options) {
|
||||
throw IllegalStateException("Default option must be an allowed option")
|
||||
}
|
||||
}
|
||||
@@ -227,4 +237,4 @@ sealed class PatchOption<T>(
|
||||
validator(it?.toFile())
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -85,9 +85,16 @@ internal class PatchOptionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should fail because of the requirement is not met`() {
|
||||
fun `should fail because the requirement is not met`() {
|
||||
assertThrows<RequirementNotMetException> {
|
||||
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
|
||||
)
|
||||
)
|
||||
private var key3: List<String> by option(
|
||||
private var key3: String by option(
|
||||
PatchOption.StringListOption(
|
||||
"key3", "TEST", listOf("TEST", "TEST1", "TEST2"), "title", "description"
|
||||
)
|
||||
)
|
||||
private var key4: List<Int> by option(
|
||||
private var key4: Int by option(
|
||||
PatchOption.IntListOption(
|
||||
"key4", 1, listOf(1, 2, 3), "title", "description"
|
||||
)
|
||||
@@ -196,5 +196,10 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
||||
"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