Skip to content

Commit

Permalink
Fix try-catch in save import (strato-emu#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloG02 authored Jan 29, 2024
1 parent 135b7f3 commit b4e7632
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.FilenameFilter
import java.io.IOException
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.zip.ZipEntry
Expand Down Expand Up @@ -170,8 +171,8 @@ interface SaveManagementUtils {

val filterTitleId = FilenameFilter { _, dirName -> dirName.matches(Regex("^0100[\\dA-Fa-f]{12}$")) }

try {
CoroutineScope(Dispatchers.IO).launch {
CoroutineScope(Dispatchers.IO).launch {
try {
ZipUtils.unzip(inputZip, cacheSaveDir)
cacheSaveDir.list(filterTitleId)?.forEach { savePath ->
File(savesFolder, savePath).deleteRecursively()
Expand All @@ -187,11 +188,13 @@ interface SaveManagementUtils {
onImportComplete()
Toast.makeText(context, R.string.save_file_imported_ok, Toast.LENGTH_LONG).show()
}

} catch (e : IOException) {
withContext(Dispatchers.Main) {
Toast.makeText(context, R.string.error, Toast.LENGTH_LONG).show()
}
} finally {
cacheSaveDir.deleteRecursively()
}
} catch (e : Exception) {
Toast.makeText(context, R.string.error, Toast.LENGTH_LONG).show()
}
}

Expand Down

0 comments on commit b4e7632

Please sign in to comment.