From 6ad1e1c540b770b6e0f90b20e856d274ab07ffdc Mon Sep 17 00:00:00 2001 From: sgrebnov Date: Thu, 10 Apr 2014 23:20:34 +0400 Subject: [PATCH] WP8 support --- plugin.xml | 9 ++++++++ src/wp/FileOpener.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/wp/FileOpener.cs diff --git a/plugin.xml b/plugin.xml index a5e6b11..78eedba 100644 --- a/plugin.xml +++ b/plugin.xml @@ -24,4 +24,13 @@ + + + + + + + + + diff --git a/src/wp/FileOpener.cs b/src/wp/FileOpener.cs new file mode 100644 index 0000000..653b7f9 --- /dev/null +++ b/src/wp/FileOpener.cs @@ -0,0 +1,50 @@ +// Copyright (c) Sergey Grebnov. Licensed under the MIT license. + +using System; +using System.Collections.Generic; +using System.IO.IsolatedStorage; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Storage; +using WPCordovaClassLib.Cordova.Commands; + +namespace WPCordovaClassLib.Cordova.Commands +{ + public class FileOpener : BaseCommand + { + async public void openFile(string options) + { + var optStings = JSON.JsonHelper.Deserialize(options); + + string filePath = optStings[0].Replace('/', '\\').Substring(2); + + try + { + + StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; + StorageFile file = await local.GetFileAsync(filePath); + + if (file == null) + { + this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "File not found: " + filePath)); + return; + } + + var success = await Windows.System.Launcher.LaunchFileAsync(file); + + if (success) + { + this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK)); + } + else + { + this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unable to start the app associated with the following file: " + filePath)); + } + } + catch (Exception ex) { + this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message)); + } + } + } +} \ No newline at end of file