From f12d7160f840eaa2607002cf0be2e3e8c1b17941 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 26 Sep 2019 00:01:30 +0200 Subject: ANDROID: Added list of external storages to the list of accessible directories --- .../org/scummvm/scummvm/ExternalStorage.java | 36 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'backends/platform/android/org') diff --git a/backends/platform/android/org/scummvm/scummvm/ExternalStorage.java b/backends/platform/android/org/scummvm/scummvm/ExternalStorage.java index d8bab31517..acfd2393a4 100644 --- a/backends/platform/android/org/scummvm/scummvm/ExternalStorage.java +++ b/backends/platform/android/org/scummvm/scummvm/ExternalStorage.java @@ -115,7 +115,7 @@ public class ExternalStorage { } } hash += "]"; - if (!mountHash.contains(hash)){ + if (!mountHash.contains(hash)) { String key = SD_CARD + "_" + (map.size() / 2); if (map.size() == 0) { key = SD_CARD; @@ -134,10 +134,38 @@ public class ExternalStorage { map.add(DATA_DIRECTORY); map.add(Environment.getDataDirectory().getAbsolutePath()); - if (map.isEmpty()) { - map.add(SD_CARD); - map.add(Environment.getExternalStorageDirectory().getAbsolutePath()); + // Now go through the external storage + String state = Environment.getExternalStorageState(); + + if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) { // we can read the External Storage... + // Retrieve the primary External Storage: + File primaryExternalStorage = Environment.getExternalStorageDirectory(); + + //Retrieve the External Storages root directory: + String externalStorageRootDir; + int count = 0; + if ((externalStorageRootDir = primaryExternalStorage.getParent()) == null) { // no parent... + String key = primaryExternalStorage.getAbsolutePath(); + if (!map.contains(key)) { + map.add(key); // Make name as directory + map.add(key); + } + } else { + File externalStorageRoot = new File(externalStorageRootDir); + File[] files = externalStorageRoot.listFiles(); + + for (final File file : files) { + if (file.isDirectory() && file.canRead() && (file.listFiles().length > 0)) { // it is a real directory (not a USB drive)... + String key = file.getAbsolutePath(); + if (!map.contains(key)) { + map.add(key); // Make name as directory + map.add(key); + } + } + } + } } + return map; } } -- cgit v1.2.3