mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-01 05:44:24 +02:00
refactor: remove PathOption and FileOption
This commit is contained in:
parent
ed1851013e
commit
c348c1f0a0
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
package app.revanced.patcher.patch
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.nio.file.Path
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
||||||
@ -207,36 +205,4 @@ sealed class PatchOption<T>(
|
|||||||
) : ListOption<Int>(
|
) : ListOption<Int>(
|
||||||
key, default, options, title, description, required, validator
|
key, default, options, title, description, required, validator
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* A [PatchOption] representing a [Path].
|
|
||||||
* @see PatchOption
|
|
||||||
*/
|
|
||||||
open class PathOption(
|
|
||||||
key: String,
|
|
||||||
default: Path?,
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
required: Boolean = false,
|
|
||||||
validator: (Path?) -> Boolean = { true }
|
|
||||||
) : PatchOption<Path>(
|
|
||||||
key, default, title, description, required, validator
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A [PathOption] of type [File].
|
|
||||||
* @see PathOption
|
|
||||||
*/
|
|
||||||
class FileOption(
|
|
||||||
key: String,
|
|
||||||
default: File?,
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
required: Boolean = false,
|
|
||||||
validator: (File?) -> Boolean = { true }
|
|
||||||
) : PathOption(
|
|
||||||
key, default?.toPath(), title, description, required, {
|
|
||||||
validator(it?.toFile())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package app.revanced.patcher.patch
|
|||||||
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
import java.io.File
|
|
||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
|
|
||||||
internal class PatchOptionsTest {
|
internal class PatchOptionsTest {
|
||||||
@ -34,10 +33,6 @@ internal class PatchOptionsTest {
|
|||||||
println(choice)
|
println(choice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is PatchOption.PathOption -> {
|
|
||||||
option.value = File("test.txt").toPath()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val option = options["key1"]
|
val option = options["key1"]
|
||||||
@ -94,7 +89,7 @@ internal class PatchOptionsTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `should fail because getting a non-initialized option is illegal`() {
|
fun `should fail because getting a non-initialized option is illegal`() {
|
||||||
assertThrows<RequirementNotMetException> {
|
assertThrows<RequirementNotMetException> {
|
||||||
println(options["key6"].value)
|
println(options["key5"].value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,8 +32,6 @@ import org.jf.dexlib2.immutable.reference.ImmutableFieldReference
|
|||||||
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
||||||
import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
||||||
import org.jf.dexlib2.util.Preconditions
|
import org.jf.dexlib2.util.Preconditions
|
||||||
import java.io.File
|
|
||||||
import java.nio.file.Path
|
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("example-bytecode-patch")
|
@Name("example-bytecode-patch")
|
||||||
@ -191,14 +189,9 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||||||
"key4", 1, listOf(1, 2, 3), "title", "description"
|
"key4", 1, listOf(1, 2, 3), "title", "description"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
private var key5: Path? by option(
|
private var key5: String? by option(
|
||||||
PatchOption.PathOption(
|
|
||||||
"key5", File("test.txt").toPath(), "title", "description"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
private var key6: String? by option(
|
|
||||||
PatchOption.StringOption(
|
PatchOption.StringOption(
|
||||||
"key6", null, "title", "description", true
|
"key5", null, "title", "description", true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user