mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 09:08:04 +01:00
feat: add PathOption back
Now backed by a String.
This commit is contained in:
parent
456db7289a
commit
172655bde0
3 changed files with 30 additions and 0 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
package app.revanced.patcher.patch
|
||||
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.pathString
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
||||
|
@ -227,4 +229,20 @@ sealed class PatchOption<T>(
|
|||
) : ListOption<Int>(
|
||||
key, default, options, title, description, required, validator
|
||||
)
|
||||
|
||||
/**
|
||||
* A [PatchOption] representing a [Path], backed by a [String].
|
||||
* The validator passes a [String], if you need a [Path] you will have to convert it yourself.
|
||||
* @see PatchOption
|
||||
*/
|
||||
class PathOption(
|
||||
key: String,
|
||||
default: Path?,
|
||||
title: String,
|
||||
description: String,
|
||||
required: Boolean = false,
|
||||
validator: (String?) -> Boolean = { true }
|
||||
) : PatchOption<String>(
|
||||
key, default?.pathString, title, description, required, validator
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package app.revanced.patcher.patch
|
|||
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.pathString
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
internal class PatchOptionsTest {
|
||||
|
@ -33,6 +35,10 @@ internal class PatchOptionsTest {
|
|||
println(choice)
|
||||
}
|
||||
}
|
||||
|
||||
is PatchOption.PathOption -> {
|
||||
option.value = Path("test.txt").pathString
|
||||
}
|
||||
}
|
||||
}
|
||||
val option = options.get<String>("key1")
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.jf.dexlib2.immutable.reference.ImmutableFieldReference
|
|||
import org.jf.dexlib2.immutable.reference.ImmutableStringReference
|
||||
import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue
|
||||
import org.jf.dexlib2.util.Preconditions
|
||||
import kotlin.io.path.Path
|
||||
|
||||
@Patch
|
||||
@Name("example-bytecode-patch")
|
||||
|
@ -194,5 +195,10 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
|||
"key5", null, "title", "description", true
|
||||
)
|
||||
)
|
||||
private var key6 by option(
|
||||
PatchOption.PathOption(
|
||||
"key6", Path("test.txt"), "title", "description", true
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue