Display uncompressed size for DMG images
This commit is contained in:
parent
53dc07490c
commit
aa78d36cb0
4 changed files with 31 additions and 15 deletions
|
@ -28,8 +28,10 @@ class ConfirmationActivity : ActivityBase() {
|
|||
setContentView(R.layout.activity_confirmation)
|
||||
actionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
displayDetails()
|
||||
// displayImageLayout must be called before displayDetails
|
||||
// to ensure uncompressed image size is available
|
||||
displayImageLayout()
|
||||
displayDetails()
|
||||
}
|
||||
|
||||
fun displayDetails() {
|
||||
|
@ -46,8 +48,17 @@ class ConfirmationActivity : ActivityBase() {
|
|||
if (confirm_sel_image.text == null)
|
||||
confirm_sel_image.text = getString(R.string.unknown_filename)
|
||||
|
||||
val imgSize = StateKeeper.imageFile?.getFileSize(this)
|
||||
confirm_sel_image_size.text = imgSize?.toHRSize()
|
||||
val imgSize: Long?
|
||||
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
|
||||
|
||||
|
@ -63,12 +74,7 @@ class ConfirmationActivity : ActivityBase() {
|
|||
if (imgSize!! > devSize)
|
||||
confirm_extra_info.text = getString(R.string.image_bigger_than_usb)
|
||||
else {
|
||||
var text =
|
||||
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)
|
||||
val text = getString(R.string.tap_next_to_write)
|
||||
confirm_extra_info.text = text
|
||||
canContinue = true
|
||||
}
|
||||
|
|
|
@ -13,9 +13,10 @@ import java.io.File
|
|||
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 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>()
|
||||
var ptType: PartitionTableType? = null
|
||||
var imgSize = 0L
|
||||
|
||||
val pb = ProcessBuilder(dmg2img.path, "-v", "-l", file.path)
|
||||
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.size = SECTOR_SIZE * sectorcount.toLong()
|
||||
imgSize += pb.size!!
|
||||
|
||||
if (label.isNotEmpty())
|
||||
pb.fsLabel = label
|
||||
|
@ -67,7 +69,7 @@ private fun readPartitionTable(dmg2img: File, libDir: String, file: File): Pair<
|
|||
pt.add(pb.build())
|
||||
}
|
||||
|
||||
return Pair(ptType, pt)
|
||||
return Triple(ptType, pt, imgSize)
|
||||
}
|
||||
|
||||
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 partTable: List<Partition>? = null
|
||||
private var partTableType: PartitionTableType? = null
|
||||
private var imgSize: Long? = null
|
||||
|
||||
private fun readInfo() {
|
||||
if (loaded)
|
||||
return
|
||||
val pair = readPartitionTable(dmg2img, libDir, File(uri.path))
|
||||
val triple = readPartitionTable(dmg2img, libDir, File(uri.path))
|
||||
loaded = true
|
||||
partTableType = pair.first
|
||||
partTable = pair.second
|
||||
partTableType = triple.first
|
||||
partTable = triple.second
|
||||
imgSize = triple.third
|
||||
}
|
||||
|
||||
override val partitionTable: List<Partition>?
|
||||
|
@ -99,4 +103,10 @@ class DMGImage(private val uri: Uri, private val context: Context) : Image {
|
|||
return partTableType
|
||||
}
|
||||
|
||||
override val size: Long?
|
||||
get() {
|
||||
readInfo()
|
||||
return imgSize
|
||||
}
|
||||
|
||||
}
|
|
@ -6,4 +6,5 @@ import eu.depau.etchdroid.utils.Partition
|
|||
interface Image {
|
||||
val partitionTable: List<Partition>?
|
||||
val tableType: PartitionTableType?
|
||||
val size: Long?
|
||||
}
|
|
@ -71,7 +71,6 @@
|
|||
<string name="fs_label">Label</string>
|
||||
<string name="fs_type">Type</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="this_app">This app</string>
|
||||
<string name="license_apache2_0">Apache 2.0</string>
|
||||
|
|
Loading…
Reference in a new issue