From d84b20e6209a7134dda39276dc1fa09a4229e604 Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 11 Dec 2018 08:59:29 -0700 Subject: [PATCH 1/3] Update fileOpener2Proxy.js --- src/windows/fileOpener2Proxy.js | 150 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index ce2dee6..b9c82d9 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -1,93 +1,95 @@ - var cordova = require('cordova'), - fileOpener2 = require('./FileOpener2'); +var cordova = require('cordova'), + fileOpener2 = require('./FileOpener2'); - var schemes = [ - { protocol: 'ms-app', getFile: getFileFromApplicationUri }, - { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile - ] +var schemes = [ + { protocol: 'ms-app', getFile: getFileFromApplicationUri }, + { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile +] - 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; - } +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; +} - 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); +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); + var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); - } + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); +} - function getFileFromFileUri(uri) { - /* 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; +function getFileFromFileUri(uri) { + /* 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; - } + 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); - } + return getFileFromNativePath(path); +} - function getFileFromNativePath(path) { - var nativePath = path.split("/").join("\\"); +function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); - return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); - } + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); +} - function getFileLoaderForScheme(path) { - var fileLoader = getFileFromNativePath; +function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; - schemes.some(function (scheme) { - return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; - }); + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); - return fileLoader; - } + return fileLoader; +} - module.exports = { +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) { - successCallback(); - }, function (error) { - errorCallback(error); - }); + open: function (successCallback, errorCallback, args) { + + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + try{ + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); + }); + }, function (error) { + console.log("Error while opening the file: "+error); + errorCallback(error); + }); + }catch(error){ + errorCallback(error); + } + } - }, function (error) { - console.log("Error while opening the file: "+error); - errorCallback(error); - }); - } - - }; +}; - require("cordova/exec/proxy").add("FileOpener2", module.exports); +require("cordova/exec/proxy").add("FileOpener2", module.exports); From 0c6cbedb172f8351570a3d57b4070db9e3268ecb Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 11 Dec 2018 09:02:14 -0700 Subject: [PATCH 2/3] Update fileOpener2Proxy.js --- src/windows/fileOpener2Proxy.js | 150 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 74 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index b9c82d9..d5d2e2d 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -1,95 +1,97 @@ -var cordova = require('cordova'), - fileOpener2 = require('./FileOpener2'); + var cordova = require('cordova'), + fileOpener2 = require('./FileOpener2'); -var schemes = [ - { protocol: 'ms-app', getFile: getFileFromApplicationUri }, - { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile -] + var schemes = [ + { protocol: 'ms-app', getFile: getFileFromApplicationUri }, + { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile + ] -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; -} - -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) { - /* 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; + 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 getFileFromNativePath(path); -} + 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); -function getFileFromNativePath(path) { - var nativePath = path.split("/").join("\\"); + var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); -} + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + } -function getFileLoaderForScheme(path) { - var fileLoader = getFileFromNativePath; + function getFileFromFileUri(uri) { + /* 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; - schemes.some(function (scheme) { - return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; - }); + 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 fileLoader; -} + return getFileFromNativePath(path); + } -module.exports = { + function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); - open: function (successCallback, errorCallback, args) { - - var path = args[0]; - - var getFile = getFileLoaderForScheme(path); - try{ - getFile(path).then(function (file) { - var options = new Windows.System.LauncherOptions(); + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); + } + + function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; + + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); + + return fileLoader; + } + + module.exports = { + + open: function (successCallback, errorCallback, args) { - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - successCallback(); - }, function (error) { + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + + try{ + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); + }); + }catch(error){ errorCallback(error); - }); + } + }, function (error) { console.log("Error while opening the file: "+error); errorCallback(error); }); - }catch(error){ - errorCallback(error); } - } + + }; -}; - -require("cordova/exec/proxy").add("FileOpener2", module.exports); + require("cordova/exec/proxy").add("FileOpener2", module.exports); From 85fa81fba36f3c0e7a0df332346780b5ec0096b5 Mon Sep 17 00:00:00 2001 From: Nathaniel van Diepen Date: Tue, 11 Dec 2018 09:03:22 -0700 Subject: [PATCH 3/3] Update fileOpener2Proxy.js --- src/windows/fileOpener2Proxy.js | 136 ++++++++++++++++---------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index d5d2e2d..8155002 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -1,97 +1,97 @@ - var cordova = require('cordova'), - fileOpener2 = require('./FileOpener2'); + var cordova = require('cordova'), + fileOpener2 = require('./FileOpener2'); - var schemes = [ + var schemes = [ { protocol: 'ms-app', getFile: getFileFromApplicationUri }, { protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile - ] + ] - 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; - } + 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; + } - function getFileFromApplicationUri(uri) { - /* bad path from a file entry due to the last '//' + 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 index = nthIndex(uri, "//", 3); + var newUri = uri.substr(0, index) + uri.substr(index + 1); - var applicationUri = new Windows.Foundation.Uri(newUri); + var applicationUri = new Windows.Foundation.Uri(newUri); - return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); - } + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + } - function getFileFromFileUri(uri) { - /* uri example: + function getFileFromFileUri(uri) { + /* 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; + 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; - } + 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); - } + return getFileFromNativePath(path); + } - function getFileFromNativePath(path) { - var nativePath = path.split("/").join("\\"); + function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); - return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); - } + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); + } - function getFileLoaderForScheme(path) { - var fileLoader = getFileFromNativePath; + function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; - schemes.some(function (scheme) { - return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; - }); + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); - return fileLoader; - } + return fileLoader; + } - module.exports = { + 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(); - + open: function (successCallback, errorCallback, args) { + + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + try{ - Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { - successCallback(); - }, function (error) { - errorCallback(error); - }); + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { + successCallback(); + }, function (error) { + errorCallback(error); + }); }catch(error){ errorCallback(error); } - }, function (error) { - console.log("Error while opening the file: "+error); - errorCallback(error); - }); - } - - }; + }, function (error) { + console.log("Error while opening the file: "+error); + errorCallback(error); + }); + } + + }; - require("cordova/exec/proxy").add("FileOpener2", module.exports); + require("cordova/exec/proxy").add("FileOpener2", module.exports);