Avoid writing zeroes because of Java ByteBuffer's weirdness
This commit is contained in:
parent
3094576fa9
commit
4ca93839e2
1 changed files with 6 additions and 3 deletions
|
@ -10,6 +10,8 @@ import eu.depau.ddroid.utils.name
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
class UsbAPIWriteService : UsbWriteService("UsbAPIWriteService") {
|
class UsbAPIWriteService : UsbWriteService("UsbAPIWriteService") {
|
||||||
|
val DD_BLOCKSIZE = 4096
|
||||||
|
|
||||||
class Action {
|
class Action {
|
||||||
val WRITE_IMAGE = "eu.depau.ddroid.action.API_WRITE_IMAGE"
|
val WRITE_IMAGE = "eu.depau.ddroid.action.API_WRITE_IMAGE"
|
||||||
val WRITE_CANCEL = "eu.depau.ddroid.action.API_WRITE_CANCEL"
|
val WRITE_CANCEL = "eu.depau.ddroid.action.API_WRITE_CANCEL"
|
||||||
|
@ -45,7 +47,8 @@ class UsbAPIWriteService : UsbWriteService("UsbAPIWriteService") {
|
||||||
msDev.init()
|
msDev.init()
|
||||||
|
|
||||||
val blockDev = msDev.blockDevice
|
val blockDev = msDev.blockDevice
|
||||||
val byteBuffer = ByteBuffer.allocate(blockDev.blockSize)
|
var bsFactor = DD_BLOCKSIZE / blockDev.blockSize
|
||||||
|
val byteBuffer = ByteBuffer.allocate(blockDev.blockSize * bsFactor)
|
||||||
val imageSize = uri.getFileSize(this)
|
val imageSize = uri.getFileSize(this)
|
||||||
val inputStream = contentResolver.openInputStream(uri)!!
|
val inputStream = contentResolver.openInputStream(uri)!!
|
||||||
|
|
||||||
|
@ -56,12 +59,12 @@ class UsbAPIWriteService : UsbWriteService("UsbAPIWriteService") {
|
||||||
readBytes = inputStream.read(byteBuffer.array()!!)
|
readBytes = inputStream.read(byteBuffer.array()!!)
|
||||||
if (readBytes < 0)
|
if (readBytes < 0)
|
||||||
break
|
break
|
||||||
|
byteBuffer.position(0)
|
||||||
|
|
||||||
byteBuffer.position(readBytes)
|
|
||||||
blockDev.write(offset, byteBuffer)
|
blockDev.write(offset, byteBuffer)
|
||||||
offset++
|
offset++
|
||||||
|
|
||||||
notify(offset * blockDev.blockSize, imageSize)
|
notify(offset * blockDev.blockSize * bsFactor, imageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
msDev.close()
|
msDev.close()
|
||||||
|
|
Loading…
Reference in a new issue