From 8aba748735e83ed5865a2e78f6af9d966e0017b2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 26 Sep 2013 23:06:10 -0400 Subject: [PATCH] [Android] Fix a situation within the FolderBrowser where the application would crash. listFiles() returns null when either the File object it's called on isn't a directory or if an I/O error happens (in their infinite wisdom, they actually thought NOT throwing an exception was a cool way to handle this. How about that?). In the case of trying to access system directories as a normal user, an I/O error will occur due to permission access rights. This fixes that. --- .../folderbrowser/FolderBrowser.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/folderbrowser/FolderBrowser.java b/Source/Android/src/org/dolphinemu/dolphinemu/folderbrowser/FolderBrowser.java index e28f30206d..e8a3fd9c94 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/folderbrowser/FolderBrowser.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/folderbrowser/FolderBrowser.java @@ -48,39 +48,43 @@ public final class FolderBrowser extends ListFragment { m_activity.setTitle(getString(R.string.current_dir) + currDir.getName()); File[] dirs = currDir.listFiles(); - Listdir = new ArrayList(); - Listfls = new ArrayList(); + List dir = new ArrayList(); + List fls = new ArrayList(); // Supported extensions to filter by Set validExts = new HashSet(Arrays.asList(".dff", ".dol", ".elf", ".gcm", ".gcz", ".iso", ".wad", ".wbfs")); - // Search for any directories or files within the current dir. - for(File entry : dirs) + // If dirs is null, then we don't have access permissions to the selected folder. + if (dirs != null) { - try + // Search for any directories or files within the current dir. + for(File entry : dirs) { - String entryName = entry.getName(); - boolean hasExtension = (entryName.lastIndexOf(".") != -1); - - // Skip hidden folders/files. - if (!entry.isHidden()) + try { - if(entry.isDirectory()) + String entryName = entry.getName(); + boolean hasExtension = (entryName.lastIndexOf(".") != -1); + + // Skip hidden folders/files. + if (!entry.isHidden()) { - dir.add(new FolderBrowserItem(entryName, entry.getAbsolutePath())); - } - else if (entry.isFile() && hasExtension) - { - if (validExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.')))) + if(entry.isDirectory()) { - fls.add(new FolderBrowserItem(entryName, getString(R.string.file_size)+entry.length(), entry.getAbsolutePath())); + dir.add(new FolderBrowserItem(entryName, entry.getAbsolutePath())); + } + else if (entry.isFile() && hasExtension) + { + if (validExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.')))) + { + fls.add(new FolderBrowserItem(entryName, getString(R.string.file_size)+entry.length(), entry.getAbsolutePath())); + } } } } - } - catch (Exception ex) - { - Log.e("FolderBrowser", ex.toString()); + catch (Exception ex) + { + Log.e("FolderBrowser", ex.toString()); + } } }