From 5935a4e8acb39994b5cbddd94a0b8b2a82e4aa11 Mon Sep 17 00:00:00 2001
From: Gillardo <darren.gillard81@gmail.com>
Date: Tue, 5 May 2015 09:59:27 +0100
Subject: [PATCH] Added support for Windows

Added support for Windows.  Updated wp8 so that file can be on device,
rather than only in local storage folder
---
 plugin.xml                      | 20 ++++++++++++++------
 src/windows/fileOpener2Proxy.js | 26 ++++++++++++++++++++++++++
 src/wp8/FileOpener2.cs          |  9 +++------
 3 files changed, 43 insertions(+), 12 deletions(-)
 create mode 100644 src/windows/fileOpener2Proxy.js

diff --git a/plugin.xml b/plugin.xml
index a7008e7..3e7ad67 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -39,11 +39,19 @@
 
 	<!-- WP8 -->
 	<platform name="wp8">
-	<config-file target="config.xml" parent="/*">
-	  <feature name="FileOpener2">
-		<param name="wp-package" value="FileOpener2" />
-	  </feature>
-	</config-file>
-	<source-file src="src/wp8/FileOpener2.cs" />
+		<config-file target="config.xml" parent="/*">
+		  <feature name="FileOpener2">
+			<param name="wp-package" value="FileOpener2" />
+		  </feature>
+		</config-file>
+		<source-file src="src/wp8/FileOpener2.cs" />
 	</platform>
+	
+
+	 <!-- windows -->
+    <platform name="windows">
+        <js-module src="src/windows/fileOpener2Proxy.js" name="fileOpener2Proxy">
+            <merges target="" />
+        </js-module>
+    </platform>
 </plugin>
diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js
new file mode 100644
index 0000000..71692ca
--- /dev/null
+++ b/src/windows/fileOpener2Proxy.js
@@ -0,0 +1,26 @@
+
+	var cordova = require('cordova'),
+		fileOpener2 = require('./FileOpener2');
+
+	module.exports = {
+
+	    open: function (successCallback, errorCallback, args) {
+	        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(function (file) {
+	            var options = new Windows.System.LauncherOptions();
+	            options.displayApplicationPicker = true;
+
+	            Windows.System.Launcher.launchFileAsync(file, options).then(function (success) {
+	                if (success) {
+	                    successCallback();
+	                } else {
+	                    errorCallback();
+	                }
+	            });
+
+	        });
+		}
+		
+	};
+
+	require("cordova/exec/proxy").add("FileOpener2", module.exports);
+
diff --git a/src/wp8/FileOpener2.cs b/src/wp8/FileOpener2.cs
index 9c389e7..b19604d 100644
--- a/src/wp8/FileOpener2.cs
+++ b/src/wp8/FileOpener2.cs
@@ -17,16 +17,13 @@ namespace WPCordovaClassLib.Cordova.Commands
         public async void open(string options)
         {
             string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
-            var fileName = System.IO.Path.GetFileName(args[0]);
+
             string aliasCurrentCommandCallbackId = args[2];
 
             try
             {
-                // Access isolated storage.
-                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
-
-                // Access the file.
-                StorageFile file = await local.GetFileAsync(fileName);
+                // Get the file.
+                StorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(args[0]);
 
                 // Launch the bug query file.
                 await Windows.System.Launcher.LaunchFileAsync(file);