Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Fix a situation within the FolderBrowser where the applicat…
…ion 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.
  • Loading branch information
lioncash committed Sep 27, 2013
1 parent bea76ac commit 8aba748
Showing 1 changed file with 25 additions and 21 deletions.
Expand Up @@ -48,39 +48,43 @@ private void Fill(File currDir)
{
m_activity.setTitle(getString(R.string.current_dir) + currDir.getName());
File[] dirs = currDir.listFiles();
List<FolderBrowserItem>dir = new ArrayList<FolderBrowserItem>();
List<FolderBrowserItem>fls = new ArrayList<FolderBrowserItem>();
List<FolderBrowserItem> dir = new ArrayList<FolderBrowserItem>();
List<FolderBrowserItem> fls = new ArrayList<FolderBrowserItem>();

// Supported extensions to filter by
Set<String> validExts = new HashSet<String>(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())
{
dir.add(new FolderBrowserItem(entryName, entry.getAbsolutePath()));
}
else if (entry.isFile() && hasExtension)
String entryName = entry.getName();
boolean hasExtension = (entryName.lastIndexOf(".") != -1);

// Skip hidden folders/files.
if (!entry.isHidden())
{
if (validExts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
if(entry.isDirectory())
{
dir.add(new FolderBrowserItem(entryName, entry.getAbsolutePath()));
}
else if (entry.isFile() && hasExtension)
{
fls.add(new FolderBrowserItem(entryName, getString(R.string.file_size)+entry.length(), entry.getAbsolutePath()));
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());
}
}
}

Expand Down

0 comments on commit 8aba748

Please sign in to comment.