Display uncompressed size for DMG images

This commit is contained in:
Davide Depau 2018-09-01 03:45:19 +02:00
parent 53dc07490c
commit aa78d36cb0
4 changed files with 31 additions and 15 deletions

View file

@ -28,8 +28,10 @@ class ConfirmationActivity : ActivityBase() {
setContentView(R.layout.activity_confirmation) setContentView(R.layout.activity_confirmation)
actionBar?.setDisplayHomeAsUpEnabled(true) actionBar?.setDisplayHomeAsUpEnabled(true)
displayDetails() // displayImageLayout must be called before displayDetails
// to ensure uncompressed image size is available
displayImageLayout() displayImageLayout()
displayDetails()
} }
fun displayDetails() { fun displayDetails() {
@ -46,8 +48,17 @@ class ConfirmationActivity : ActivityBase() {
if (confirm_sel_image.text == null) if (confirm_sel_image.text == null)
confirm_sel_image.text = getString(R.string.unknown_filename) confirm_sel_image.text = getString(R.string.unknown_filename)
val imgSize = StateKeeper.imageFile?.getFileSize(this) val imgSize: Long?
confirm_sel_image_size.text = imgSize?.toHRSize() val sizeStr: String?
if (StateKeeper.imageRepr?.size != null) {
imgSize = StateKeeper.imageRepr?.size
sizeStr = imgSize?.toHRSize() + " (uncompressed)"
} else {
imgSize = StateKeeper.imageFile?.getFileSize(this)
sizeStr = imgSize?.toHRSize()
}
confirm_sel_image_size.text = sizeStr
confirm_sel_usbdev.text = StateKeeper.usbDevice?.name confirm_sel_usbdev.text = StateKeeper.usbDevice?.name
@ -63,12 +74,7 @@ class ConfirmationActivity : ActivityBase() {
if (imgSize!! > devSize) if (imgSize!! > devSize)
confirm_extra_info.text = getString(R.string.image_bigger_than_usb) confirm_extra_info.text = getString(R.string.image_bigger_than_usb)
else { else {
var text = val text = getString(R.string.tap_next_to_write)
if (StateKeeper.flashMethod == FlashMethod.FLASH_DMG_API)
getString(R.string.no_image_size_check_dmg) + "\n"
else
""
text += getString(R.string.tap_next_to_write)
confirm_extra_info.text = text confirm_extra_info.text = text
canContinue = true canContinue = true
} }

View file

@ -13,9 +13,10 @@ import java.io.File
val SECTOR_SIZE = 512 val SECTOR_SIZE = 512
private val partRegex = Regex("partition (\\d+): begin=(\\d+), size=(\\d+), decoded=(\\d+), firstsector=(\\d+), sectorcount=(\\d+), blocksruncount=(\\d+)\\s+(.*) \\((.+) : \\d+\\)", RegexOption.MULTILINE) private val partRegex = Regex("partition (\\d+): begin=(\\d+), size=(\\d+), decoded=(\\d+), firstsector=(\\d+), sectorcount=(\\d+), blocksruncount=(\\d+)\\s+(.*) \\((.+) : \\d+\\)", RegexOption.MULTILINE)
private fun readPartitionTable(dmg2img: File, libDir: String, file: File): Pair<PartitionTableType?, List<Partition>?> { private fun readPartitionTable(dmg2img: File, libDir: String, file: File): Triple<PartitionTableType?, List<Partition>?, Long?> {
val pt = ArrayList<Partition>() val pt = ArrayList<Partition>()
var ptType: PartitionTableType? = null var ptType: PartitionTableType? = null
var imgSize = 0L
val pb = ProcessBuilder(dmg2img.path, "-v", "-l", file.path) val pb = ProcessBuilder(dmg2img.path, "-v", "-l", file.path)
pb.environment()["LD_LIBRARY_PATH"] = libDir pb.environment()["LD_LIBRARY_PATH"] = libDir
@ -39,6 +40,7 @@ private fun readPartitionTable(dmg2img: File, libDir: String, file: File): Pair<
pb.number = number.toInt() pb.number = number.toInt()
pb.size = SECTOR_SIZE * sectorcount.toLong() pb.size = SECTOR_SIZE * sectorcount.toLong()
imgSize += pb.size!!
if (label.isNotEmpty()) if (label.isNotEmpty())
pb.fsLabel = label pb.fsLabel = label
@ -67,7 +69,7 @@ private fun readPartitionTable(dmg2img: File, libDir: String, file: File): Pair<
pt.add(pb.build()) pt.add(pb.build())
} }
return Pair(ptType, pt) return Triple(ptType, pt, imgSize)
} }
class DMGImage(private val uri: Uri, private val context: Context) : Image { class DMGImage(private val uri: Uri, private val context: Context) : Image {
@ -76,14 +78,16 @@ class DMGImage(private val uri: Uri, private val context: Context) : Image {
private var loaded: Boolean = false private var loaded: Boolean = false
private var partTable: List<Partition>? = null private var partTable: List<Partition>? = null
private var partTableType: PartitionTableType? = null private var partTableType: PartitionTableType? = null
private var imgSize: Long? = null
private fun readInfo() { private fun readInfo() {
if (loaded) if (loaded)
return return
val pair = readPartitionTable(dmg2img, libDir, File(uri.path)) val triple = readPartitionTable(dmg2img, libDir, File(uri.path))
loaded = true loaded = true
partTableType = pair.first partTableType = triple.first
partTable = pair.second partTable = triple.second
imgSize = triple.third
} }
override val partitionTable: List<Partition>? override val partitionTable: List<Partition>?
@ -99,4 +103,10 @@ class DMGImage(private val uri: Uri, private val context: Context) : Image {
return partTableType return partTableType
} }
override val size: Long?
get() {
readInfo()
return imgSize
}
} }

View file

@ -6,4 +6,5 @@ import eu.depau.etchdroid.utils.Partition
interface Image { interface Image {
val partitionTable: List<Partition>? val partitionTable: List<Partition>?
val tableType: PartitionTableType? val tableType: PartitionTableType?
val size: Long?
} }

View file

@ -71,7 +71,6 @@
<string name="fs_label">Label</string> <string name="fs_label">Label</string>
<string name="fs_type">Type</string> <string name="fs_type">Type</string>
<string name="part_size">Size</string> <string name="part_size">Size</string>
<string name="no_image_size_check_dmg">Image size checks can\'t be performed on DMG images. Make sure the USB drive is large enough before flashing.</string>
<string name="license_gpl3">GNU GPLv3</string> <string name="license_gpl3">GNU GPLv3</string>
<string name="this_app">This app</string> <string name="this_app">This app</string>
<string name="license_apache2_0">Apache 2.0</string> <string name="license_apache2_0">Apache 2.0</string>