refactor: Move code out of use block

This commit is contained in:
oSumAtrIX 2024-02-24 01:10:23 +01:00
parent 9c0ad4604a
commit de63cfa426
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -273,8 +273,7 @@ internal object PatchCommand : Runnable {
} }
// endregion // endregion
val (packageName, patcherResult) = Patcher(
Patcher(
PatcherConfig( PatcherConfig(
apk, apk,
temporaryFilesPath, temporaryFilesPath,
@ -296,57 +295,55 @@ internal object PatchCommand : Runnable {
// region Patch // region Patch
val patcherResult = patcher.context.packageMetadata.packageName to patcher.apply {
patcher.apply { acceptIntegrations(integrations)
acceptIntegrations(integrations) acceptPatches(filteredPatches)
acceptPatches(filteredPatches)
// Execute patches. // Execute patches.
runBlocking { runBlocking {
apply(false).collect { patchResult -> apply(false).collect { patchResult ->
patchResult.exception?.let { patchResult.exception?.let {
StringWriter().use { writer -> StringWriter().use { writer ->
it.printStackTrace(PrintWriter(writer)) it.printStackTrace(PrintWriter(writer))
logger.severe("${patchResult.patch.name} failed:\n$writer") logger.severe("${patchResult.patch.name} failed:\n$writer")
} }
} ?: logger.info("${patchResult.patch.name} succeeded") } ?: logger.info("${patchResult.patch.name} succeeded")
}
} }
}.get() }
}.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))
// endregion // 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) { if (purge) {
logger.info("Purging temporary files") logger.info("Purging temporary files")
purge(temporaryFilesPath) purge(temporaryFilesPath)