diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2013-01-08 14:24:58 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2013-01-08 14:24:58 +0100 |
commit | a358917d95b169a0c03c445a3ca816a0d2fb26a6 (patch) | |
tree | 84fd5f46d8d098487fffda47e1f6c7542d61ae41 /main/src | |
parent | 5dbb83845f49d381c3575ab07b2414d1fbf9f456 (diff) | |
download | cgeo-a358917d95b169a0c03c445a3ca816a0d2fb26a6.zip cgeo-a358917d95b169a0c03c445a3ca816a0d2fb26a6.tar.gz cgeo-a358917d95b169a0c03c445a3ca816a0d2fb26a6.tar.bz2 |
fix #2361: index out of bounds in dir chooser
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/files/SimpleDirChooser.java | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/files/SimpleDirChooser.java b/main/src/cgeo/geocaching/files/SimpleDirChooser.java index 346780d..404777a 100644 --- a/main/src/cgeo/geocaching/files/SimpleDirChooser.java +++ b/main/src/cgeo/geocaching/files/SimpleDirChooser.java @@ -43,13 +43,7 @@ public class SimpleDirChooser extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Bundle extras = getIntent().getExtras(); - String startDir = extras.getString(START_DIR); - if (StringUtils.isBlank(startDir)) { - startDir = Environment.getExternalStorageDirectory().getPath(); - } else { - startDir = startDir.substring(0, startDir.lastIndexOf(File.separatorChar)); - } - currentDir = new File(startDir); + currentDir = dirContaining(extras.getString(START_DIR)); ActivityMixin.setTheme(this); setContentView(R.layout.simple_dir_chooser); @@ -82,6 +76,18 @@ public class SimpleDirChooser extends ListActivity { }); } + /** + * Return the directory containing a given path, or a sensible default. + * + * @param path the path to get the enclosing directory from, can be null or empty + * @return the directory containing <code>path</code>, or a sensible default if none + */ + private static File dirContaining(final String path) { + return StringUtils.contains(path, File.separatorChar) ? + new File(StringUtils.substringBeforeLast(path, Character.toString(File.separatorChar))) : + Environment.getExternalStorageDirectory(); + } + private void fill(File dir) { EditText path = (EditText) findViewById(R.id.simple_dir_chooser_path); path.setText(this.getResources().getString(R.string.simple_dir_chooser_current_path) + " " + dir.getAbsolutePath()); |