refactor: replace try catch block with null check

This commit is contained in:
oSumAtrIX 2022-06-21 17:35:59 +02:00
parent c7d72c4d1c
commit 430de23856
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 12 additions and 15 deletions

View File

@ -23,10 +23,10 @@ internal object MainCommand : Runnable {
var patchBundles = arrayOf<String>()
@ArgGroup(exclusive = false)
lateinit var lArgs: ListingArgs
var lArgs: ListingArgs? = null
@ArgGroup(exclusive = false)
lateinit var pArgs: PatchingArgs
var pArgs: PatchingArgs? = null
}
class ListingArgs {
@ -79,17 +79,14 @@ internal object MainCommand : Runnable {
}
override fun run() {
try {
if (args.lArgs.listOnly) {
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
println("[available] ${patch.patchName}")
}
return
if (args.lArgs?.listOnly == true) {
for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) {
println("[available] ${patch.patchName}")
}
} catch (_: UninitializedPropertyAccessException) {
return
}
val args = args.pArgs
val args = args.pArgs?: return
val patcher = app.revanced.patcher.Patcher(
PatcherOptions(

View File

@ -10,7 +10,7 @@ import java.nio.file.Files
internal object Patcher {
internal fun start(patcher: app.revanced.patcher.Patcher, output: File) {
val args = args.pArgs;
val args = args.pArgs!!
// merge files like necessary integrations
patcher.mergeFiles()

View File

@ -7,7 +7,7 @@ import java.io.File
object Signing {
fun start(inputFile: File, outputFile: File, cn: String, password: String) {
val cacheDirectory = File(args.pArgs.cacheDirectory)
val cacheDirectory = File(args.pArgs!!.cacheDirectory)
val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk")
val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk")

View File

@ -16,7 +16,7 @@ fun Patcher.addPatchesFiltered(
val packageName = this.data.packageMetadata.packageName
val packageVersion = this.data.packageMetadata.packageVersion
MainCommand.args.patchBundles.forEach { bundle ->
args.patchBundles.forEach { bundle ->
val includedPatches = mutableListOf<Class<out Patch<Data>>>()
JarPatchBundle(bundle).loadPatches().forEach patch@{ patch ->
val compatiblePackages = patch.compatiblePackages
@ -24,7 +24,7 @@ fun Patcher.addPatchesFiltered(
val prefix = "[skipped] $patchName"
val args = MainCommand.args.pArgs
val args = MainCommand.args.pArgs!!
if (includeFilter) {
if (!args.includedPatches.contains(patchName)) {
@ -68,5 +68,5 @@ fun Patcher.applyPatchesVerbose() {
}
fun Patcher.mergeFiles() {
this.addFiles(MainCommand.args.pArgs.mergeFiles)
this.addFiles(args.pArgs!!.mergeFiles)
}