feat: Do not support reading options from a properties file

Previously needed because patch options could not be used comfortably in ReVanced Manager.
This commit is contained in:
oSumAtrIX 2023-10-12 02:16:21 +02:00
parent 9f86daa822
commit 3d1c0c1a95
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -1,19 +1,14 @@
package app.revanced.patches.reddit.customclients package app.revanced.patches.reddit.customclients
import android.os.Environment
import app.revanced.extensions.exception import app.revanced.extensions.exception
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.options.PatchOptionException
import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption
import java.io.File
import java.util.*
abstract class AbstractSpoofClientPatch( abstract class AbstractSpoofClientPatch(
private val redirectUri: String, redirectUri: String,
private val clientIdFingerprints: List<MethodFingerprint>, private val clientIdFingerprints: List<MethodFingerprint>,
private val userAgentFingerprints: List<MethodFingerprint>? = null, private val userAgentFingerprints: List<MethodFingerprint>? = null,
private val miscellaneousFingerprints: List<MethodFingerprint>? = null private val miscellaneousFingerprints: List<MethodFingerprint>? = null
@ -34,59 +29,6 @@ abstract class AbstractSpoofClientPatch(
) )
override fun execute(context: BytecodeContext) { override fun execute(context: BytecodeContext) {
val requiredOptions = options.values.filter { it.required }
val isAndroidButRequiredOptionsUnset = try {
Class.forName("android.os.Environment")
requiredOptions.any { it.value == null }
} catch (_: ClassNotFoundException) {
false
}
if (isAndroidButRequiredOptionsUnset) {
val properties = Properties()
val propertiesFile = File(
Environment.getExternalStorageDirectory(),
"revanced_client_spoof_${redirectUri.hashCode()}.properties"
)
if (propertiesFile.exists()) {
properties.load(propertiesFile.inputStream())
// Set options from properties file.
properties.forEach { (name, value) ->
try {
options[name.toString()] = value.toString().trim()
} catch (_: PatchOptionException.PatchOptionNotFoundException) {
// Ignore unknown options.
}
}
} else {
options.keys.forEach { properties.setProperty(it, "") }
properties.store(
propertiesFile.outputStream(),
"Options for the ReVanced \"Client Spoof\" patch. Required options: " +
requiredOptions.joinToString { it.key }
)
}
requiredOptions.filter { it.value == null }.let { requiredUnsetOptions ->
if (requiredUnsetOptions.isEmpty()) return@let
val error = """
In order to use this patch, you need to provide the following options:
${requiredUnsetOptions.joinToString("\n") { "${it.key}: ${it.description}" }}
A properties file has been created at ${propertiesFile.absolutePath}.
Please fill in the required options before using this patch.
""".trimIndent()
throw PatchException(error)
}
}
fun List<MethodFingerprint>?.executePatch( fun List<MethodFingerprint>?.executePatch(
patch: List<MethodFingerprintResult>.(BytecodeContext) -> Unit patch: List<MethodFingerprintResult>.(BytecodeContext) -> Unit
) = this?.map { it.result ?: throw it.exception }?.patch(context) ) = this?.map { it.result ?: throw it.exception }?.patch(context)