@@ -20,6 +20,7 @@ import cfig.bootimg.cpio.AndroidCpio
2020import rom.fdt.DTC
2121import cfig.helper.Helper
2222import cfig.helper.ZipHelper
23+ import cfig.packable.BootImgParser
2324import cfig.utils.KernelExtractor
2425import com.github.freva.asciitable.HorizontalAlign
2526import org.apache.commons.exec.CommandLine
@@ -32,6 +33,8 @@ import java.io.File
3233import java.nio.file.Files
3334import java.nio.file.Paths
3435import java.io.FileInputStream
36+ import java.io.FileOutputStream
37+ import java.io.IOException
3538import java.lang.NumberFormatException
3639import java.nio.ByteBuffer
3740import java.nio.ByteOrder
@@ -52,6 +55,12 @@ class Common {
5255 private val log = LoggerFactory .getLogger(Common ::class .java)
5356 private const val MAX_ANDROID_VER = 11
5457
58+ val loadProperties: (String ) -> Properties = { fileName ->
59+ Properties ().apply {
60+ File (fileName).inputStream().use { load(it) }
61+ }
62+ }
63+
5564 @Throws(IllegalArgumentException ::class )
5665 fun packOsVersion (x : String? ): Int {
5766 if (x.isNullOrBlank()) return 0
@@ -423,19 +432,24 @@ class Common {
423432 )
424433 }
425434
426- fun printPackSummary (imageName : String ) {
435+ fun printPackSummary (imageName : String , outFile : String? = null ) {
427436 val prints: MutableList <Pair <String , String >> = mutableListOf ()
428437 val tableHeader = de.vandermeer.asciitable.AsciiTable ().apply {
429438 addRule(); addRow(" What" , " Where" ); addRule()
430439 }
431440 val tab = de.vandermeer.asciitable.AsciiTable ().let {
432441 it.addRule()
433- if (File ( " $imageName .signed " ).exists() ) {
434- it.addRow(" re-packed $imageName " , " $imageName .signed " )
435- prints.add(Pair (" re-packed $imageName " , " $imageName .signed " ))
442+ if (outFile != null ) {
443+ it.addRow(" re-packed $imageName " , outFile )
444+ prints.add(Pair (" re-packed $imageName " , outFile ))
436445 } else {
437- it.addRow(" re-packed $imageName " , " $imageName .clear" )
438- prints.add(Pair (" re-packed $imageName " , " $imageName .clear" ))
446+ if (File (" $imageName .signed" ).exists()) {
447+ it.addRow(" re-packed $imageName " , " $imageName .signed" )
448+ prints.add(Pair (" re-packed $imageName " , " $imageName .signed" ))
449+ } else {
450+ it.addRow(" re-packed $imageName " , " $imageName .clear" )
451+ prints.add(Pair (" re-packed $imageName " , " $imageName .clear" ))
452+ }
439453 }
440454 it.addRule()
441455 it
@@ -457,6 +471,31 @@ class Common {
457471 }
458472 }
459473
474+ /*
475+ be_caller_dir: set in "be" script, to support out of tree invocation
476+ */
477+ fun shortenPath (fullPath : String , inCurrentPath : String = System .getProperty("user.dir")): String {
478+ val currentPath = System .getenv(" be_caller_dir" ) ? : inCurrentPath
479+ val full = Paths .get(fullPath).normalize().toAbsolutePath()
480+ val base = Paths .get(currentPath).normalize().toAbsolutePath()
481+ return try {
482+ base.relativize(full).toString()
483+ } catch (e: IllegalArgumentException ) {
484+ full.toString()
485+ }
486+ }
487+
488+ fun String.toShortenPath (inCurrentPath : String = System .getProperty("user.dir")): String {
489+ val currentPath = System .getenv(" be_caller_dir" ) ? : inCurrentPath
490+ val full = Paths .get(this ).normalize().toAbsolutePath()
491+ val base = Paths .get(currentPath).normalize().toAbsolutePath()
492+ return try {
493+ base.relativize(full).toString()
494+ } catch (e: IllegalArgumentException ) {
495+ full.toString()
496+ }
497+ }
498+
460499 fun printPackSummaryInternal (imageName : String ) {
461500 val prints: MutableList <Pair <String , String >> = mutableListOf ()
462501 val tableHeader = de.vandermeer.asciitable.AsciiTable ().apply {
@@ -485,5 +524,24 @@ class Common {
485524 log.info(" \n\t\t\t Pack Summary of ${imageName} \n {}\n {}" , tableHeader.render(), tab.render())
486525 }
487526 }
527+
528+ fun createWorkspaceIni (fileName : String ) {
529+ // create workspace file
530+ val workspaceFile = File (Helper .prop(" workDir" ), " workspace.ini" ).canonicalPath
531+ try {
532+ FileOutputStream (workspaceFile).use { output ->
533+ Properties ().also {
534+ it.setProperty(" file" , fileName)
535+ it.setProperty(" workDir" , Helper .prop(" workDir" ))
536+ it.setProperty(" role" , File (fileName).name)
537+ it.store(output, " unpackInternal configuration" )
538+ }
539+ log.info(" workspace file created: $workspaceFile " )
540+ }
541+ } catch (e: IOException ) {
542+ log.error(" error writing workspace file: ${e.message} " )
543+ }
544+ // create workspace file done
545+ }
488546 }
489547}
0 commit comments