diff options
| author | 2023-06-02 14:23:25 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:06:08 -0700 | |
| commit | a789046127dba7b5d4c7510d730f1241c731a94a (patch) | |
| tree | 6e8f47fd1c3e7cb3660d69cd767943cdfd6b351c | |
| parent | android: vk_presentation_manager: Fix unusued needs_recreation. (diff) | |
| download | yuzu-a789046127dba7b5d4c7510d730f1241c731a94a.tar.gz yuzu-a789046127dba7b5d4c7510d730f1241c731a94a.tar.xz yuzu-a789046127dba7b5d4c7510d730f1241c731a94a.zip | |
android: Fix crash on importing invalid save
Diffstat (limited to '')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ImportExportSavesFragment.kt | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ImportExportSavesFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ImportExportSavesFragment.kt index 7a990d0cc..5f107b37d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ImportExportSavesFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ImportExportSavesFragment.kt | |||
| @@ -11,6 +11,7 @@ import android.provider.DocumentsContract | |||
| 11 | import android.widget.Toast | 11 | import android.widget.Toast |
| 12 | import androidx.activity.result.ActivityResultLauncher | 12 | import androidx.activity.result.ActivityResultLauncher |
| 13 | import androidx.activity.result.contract.ActivityResultContracts | 13 | import androidx.activity.result.contract.ActivityResultContracts |
| 14 | import androidx.appcompat.app.AppCompatActivity | ||
| 14 | import androidx.documentfile.provider.DocumentFile | 15 | import androidx.documentfile.provider.DocumentFile |
| 15 | import androidx.fragment.app.DialogFragment | 16 | import androidx.fragment.app.DialogFragment |
| 16 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 17 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| @@ -49,6 +50,7 @@ class ImportExportSavesFragment : DialogFragment() { | |||
| 49 | 50 | ||
| 50 | override fun onCreate(savedInstanceState: Bundle?) { | 51 | override fun onCreate(savedInstanceState: Bundle?) { |
| 51 | super.onCreate(savedInstanceState) | 52 | super.onCreate(savedInstanceState) |
| 53 | val activity = requireActivity() as AppCompatActivity | ||
| 52 | 54 | ||
| 53 | val activityResultRegistry = requireActivity().activityResultRegistry | 55 | val activityResultRegistry = requireActivity().activityResultRegistry |
| 54 | startForResultExportSave = activityResultRegistry.register( | 56 | startForResultExportSave = activityResultRegistry.register( |
| @@ -61,7 +63,7 @@ class ImportExportSavesFragment : DialogFragment() { | |||
| 61 | "documentPickerKey", | 63 | "documentPickerKey", |
| 62 | ActivityResultContracts.OpenDocument() | 64 | ActivityResultContracts.OpenDocument() |
| 63 | ) { | 65 | ) { |
| 64 | it?.let { uri -> importSave(uri) } | 66 | it?.let { uri -> importSave(uri, activity) } |
| 65 | } | 67 | } |
| 66 | } | 68 | } |
| 67 | 69 | ||
| @@ -183,7 +185,7 @@ class ImportExportSavesFragment : DialogFragment() { | |||
| 183 | * Imports the save files contained in the zip file, and replaces any existing ones with the new save file. | 185 | * Imports the save files contained in the zip file, and replaces any existing ones with the new save file. |
| 184 | * @param zipUri The Uri of the zip file containing the save file(s) to import. | 186 | * @param zipUri The Uri of the zip file containing the save file(s) to import. |
| 185 | */ | 187 | */ |
| 186 | private fun importSave(zipUri: Uri) { | 188 | private fun importSave(zipUri: Uri, activity: AppCompatActivity) { |
| 187 | val inputZip = context.contentResolver.openInputStream(zipUri) | 189 | val inputZip = context.contentResolver.openInputStream(zipUri) |
| 188 | // A zip needs to have at least one subfolder named after a TitleId in order to be considered valid. | 190 | // A zip needs to have at least one subfolder named after a TitleId in order to be considered valid. |
| 189 | var validZip = false | 191 | var validZip = false |
| @@ -214,7 +216,7 @@ class ImportExportSavesFragment : DialogFragment() { | |||
| 214 | MessageDialogFragment.newInstance( | 216 | MessageDialogFragment.newInstance( |
| 215 | R.string.save_file_invalid_zip_structure, | 217 | R.string.save_file_invalid_zip_structure, |
| 216 | R.string.save_file_invalid_zip_structure_description | 218 | R.string.save_file_invalid_zip_structure_description |
| 217 | ).show(childFragmentManager, MessageDialogFragment.TAG) | 219 | ).show(activity.supportFragmentManager, MessageDialogFragment.TAG) |
| 218 | return@withContext | 220 | return@withContext |
| 219 | } | 221 | } |
| 220 | Toast.makeText( | 222 | Toast.makeText( |