[File] Added using encoding to url paths.
authorTomasz Marciniak <t.marciniak@samsung.com>
Tue, 17 Nov 2015 08:44:23 +0000 (09:44 +0100)
committerTomasz Marciniak <t.marciniak@samsung.com>
Tue, 17 Nov 2015 08:44:23 +0000 (09:44 +0100)
[Feature] Now nativeURLs are encoded. Cordova.file paths
are changed to URI paths.

[Verification] Code compiles. pass rate: 140/140, all manual tests pass.

Change-Id: Ia2c05c0cdad53523d0d03987e9b58573f19f9241
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/file/js/fileSystemPaths.js
src/file/js/rootsUtils.js

index 80bdba4..e968d6c 100644 (file)
@@ -19,27 +19,36 @@ cordova.define('cordova-plugin-file.tizen.fileSystemPaths', function(require, ex
 // TODO: remove -> end
 
 var pathsPrefix = {
-  applicationDirectory: 'wgt-package/',
-  dataDirectory: 'wgt-private/',
-  cacheDirectory:'wgt-private-tmp/',
-  sharedDirectory: '/opt/usr/media/',
+  sharedDirectory: 'file:///opt/usr/media/'
 };
 
 function setExternalStorage(callback) {
+  var label = '';
+
+  var onError = function(error) {
+    console.error('Failed to get external storage: ' + error.message);
+    callback(pathsPrefix);
+  }
+
   var onSuccess = function(storages) {
     for (var i = 0; i < storages.length; ++i) {
       if (storages[i].type === 'EXTERNAL' && storages[i].state === 'MOUNTED') {
-        pathsPrefix.externalRootDirectory = storages[i].label + '/';
+        label = storages[i].label;
         break;
       }
     }
 
-    callback(pathsPrefix);
-  }
+    var onSuccessStorage = function(storage) {
+      pathsPrefix.externalRootDirectory = 'file://' + storage.fullPath + '/';
+      callback(pathsPrefix);
+    }
 
-  var onError = function(error) {
-    console.error('Failed to get external storage: ' + error.message);
-    callback(pathsPrefix);
+    try {
+      tizen.filesystem.resolve(label, onSuccessStorage, onError);
+    } catch(error) {
+      console.error('Failed to resolve external storage: ' + error.message);
+      callback(pathsPrefix);
+    }
   }
 
   try {
@@ -53,7 +62,11 @@ function setExternalStorage(callback) {
 function setApplicationStorageDirectory(callback) {
   try {
     var app = tizen.application.getCurrentApplication();
-    pathsPrefix.applicationStorageDirectory = '/opt/usr/apps/' + app.appInfo.packageId + '/';
+    var basePath = 'file:///opt/usr/apps/' + app.appInfo.packageId + '/';
+    pathsPrefix.applicationStorageDirectory = basePath;
+    pathsPrefix.applicationDirectory = basePath + 'res/wgt/';
+    pathsPrefix.dataDirectory = basePath + 'data/';
+    pathsPrefix.cacheDirectory = basePath + 'tmp/';
     setExternalStorage(callback);
   } catch(error) {
     console.error('Failed to get current application: ' + error.message);
index 1a3fa88..ef273b1 100644 (file)
@@ -46,7 +46,7 @@ var rootsUtils = (function() {
     return {
       name: getName(uri),
       fullPath: getFullPath(uri),
-      nativeURL: getNativeUrl(uri),
+      nativeURL: encodeURI(getNativeUrl(uri)),
       filesystemName: fsName
     };
   }
@@ -186,7 +186,7 @@ var rootsUtils = (function() {
     }
 
     if (url) {
-      url = getNativeUrl(url);
+      url = decodeURI(getNativeUrl(url));
     } else {
       console.error('Failed to decode internal URL: ' + input);
     }