From dd4e9fd42e189614262fe5449ffc65ce6269d45c Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 25 Feb 2014 15:41:31 -0800 Subject: #294 Auto reset cache location when it is no longer available --- .../dsub/activity/SubsonicFragmentActivity.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java index 7444229b..7e047a94 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicFragmentActivity.java @@ -434,9 +434,14 @@ public class SubsonicFragmentActivity extends SubsonicActivity { PreferenceManager.setDefaultValues(this, R.xml.settings, false); SharedPreferences prefs = Util.getPreferences(this); if (!prefs.contains(Constants.PREFERENCES_KEY_CACHE_LOCATION)) { - SharedPreferences.Editor editor = prefs.edit(); - editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory(this).getPath()); - editor.commit(); + resetCacheLocation(prefs); + } else { + String path = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); + File cacheLocation = new File(path); + if(!FileUtil.ensureDirectoryExistsAndIsReadWritable(cacheLocation)) { + resetCacheLocation(prefs); + Util.info(this, R.string.common_warning, R.string.settings_cache_location_reset); + } } if (!prefs.contains(Constants.PREFERENCES_KEY_OFFLINE)) { @@ -457,6 +462,12 @@ public class SubsonicFragmentActivity extends SubsonicActivity { } } + private void resetCacheLocation(SharedPreferences prefs) { + SharedPreferences.Editor editor = prefs.edit(); + editor.putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, FileUtil.getDefaultMusicDirectory(this).getPath()); + editor.commit(); + } + private void createAccount() { final Context context = this; -- cgit v1.2.3