From e2ea30f9734b529a2164e507cf842fa2eb4dc6d3 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Wed, 12 Oct 2016 12:50:55 +0200 Subject: [PATCH 1/4] Update fileOpener2Proxy.js It didn't work on windows, mainly due to uri/path problems. I fixed it, + some changes like an error on callback. --- src/windows/fileOpener2Proxy.js | 59 ++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 57ca558..e74077e 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -4,18 +4,46 @@ var schemes = [ { protocol: 'ms-app', getFile: getFileFromApplicationUri }, - { protocol: 'file:///', getFile: getFileFromFileUri } + { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile ] - function getFileFromApplicationUri(uri) { - var applicationUri = new Windows.Foundation.Uri(uri); + function nthIndex(str, pat, n) { + var L = str.length, i = -1; + while (n-- && i++ < L) { + i = str.indexOf(pat, i); + if (i < 0) break; + } + return i; + } - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + function getFileFromApplicationUri(uri) { + /* bad path from a file entry due to the last '//' + example: ms-appdata:///local//path/to/file + */ + var index = nthIndex(uri, "//", 3); + var newUri = uri.substr(0, index) + uri.substr(index + 1); + + var applicationUri = new Windows.Foundation.Uri(newUri); + + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri);; } function getFileFromFileUri(uri) { - var path = Windows.Storage.ApplicationData.current.localFolder.path + - uri.substr(8); + /* uri example: + cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file + */ + var indexFrom = nthIndex(uri, "/", 3) + 1; + var indexTo = nthIndex(uri, "/", 4); + var whichFolder = uri.substring(indexFrom, indexTo); + var filePath = uri.substr(indexTo + 1); + var path = "\\" + filePath; + + if (whichFolder == "persistent") { + path = Windows.Storage.ApplicationData.current.localFolder.path + path; + } + else { //temporary, note: no roaming management + path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; + } return getFileFromNativePath(path); } @@ -39,23 +67,22 @@ module.exports = { open: function (successCallback, errorCallback, args) { + var path = args[0]; var getFile = getFileLoaderForScheme(path); - + getFile(path).then(function (file) { var options = new Windows.System.LauncherOptions(); - - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - if (success) { - successCallback(); - } else { - errorCallback(); - } + + Windows.System.Launcher.launchFileAsync(file, options).done(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); }); - }, function (errror) { - console.log("Error abriendo el archivo"); + }, function (error) { + console.log("Error while opening the file: "+error); }); } From 91064a039097f48fc6a9672a4cbf916e504a2849 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Wed, 12 Oct 2016 13:54:26 +0200 Subject: [PATCH 2/4] Update fileOpener2Proxy.js add another errorCallBack --- src/windows/fileOpener2Proxy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index e74077e..48f7332 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -83,6 +83,7 @@ }, function (error) { console.log("Error while opening the file: "+error); + errorCallback(error); }); } From bea7625d8fbff198df92d47d8e78cd6dadd14989 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Wed, 12 Oct 2016 17:05:00 +0200 Subject: [PATCH 3/4] Update fileOpener2Proxy.js double ; --- src/windows/fileOpener2Proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 48f7332..69d34ee 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -25,7 +25,7 @@ var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri);; + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); } function getFileFromFileUri(uri) { From d2ccb221e95cd3613540ad2b9f0ec37cacb9fc65 Mon Sep 17 00:00:00 2001 From: J3r0M3D3V Date: Thu, 13 Oct 2016 11:04:11 +0200 Subject: [PATCH 4/4] Update fileOpener2Proxy.js then > done --- src/windows/fileOpener2Proxy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 69d34ee..ce2dee6 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -75,7 +75,7 @@ getFile(path).then(function (file) { var options = new Windows.System.LauncherOptions(); - Windows.System.Launcher.launchFileAsync(file, options).done(function (success) { + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { successCallback(); }, function (error) { errorCallback(error);