From b4e763202f593502dadce7dc8e3669117db5667b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= <71378035+PabloG02@users.noreply.github.com> Date: Mon, 29 Jan 2024 17:09:29 +0100 Subject: [PATCH] Fix try-catch in save import (#197) --- .../stratoemu/strato/utils/SaveManagementUtils.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/stratoemu/strato/utils/SaveManagementUtils.kt b/app/src/main/java/org/stratoemu/strato/utils/SaveManagementUtils.kt index 97e0a3e26..8cef9304f 100644 --- a/app/src/main/java/org/stratoemu/strato/utils/SaveManagementUtils.kt +++ b/app/src/main/java/org/stratoemu/strato/utils/SaveManagementUtils.kt @@ -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 @@ -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() @@ -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() } }