You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/05/16 03:01:23 UTC
git commit: CB-285 Add cordova.file.*Directory properties for iOS &
Android
Repository: cordova-plugin-file
Updated Branches:
refs/heads/master bff46b6fc -> 856b8c5cf
CB-285 Add cordova.file.*Directory properties for iOS & Android
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/856b8c5c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/856b8c5c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/856b8c5c
Branch: refs/heads/master
Commit: 856b8c5cf3ccbfa36cf61ac4b6cd14bf26aeef88
Parents: bff46b6
Author: Andrew Grieve <ag...@chromium.org>
Authored: Tue May 13 21:46:13 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu May 15 21:01:09 2014 -0400
----------------------------------------------------------------------
plugin.xml | 9 ++++++
src/android/FileUtils.java | 20 ++++++++++++++
src/ios/CDVFile.m | 30 ++++++++++++++++++++
www/fileSystemPaths.js | 61 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 120 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/856b8c5c/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 731c51b..21f177e 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -135,6 +135,10 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<js-module src="www/fileSystems-roots.js" name="fileSystems-roots">
<runs/>
</js-module>
+ <js-module src="www/fileSystemPaths.js" name="fileSystemPaths">
+ <merges target="cordova" />
+ <runs/>
+ </js-module>
</platform>
<!-- amazon-fireos -->
@@ -208,6 +212,11 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<runs/>
</js-module>
+ <js-module src="www/fileSystemPaths.js" name="fileSystemPaths">
+ <merges target="cordova" />
+ <runs/>
+ </js-module>
+
<framework src="AssetsLibrary.framework" />
<framework src="MobileCoreServices.framework" />
</platform>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/856b8c5c/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 5fbe1f6..9233a62 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -344,6 +344,8 @@ public class FileUtils extends CordovaPlugin {
callbackContext.success(requestAllFileSystems());
}
}, callbackContext);
+ } else if (action.equals("requestAllPaths")) {
+ callbackContext.success(requestAllPaths());
} else if (action.equals("requestFileSystem")) {
final int fstype=args.getInt(0);
final long size = args.optLong(1);
@@ -850,6 +852,24 @@ public class FileUtils extends CordovaPlugin {
return ret;
}
+ private static String toDirUrl(File f) {
+ return Uri.fromFile(f).toString() + '/';
+ }
+
+ private JSONObject requestAllPaths() throws JSONException {
+ Context context = cordova.getActivity();
+ JSONObject ret = new JSONObject();
+ ret.put("applicationDirectory", "file:///android_asset/");
+ ret.put("applicationStorageDirectory", toDirUrl(context.getFilesDir().getParentFile()));
+ ret.put("dataDirectory", toDirUrl(context.getFilesDir()));
+ ret.put("cacheDirectory", toDirUrl(context.getCacheDir()));
+ ret.put("externalApplicationStorageDirectory", toDirUrl(context.getExternalFilesDir(null).getParentFile()));
+ ret.put("externalDataDirectory", toDirUrl(context.getExternalFilesDir(null)));
+ ret.put("externalCacheDirectory", toDirUrl(context.getExternalCacheDir()));
+ ret.put("externalRootDirectory", toDirUrl(Environment.getExternalStorageDirectory()));
+ return ret;
+ }
+
/**
* Returns a JSON object representing the given File. Internal APIs should be modified
* to use URLs instead of raw FS paths wherever possible, when interfacing with this plugin.
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/856b8c5c/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 11b8dd3..b22b7cf 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -458,6 +458,36 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
+- (void)requestAllPaths:(CDVInvokedUrlCommand*)command
+{
+ NSString* libPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];
+ NSString* libPathSync = [libPath stringByAppendingPathComponent:@"Cloud"];
+ NSString* libPathNoSync = [libPath stringByAppendingPathComponent:@"NoCloud"];
+ NSString* docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
+ NSString* storagePath = [libPath stringByDeletingLastPathComponent];
+ NSString* cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
+
+ // Create the directories if necessary.
+ [[NSFileManager defaultManager] createDirectoryAtPath:libPathSync withIntermediateDirectories:YES attributes:nil error:nil];
+ [[NSFileManager defaultManager] createDirectoryAtPath:libPathNoSync withIntermediateDirectories:YES attributes:nil error:nil];
+ // Mark NoSync as non-iCloud.
+ [[NSURL fileURLWithPath:libPathNoSync] setResourceValue: [NSNumber numberWithBool: YES]
+ forKey: NSURLIsExcludedFromBackupKey error:nil];
+
+ NSDictionary* ret = @{
+ @"applicationDirectory": [[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]] absoluteString],
+ @"applicationStorageDirectory": [[NSURL fileURLWithPath:storagePath] absoluteString],
+ @"dataDirectory": [[NSURL fileURLWithPath:libPathNoSync] absoluteString],
+ @"syncedDataDirectory": [[NSURL fileURLWithPath:libPathSync] absoluteString],
+ @"documentsDirectory": [[NSURL fileURLWithPath:docPath] absoluteString],
+ @"cacheDirectory": [[NSURL fileURLWithPath:cachePath] absoluteString],
+ @"tempDirectory": [[NSURL fileURLWithPath:NSTemporaryDirectory()] absoluteString]
+ };
+
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:ret];
+ [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
+}
+
/* Creates and returns a dictionary representing an Entry Object
*
* IN:
http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/856b8c5c/www/fileSystemPaths.js
----------------------------------------------------------------------
diff --git a/www/fileSystemPaths.js b/www/fileSystemPaths.js
new file mode 100644
index 0000000..8ef0bb8
--- /dev/null
+++ b/www/fileSystemPaths.js
@@ -0,0 +1,61 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var exec = require('cordova/exec');
+var channel = require('cordova/channel');
+
+exports.file = {
+ // Read-only directory where the application is installed.
+ applicationDirectory: null,
+ // Root of app's private writable storage
+ applicationStorageDirectory: null,
+ // Where to put app-specific data files.
+ dataDirectory: null,
+ // Cached files that should survive app restarts.
+ // Apps should not rely on the OS to delete files in here.
+ cacheDirectory: null,
+ // Android: the application space on external storage.
+ externalApplicationStorageDirectory: null,
+ // Android: Where to put app-specific data files on external storage.
+ externalDataDirectory: null,
+ // Android: the application cache on external storage.
+ externalCacheDirectory: null,
+ // Android: the external storage (SD card) root.
+ externalRootDirectory: null,
+ // iOS: Temp directory that the OS can clear at will.
+ tempDirectory: null,
+ // iOS: Holds app-specific files that should be synced (e.g. to iCloud).
+ syncedDataDirectory: null,
+ // iOS: Files private to the app, but that are meaningful to other applciations (e.g. Office files)
+ documentsDirectory: null
+};
+
+channel.waitForInitialization('onFileSystemPathsReady');
+channel.onCordovaReady.subscribe(function() {
+ function after(paths) {
+ for (var k in paths) {
+ exports.file[k] = paths[k];
+ }
+ channel.initializationComplete('onFileSystemPathsReady');
+ }
+ exec(after, null, 'File', 'requestAllPaths', []);
+});
+