refactor: apply formatting

This commit is contained in:
oSumAtrIX 2022-06-21 01:02:41 +02:00
parent 76da6c1fa6
commit 3cc98efaa6
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -6,9 +6,7 @@ import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.extensions.PatchExtensions.patchName import app.revanced.patcher.extensions.PatchExtensions.patchName
import app.revanced.patcher.util.patch.implementation.JarPatchBundle import app.revanced.patcher.util.patch.implementation.JarPatchBundle
import app.revanced.utils.adb.Adb import app.revanced.utils.adb.Adb
import picocli.CommandLine.Command import picocli.CommandLine.*
import picocli.CommandLine.Option
import picocli.CommandLine.ArgGroup
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
@ -17,84 +15,87 @@ import java.nio.file.Files
) )
internal object MainCommand : Runnable { internal object MainCommand : Runnable {
@ArgGroup(exclusive = false, multiplicity="1") @ArgGroup(exclusive = false, multiplicity = "1")
lateinit var args: Args lateinit var args: Args
class Args class Args {
{ @Option(names = ["-b", "--bundles"], description = ["One or more bundles of patches"], required = true)
@Option(names = ["-b", "--bundles"], description = ["One or more bundles of patches"], required = true) var patchBundles = arrayOf<String>()
var patchBundles = arrayOf<String>()
@ArgGroup(exclusive = false) @ArgGroup(exclusive = false)
lateinit var lArgs: ListingArgs lateinit var lArgs: ListingArgs
@ArgGroup(exclusive = false) @ArgGroup(exclusive = false)
lateinit var pArgs: PatchingArgs lateinit var pArgs: PatchingArgs
} }
class ListingArgs { class ListingArgs {
@Option(names = ["-l", "--list"], description = ["List patches only"], required = true) @Option(names = ["-l", "--list"], description = ["List patches only"], required = true)
public var listOnly: Boolean = false var listOnly: Boolean = false
} }
class PatchingArgs { class PatchingArgs {
@Option(names = ["-a", "--apk"], description = ["Input file to be patched"], required = true) @Option(names = ["-a", "--apk"], description = ["Input file to be patched"], required = true)
lateinit var inputFile: File lateinit var inputFile: File
@Option(names = ["-o", "--out"], description = ["Output file path"], required = true) @Option(names = ["-o", "--out"], description = ["Output file path"], required = true)
lateinit var outputPath: String lateinit var outputPath: String
@Option( @Option(
names = ["-i", "--include"], names = ["-i", "--include"],
description = ["Which patches to include. If none is specified, all compatible default patches will be included"] description = ["Which patches to include. If none is specified, all compatible default patches will be included"]
) )
var includedPatches = arrayOf<String>() var includedPatches = arrayOf<String>()
@Option(names = ["-r", "--resource-patcher"], description = ["Disable patching resources"]) @Option(names = ["-r", "--resource-patcher"], description = ["Disable patching resources"])
var disableResourcePatching: Boolean = false var disableResourcePatching: Boolean = false
@Option(names = ["--debugging"], description = ["Disable patch version compatibility"]) @Option(names = ["--debugging"], description = ["Disable patch version compatibility"])
var debugging: Boolean = false var debugging: Boolean = false
@Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"]) @Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"])
var mergeFiles = listOf<File>() var mergeFiles = listOf<File>()
@Option(names = ["--install"], description = ["If specified, instead of mounting, install"]) @Option(names = ["--install"], description = ["If specified, instead of mounting, install"])
var install: Boolean = false var install: Boolean = false
@Option(names = ["--cn"], description = ["Overwrite the default CN for the signed file"]) @Option(names = ["--cn"], description = ["Overwrite the default CN for the signed file"])
var cn = "ReVanced" var cn = "ReVanced"
@Option(names = ["-p", "--password"], description = ["Overwrite the default password for the signed file"]) @Option(names = ["-p", "--password"], description = ["Overwrite the default password for the signed file"])
var password = "ReVanced" var password = "ReVanced"
@Option(names = ["-d", "--deploy-on"], description = ["If specified, deploy to adb device with given name"]) @Option(names = ["-d", "--deploy-on"], description = ["If specified, deploy to adb device with given name"])
var deploy: String? = null var deploy: String? = null
@Option(names = ["-t", "--temp-dir"], description = ["Temporal resource cache directory"]) @Option(names = ["-t", "--temp-dir"], description = ["Temporal resource cache directory"])
var cacheDirectory = "revanced-cache" var cacheDirectory = "revanced-cache"
@Option( @Option(
names = ["-c", "--clean"], names = ["-c", "--clean"],
description = ["Clean the temporal resource cache directory. This will be done anyways when running the patcher"] description = ["Clean the temporal resource cache directory. This will be done anyways when running the patcher"]
) )
var clean: Boolean = false var clean: Boolean = false
} }
override fun run() { override fun run() {
try try {
{ if (args.lArgs.listOnly) {
if (args.lArgs.listOnly) { for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) { println("[available] ${patch.patchName}")
println("[available] ${patch.patchName}") }
} return
return }
} } catch (_: UninitializedPropertyAccessException) {
} catch (e: UninitializedPropertyAccessException) {} }
val args = args.pArgs; val args = args.pArgs
val patcher = app.revanced.patcher.Patcher(PatcherOptions(args.inputFile, args.cacheDirectory, !args.disableResourcePatching)) val patcher = app.revanced.patcher.Patcher(
PatcherOptions(
args.inputFile, args.cacheDirectory, !args.disableResourcePatching
)
)
val outputFile = File(args.outputPath) val outputFile = File(args.outputPath)
@ -102,7 +103,8 @@ internal object MainCommand : Runnable {
Adb(outputFile, patcher.data.packageMetadata.packageName, args.deploy!!, args.install) Adb(outputFile, patcher.data.packageMetadata.packageName, args.deploy!!, args.install)
} }
val patchedFile = if (args.install) File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk") else outputFile val patchedFile =
if (args.install) File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk") else outputFile
Patcher.start(patcher, patchedFile) Patcher.start(patcher, patchedFile)