You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/02/11 00:23:14 UTC

[48/50] git commit: CB-5915: CB-5916: Reorganize preference code to make defaults possible

CB-5915: CB-5916: Reorganize preference code to make defaults possible


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/d8c5e5dc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/d8c5e5dc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/d8c5e5dc

Branch: refs/heads/master
Commit: d8c5e5dc8063658c863d4f5f13e18fdcf6383804
Parents: f4ed88d
Author: Ian Clelland <ic...@chromium.org>
Authored: Wed Feb 5 16:23:39 2014 -0500
Committer: Ian Clelland <ic...@chromium.org>
Committed: Wed Feb 5 16:23:39 2014 -0500

----------------------------------------------------------------------
 src/android/FileUtils.java | 49 +++++++++++++++++++++--------------------
 src/ios/CDVFile.m          |  6 +++--
 2 files changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8c5e5dc/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 26e3479..8e6646b 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -104,31 +104,30 @@ public class FileUtils extends CordovaPlugin {
     	String packageName = activity.getPackageName();
     	
     	String location = activity.getIntent().getStringExtra("androidpersistentfilelocation");
-    	if (location == null || !(location.equalsIgnoreCase("internal") || location.equalsIgnoreCase("compatibility"))) {
-    		Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
-    		activity.finish();
-    	}
-    	else {
-    		if (location.equalsIgnoreCase("internal")) {
-    			persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
-    			tempRoot = activity.getCacheDir().getAbsolutePath();
+    	if ("internal".equalsIgnoreCase(location)) {
+    		persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
+    		tempRoot = activity.getCacheDir().getAbsolutePath();
+    		this.configured = true;
+    	} else if ("compatibility".equalsIgnoreCase(location)) {
+    		/*
+    		 *  Fall-back to compatibility mode -- this is the logic implemented in
+    		 *  earlier versions of this plugin, and should be maintained here so
+    		 *  that apps which were originally deployed with older versions of the
+    		 *  plugin can continue to provide access to files stored under those
+    		 *  versions.
+    		 */
+    		if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+    			persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
+    			tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
+    					"/Android/data/" + packageName + "/cache/";
     		} else {
-    			/*
-    			 *  Fall-back to compatibility mode -- this is the logic implemented in
-    			 *  earlier versions of this plugin, and should be maintained here so
-    			 *  that apps which were originally deployed with older versions of the
-    			 *  plugin can continue to provide access to files stored under those
-    			 *  versions.
-    			 */
-    			if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
-    				persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
-    				tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
-    						"/Android/data/" + packageName + "/cache/";
-    			} else {
-    				persistentRoot = "/data/data/" + packageName;
-    				tempRoot = "/data/data/" + packageName + "/cache/";
-    			}
+    			persistentRoot = "/data/data/" + packageName;
+    			tempRoot = "/data/data/" + packageName + "/cache/";
     		}
+    		this.configured = true;
+    	}
+
+    	if (this.configured) {
 			// Create the directories if they don't exist.
 			new File(tempRoot).mkdirs();
 			new File(persistentRoot).mkdirs();
@@ -141,12 +140,14 @@ public class FileUtils extends CordovaPlugin {
     		this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot));
     		this.registerFilesystem(new ContentFilesystem("content", cordova, webView));
 
-           this.configured = true;
 
     		// Initialize static plugin reference for deprecated getEntry method
     		if (filePlugin == null) {
     			FileUtils.filePlugin = this;
     		}
+    	} else {
+    		Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
+    		activity.finish();
     	}
     }
     

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/d8c5e5dc/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index b1925d0..d07cc9c 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -216,8 +216,7 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
             } else {
                 NSLog(@"Unable to create library directory: %@", error);
             }
-        } else {
-            // Compatibilty by default (if we're not embedded in a CDVViewController somehow.)
+        } else if ([location isEqualToString:@"compatibility"]) {
             /*
              *  Fall-back to compatibility mode -- this is the logic implemented in
              *  earlier versions of this plugin, and should be maintained here so
@@ -226,6 +225,9 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
              *  versions.
              */
             [self registerFilesystem:[[CDVLocalFilesystem alloc] initWithName:@"persistent" root:self.rootDocsPath]];
+        } else {
+            NSAssert(false,
+                @"File plugin configuration error: Please set iosPersistentFileLocation in config.xml to one of \"library\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
         }
         [self registerFilesystem:[[CDVAssetLibraryFilesystem alloc] initWithName:@"assets-library"]];
     }