From 7d64c654cc399a4e4b4386f27b8e8528632c21d5 Mon Sep 17 00:00:00 2001 From: hank121314 Date: Thu, 6 Apr 2023 00:50:53 +0800 Subject: [PATCH] citra_android: fix select root as citra directory cause crash (#6400) --- .../main/java/org/citra/citra_emu/utils/FileUtil.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/android/app/src/main/java/org/citra/citra_emu/utils/FileUtil.java b/src/android/app/src/main/java/org/citra/citra_emu/utils/FileUtil.java index a19d15b6a..b99a35bc0 100644 --- a/src/android/app/src/main/java/org/citra/citra_emu/utils/FileUtil.java +++ b/src/android/app/src/main/java/org/citra/citra_emu/utils/FileUtil.java @@ -425,9 +425,12 @@ public class FileUtil { } public static String getFilenameWithExtensions(Uri uri) { - final String path = uri.getPath(); - final int index = path.lastIndexOf('/'); - return path.substring(index + 1); + String path = uri.getPath(); + final int slashIndex = path.lastIndexOf('/'); + path = path.substring(slashIndex + 1); + // On Android versions below 10, it is possible to select the storage root, which might result in filenames with a colon. + final int colonIndex = path.indexOf(':'); + return path.substring(colonIndex + 1); } public static double getFreeSpace(Context context, Uri uri) {