diff options
| author | 2023-04-24 01:59:41 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:05:53 -0700 | |
| commit | 83dae1739cc0afd451ed8b03db9f68fc8908f2f0 (patch) | |
| tree | 7b59a06711a3b38ae15ba02c0aaf84bd33cdfd72 /src/android | |
| parent | android: Fix first time setup scrolling bug (diff) | |
| download | yuzu-83dae1739cc0afd451ed8b03db9f68fc8908f2f0.tar.gz yuzu-83dae1739cc0afd451ed8b03db9f68fc8908f2f0.tar.xz yuzu-83dae1739cc0afd451ed8b03db9f68fc8908f2f0.zip | |
android: Show error if invalid keys file is selected
There aren't MIME types specific enough for filtering out files that aren't amiibo or production keys. So here we just check for the extensions "bin" or "keys" where appropriate and stop the process if incorrect. Previously you could select any document and it could cause the app to hang.
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 22 | ||||
| -rw-r--r-- | src/android/app/src/main/res/values/strings.xml | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index b455b7d35..c03c28aa1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt | |||
| @@ -180,6 +180,10 @@ class MainActivity : AppCompatActivity() { | |||
| 180 | windowInsets | 180 | windowInsets |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | private fun hasExtension(path: String, extension: String): Boolean { | ||
| 184 | return path.substring(path.lastIndexOf(".") + 1).contains(extension) | ||
| 185 | } | ||
| 186 | |||
| 183 | val getGamesDirectory = | 187 | val getGamesDirectory = |
| 184 | registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result -> | 188 | registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result -> |
| 185 | if (result == null) | 189 | if (result == null) |
| @@ -212,6 +216,15 @@ class MainActivity : AppCompatActivity() { | |||
| 212 | if (result == null) | 216 | if (result == null) |
| 213 | return@registerForActivityResult | 217 | return@registerForActivityResult |
| 214 | 218 | ||
| 219 | if (!hasExtension(result.toString(), "keys")) { | ||
| 220 | Toast.makeText( | ||
| 221 | applicationContext, | ||
| 222 | R.string.invalid_keys_file, | ||
| 223 | Toast.LENGTH_SHORT | ||
| 224 | ).show() | ||
| 225 | return@registerForActivityResult | ||
| 226 | } | ||
| 227 | |||
| 215 | val takeFlags = | 228 | val takeFlags = |
| 216 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION | 229 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION |
| 217 | contentResolver.takePersistableUriPermission( | 230 | contentResolver.takePersistableUriPermission( |
| @@ -243,6 +256,15 @@ class MainActivity : AppCompatActivity() { | |||
| 243 | if (result == null) | 256 | if (result == null) |
| 244 | return@registerForActivityResult | 257 | return@registerForActivityResult |
| 245 | 258 | ||
| 259 | if (!hasExtension(result.toString(), "bin")) { | ||
| 260 | Toast.makeText( | ||
| 261 | applicationContext, | ||
| 262 | R.string.invalid_keys_file, | ||
| 263 | Toast.LENGTH_SHORT | ||
| 264 | ).show() | ||
| 265 | return@registerForActivityResult | ||
| 266 | } | ||
| 267 | |||
| 246 | val takeFlags = | 268 | val takeFlags = |
| 247 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION | 269 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION |
| 248 | contentResolver.takePersistableUriPermission( | 270 | contentResolver.takePersistableUriPermission( |
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 916f516c0..92fe67bf0 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | <string name="install_prod_keys_description">Required to decrypt retail games</string> | 35 | <string name="install_prod_keys_description">Required to decrypt retail games</string> |
| 36 | <string name="install_amiibo_keys">Install Amiibo Keys</string> | 36 | <string name="install_amiibo_keys">Install Amiibo Keys</string> |
| 37 | <string name="install_amiibo_keys_description">Required to use Amiibo in game</string> | 37 | <string name="install_amiibo_keys_description">Required to use Amiibo in game</string> |
| 38 | <string name="invalid_keys_file">Invalid keys file selected</string> | ||
| 38 | <string name="install_keys_success">Keys successfully installed</string> | 39 | <string name="install_keys_success">Keys successfully installed</string> |
| 39 | <string name="install_keys_failure">Keys file (prod.keys) is invalid</string> | 40 | <string name="install_keys_failure">Keys file (prod.keys) is invalid</string> |
| 40 | <string name="install_amiibo_keys_failure">Keys file (key_retail.bin) is invalid</string> | 41 | <string name="install_amiibo_keys_failure">Keys file (key_retail.bin) is invalid</string> |