Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions src/main/kotlin/app/revanced/cli/command/PatchCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,27 @@ internal object PatchCommand : Runnable {
this.outputFilePath = outputFilePath?.absoluteFile
}

@CommandLine.Option(
names = ["-i", "--install"],
description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."],
// Empty string to indicate that the first connected device should be used.
fallbackValue = "",
arity = "0..1",
)
private var deviceSerial: String? = null

@CommandLine.Option(
names = ["--mount"],
description = ["Install the patched APK file by mounting."],
showDefaultValue = ALWAYS,
)
private var mount: Boolean = false
@ArgGroup(exclusive = false, multiplicity = "0..1")
internal var installation: Installation? = null

internal class Installation {
@CommandLine.Option(
names = ["-i", "--install"],
required = true,
description = ["Serial of the ADB device to install to. If not specified, the first connected device will be used."],
fallbackValue = "", // Empty string is used to select the first of connected devices.
arity = "0..1",
)
internal var deviceSerial: String? = null

@CommandLine.Option(
names = ["--mount"],
required = false,
description = ["Install the patched APK file by mounting."],
showDefaultValue = ALWAYS,
)
internal var mount: Boolean = false
}

@CommandLine.Option(
names = ["--keystore"],
Expand Down Expand Up @@ -245,11 +251,11 @@ internal object PatchCommand : Runnable {
keyStoreFilePath ?: outputFilePath.parentFile
.resolve("${outputFilePath.nameWithoutExtension}.keystore")

val installer = if (deviceSerial != null) {
val deviceSerial = deviceSerial!!.ifEmpty { null }
val installer = if (installation?.deviceSerial != null) {
val deviceSerial = installation?.deviceSerial!!.ifEmpty { null }

try {
if (mount) {
if (installation?.mount == true) {
AdbRootInstaller(deviceSerial)
} else {
AdbInstaller(deviceSerial)
Expand Down Expand Up @@ -332,7 +338,7 @@ internal object PatchCommand : Runnable {
apk.copyTo(temporaryFilesPath.resolve(apk.name), overwrite = true).apply {
patcherResult.applyTo(this)
}.let { patchedApkFile ->
if (!mount) {
if (installation?.mount != true) {
ApkUtils.signApk(
patchedApkFile,
outputFilePath,
Expand All @@ -355,7 +361,7 @@ internal object PatchCommand : Runnable {

// region Install.

deviceSerial?.let {
installation?.deviceSerial?.let {
runBlocking {
when (val result = installer!!.install(Installer.Apk(outputFilePath, packageName))) {
RootInstallerResult.FAILURE -> logger.severe("Failed to mount the patched APK file")
Expand Down
Loading