Skip to content

Commit

Permalink
refactor: replace try catch block with null check
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jun 21, 2022
1 parent c7d72c4 commit 430de23
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
17 changes: 7 additions & 10 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/app/revanced/cli/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/app/revanced/cli/signing/Signing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/app/revanced/utils/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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
val patchName = patch.patchName

val prefix = "[skipped] $patchName"

val args = MainCommand.args.pArgs
val args = MainCommand.args.pArgs!!

if (includeFilter) {
if (!args.includedPatches.contains(patchName)) {
Expand Down Expand Up @@ -68,5 +68,5 @@ fun Patcher.applyPatchesVerbose() {
}

fun Patcher.mergeFiles() {
this.addFiles(MainCommand.args.pArgs.mergeFiles)
this.addFiles(args.pArgs!!.mergeFiles)
}

0 comments on commit 430de23

Please sign in to comment.