Skip to content

Commit

Permalink
fix: align every file
Browse files Browse the repository at this point in the history
  • Loading branch information
Canny authored and oSumAtrIX committed Jul 21, 2022
1 parent 1cd0976 commit 96ec6a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/main/kotlin/app/revanced/cli/aligning/Aligning.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app.revanced.cli.aligning

import app.revanced.cli.command.MainCommand
import app.revanced.cli.command.MainCommand.logger
import app.revanced.utils.signing.align.ZipAligner
import java.io.File

object Aligning {
fun align(inputFile: File, outputFile: File) {
val cacheDirectory = File(MainCommand.args.sArgs?.pArgs?.cacheDirectory)
val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk")

logger.info("Aligning ${inputFile.name}")
ZipAligner.align(inputFile, alignedOutput)

logger.info("Copying ${alignedOutput.name} to ${outputFile.name}")
alignedOutput.copyTo(outputFile, true)
}
}
7 changes: 5 additions & 2 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.revanced.cli.command

import app.revanced.cli.aligning.Aligning
import app.revanced.cli.logging.impl.DefaultCliLogger
import app.revanced.cli.patcher.Patcher
import app.revanced.cli.patcher.logging.impl.PatcherLogger
Expand Down Expand Up @@ -162,8 +163,7 @@ internal object MainCommand : Runnable {
val adb: Adb? = _args.deploy?.let {
Adb(outputFile, patcher.data.packageMetadata.packageName, _args.deploy!!, !args.mount)
}
val patchedFile = if (args.mount) outputFile
else File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
val patchedFile = File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")

Patcher.start(patcher, patchedFile)

Expand All @@ -180,6 +180,9 @@ internal object MainCommand : Runnable {
)
)
}
else {
Aligning.align(patchedFile, outputFile)
}

if (args.clean) File(args.cacheDirectory).deleteRecursively()

Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/app/revanced/cli/signing/Signing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import app.revanced.utils.signing.align.ZipAligner
import java.io.File

object Signing {
fun start(inputFile: File, outputFile: File, signingOptions: SigningOptions) {
fun start(patchedFile: File, outputFile: File, signingOptions: SigningOptions) {
val cacheDirectory = File(args.sArgs?.pArgs?.cacheDirectory)
val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk")
val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk")
val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk")

// align the patchedFile and write to alignedFile
ZipAligner.align(patchedFile, alignedOutput)

// align the inputFile and write to alignedOutput
logger.info("Aligning ${inputFile.name}")
ZipAligner.align(inputFile, alignedOutput)
// sign the alignedOutput and write to signedOutput
// the reason is, in case the signer fails
// it does not damage the output file
Expand Down

0 comments on commit 96ec6a0

Please sign in to comment.