Skip to content

Commit

Permalink
Don't read binary data when not importing it
Browse files Browse the repository at this point in the history
  • Loading branch information
tmo1 committed Jul 25, 2023
1 parent d9d631a commit f142157
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions app/src/main/java/com/github/tmo1/sms_ie/ImportExportMessages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ suspend fun importMessages(
)
return@let
}
setStatusText(statusReportText, appContext.getString(R.string.importing_messages))
setStatusText(
statusReportText, appContext.getString(R.string.importing_messages)
)
BufferedReader(InputStreamReader(zipInputStream)).useLines { lines ->
lines.forEach JSONLine@{ line ->
try {
Expand Down Expand Up @@ -607,38 +609,43 @@ suspend fun importMessages(
}
}
}
setStatusText(statusReportText, appContext.getString(R.string.copying_mms_binary_data))
val buffer = ByteArray(1048576)
appContext.contentResolver.openInputStream(zipUri).use { inputStream ->
ZipInputStream(inputStream).use { zipInputStream ->
var zipEntry = zipInputStream.nextEntry
while (zipEntry != null) {
if (zipEntry.name.startsWith("data/")) {
val partUri = mmsPartMap[zipEntry.name.substring(5)]
partUri?.let {
//Log.v(LOG_TAG, "Processing part: $zipEntry")
//Log.v(LOG_TAG, "Writing to: $partUri")
appContext.contentResolver.openOutputStream(
partUri
)?.use { outputStream ->
var n = zipInputStream.read(
buffer
)
while (n > -1) {
//Log.v(LOG_TAG, "Read $n bytes")
outputStream.write(
buffer, 0, n
)
n = zipInputStream.read(
if (prefs.getBoolean("include_binary_data", true)) {
setStatusText(
statusReportText, appContext.getString(R.string.copying_mms_binary_data)
)
val buffer = ByteArray(1048576)
appContext.contentResolver.openInputStream(zipUri).use { inputStream ->
ZipInputStream(inputStream).use { zipInputStream ->
var zipEntry = zipInputStream.nextEntry
while (zipEntry != null) {
if (zipEntry.name.startsWith("data/")) {
val partUri = mmsPartMap[zipEntry.name.substring(5)]
partUri?.let {
//Log.v(LOG_TAG, "Processing part: $zipEntry")
//Log.v(LOG_TAG, "Writing to: $partUri")
appContext.contentResolver.openOutputStream(
partUri
)?.use { outputStream ->
var n = zipInputStream.read(
buffer
)
}
} ?: Log.e(
LOG_TAG, "Error opening OutputStream to write MMS binary data"
)
while (n > -1) {
//Log.v(LOG_TAG, "Read $n bytes")
outputStream.write(
buffer, 0, n
)
n = zipInputStream.read(
buffer
)
}
} ?: Log.e(
LOG_TAG,
"Error opening OutputStream to write MMS binary data"
)
}
}
zipEntry = zipInputStream.nextEntry
}
zipEntry = zipInputStream.nextEntry
}
}
}
Expand Down

0 comments on commit f142157

Please sign in to comment.