From de63cfa42687a32be788413a194585b7ab56fdb2 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 24 Feb 2024 01:10:23 +0100 Subject: [PATCH] refactor: Move code out of `use` block --- .../app/revanced/cli/command/PatchCommand.kt | 93 +++++++++---------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt index 0321a44..d5c7c80 100644 --- a/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/PatchCommand.kt @@ -273,8 +273,7 @@ internal object PatchCommand : Runnable { } // endregion - - Patcher( + val (packageName, patcherResult) = Patcher( PatcherConfig( apk, temporaryFilesPath, @@ -296,57 +295,55 @@ internal object PatchCommand : Runnable { // region Patch - val patcherResult = - patcher.apply { - acceptIntegrations(integrations) - acceptPatches(filteredPatches) + patcher.context.packageMetadata.packageName to patcher.apply { + acceptIntegrations(integrations) + acceptPatches(filteredPatches) - // Execute patches. - runBlocking { - apply(false).collect { patchResult -> - patchResult.exception?.let { - StringWriter().use { writer -> - it.printStackTrace(PrintWriter(writer)) - logger.severe("${patchResult.patch.name} failed:\n$writer") - } - } ?: logger.info("${patchResult.patch.name} succeeded") - } + // Execute patches. + runBlocking { + apply(false).collect { patchResult -> + patchResult.exception?.let { + StringWriter().use { writer -> + it.printStackTrace(PrintWriter(writer)) + logger.severe("${patchResult.patch.name} failed:\n$writer") + } + } ?: logger.info("${patchResult.patch.name} succeeded") } - }.get() - - // endregion - - // region Save - - apk.copyTo(outputFilePath, overwrite = true) - - patcherResult.applyTo(outputFilePath) - - if (!mount) { - outputFilePath.sign( - ApkUtils.SigningOptions( - keystoreFilePath, - keyStorePassword, - alias, - password, - signer, - ), - ) - } - - logger.info("Saved to $outputFilePath") - - // endregion - - // region Install - - deviceSerial?.let { serial -> - AdbManager.getAdbManager(deviceSerial = serial.ifEmpty { null }, mount) - }?.install(AdbManager.Apk(outputFilePath, patcher.context.packageMetadata.packageName)) - + } + }.get() // endregion } + // region Save + + apk.copyTo(outputFilePath, overwrite = true) + + patcherResult.applyTo(outputFilePath) + + if (!mount) { + outputFilePath.sign( + ApkUtils.SigningOptions( + keystoreFilePath, + keyStorePassword, + alias, + password, + signer, + ), + ) + } + + logger.info("Saved to $outputFilePath") + + // endregion + + // region Install + + deviceSerial?.let { serial -> + AdbManager.getAdbManager(deviceSerial = serial.ifEmpty { null }, mount) + }?.install(AdbManager.Apk(outputFilePath, packageName)) + + // endregion + if (purge) { logger.info("Purging temporary files") purge(temporaryFilesPath)