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 b455b7d351..c03c28aa1b 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() {
windowInsets
}
+ private fun hasExtension(path: String, extension: String): Boolean {
+ return path.substring(path.lastIndexOf(".") + 1).contains(extension)
+ }
+
val getGamesDirectory =
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->
if (result == null)
@@ -212,6 +216,15 @@ class MainActivity : AppCompatActivity() {
if (result == null)
return@registerForActivityResult
+ if (!hasExtension(result.toString(), "keys")) {
+ Toast.makeText(
+ applicationContext,
+ R.string.invalid_keys_file,
+ Toast.LENGTH_SHORT
+ ).show()
+ return@registerForActivityResult
+ }
+
val takeFlags =
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
contentResolver.takePersistableUriPermission(
@@ -243,6 +256,15 @@ class MainActivity : AppCompatActivity() {
if (result == null)
return@registerForActivityResult
+ if (!hasExtension(result.toString(), "bin")) {
+ Toast.makeText(
+ applicationContext,
+ R.string.invalid_keys_file,
+ Toast.LENGTH_SHORT
+ ).show()
+ return@registerForActivityResult
+ }
+
val takeFlags =
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
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 916f516c0a..92fe67bf01 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 @@
Required to decrypt retail games
Install Amiibo Keys
Required to use Amiibo in game
+ Invalid keys file selected
Keys successfully installed
Keys file (prod.keys) is invalid
Keys file (key_retail.bin) is invalid