refactor: add PatchOption.PathOption

This commit is contained in:
Sculas 2022-09-06 21:38:39 +02:00
parent 288d50a8b4
commit 53e807dec1
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
2 changed files with 20 additions and 0 deletions

View File

@ -2,6 +2,7 @@
package app.revanced.patcher.patch
import java.nio.file.Path
import kotlin.reflect.KProperty
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
@ -189,4 +190,19 @@ sealed class PatchOption<T>(
) : ListOption<Int>(
key, default, options, title, description, required, validator
)
/**
* A [PatchOption] representing a [Path].
* @see PatchOption
*/
class PathOption<T: Path>(
key: String,
default: T?,
title: String,
description: String,
required: Boolean = false,
validator: (T?) -> Boolean = { true }
) : PatchOption<T>(
key, default, title, description, required, validator
)
}

View File

@ -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 java.io.File
@Patch
@Name("example-bytecode-patch")
@ -177,5 +178,8 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
PatchOption.IntListOption(
"key4", 1, listOf(1, 2, 3), "title", "description"
),
PatchOption.PathOption(
"key5", File("test.txt").toPath(), "title", "description"
),
)
}