You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2012/11/27 03:07:31 UTC
[30/30] git commit: implements CB-1813 WP8. Don't copy site content
to IsolatedStorage
implements CB-1813 WP8. Don't copy site content to IsolatedStorage
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/b211bca4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/b211bca4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/b211bca4
Branch: refs/heads/master
Commit: b211bca4b3c0f5f2c0979afb829ab1bf457a45a8
Parents: 468bfd0
Author: Ruslan Kokorev <ru...@bsquare.com>
Authored: Thu Nov 8 15:19:52 2012 +0400
Committer: Ruslan Kokorev <ru...@bsquare.com>
Committed: Thu Nov 8 15:19:52 2012 +0400
----------------------------------------------------------------------
templates/standalone/cordovalib/Commands/File.cs | 47 ++++++
.../standalone/cordovalib/CordovaView.xaml.cs | 116 ++++++++-------
2 files changed, 107 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/b211bca4/templates/standalone/cordovalib/Commands/File.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/File.cs b/templates/standalone/cordovalib/Commands/File.cs
index 2e650b0..ca3357c 100644
--- a/templates/standalone/cordovalib/Commands/File.cs
+++ b/templates/standalone/cordovalib/Commands/File.cs
@@ -627,6 +627,53 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
+ /// <summary>
+ /// Reads application resource as a text
+ /// </summary>
+ /// <param name="options">Path to a resource</param>
+ public void readResourceAsText(string options)
+ {
+ string pathToResource;
+ try
+ {
+ string[] optStrings = JSON.JsonHelper.Deserialize<string[]>(options);
+ pathToResource = optStrings[0];
+ }
+ catch (Exception)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ if (pathToResource.StartsWith("/"))
+ {
+ pathToResource = pathToResource.Remove(0, 1);
+ }
+
+ var resource = System.Windows.Application.GetResourceStream(new Uri(pathToResource, UriKind.Relative));
+
+ if (resource == null)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
+ return;
+ }
+
+ string text;
+ StreamReader streamReader = new StreamReader(resource.Stream);
+ text = streamReader.ReadToEnd();
+
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text));
+ }
+ catch (Exception ex)
+ {
+ if (!this.HandleException(ex))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_READABLE_ERR));
+ }
+ }
+ }
public void truncate(string options)
{
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/b211bca4/templates/standalone/cordovalib/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/CordovaView.xaml.cs b/templates/standalone/cordovalib/CordovaView.xaml.cs
index cb18c39..694adfd 100644
--- a/templates/standalone/cordovalib/CordovaView.xaml.cs
+++ b/templates/standalone/cordovalib/CordovaView.xaml.cs
@@ -63,7 +63,7 @@ namespace WPCordovaClassLib
/// </summary>
private bool PageDidChange = false;
- private static string AppRoot = "/app/";
+ private static string AppRoot = "";
/// <summary>
@@ -235,61 +235,65 @@ namespace WPCordovaClassLib
}
- StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative));
-
- if (streamInfo != null)
- {
- StreamReader sr = new StreamReader(streamInfo.Stream);
- //This will Read Keys Collection for the xml file
-
- XDocument document = XDocument.Parse(sr.ReadToEnd());
-
- var files = from results in document.Descendants("FilePath")
- select new
- {
- path = (string)results.Attribute("Value")
- };
- StreamResourceInfo fileResourceStreamInfo;
-
- using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
- {
-
- foreach (var file in files)
- {
- fileResourceStreamInfo = Application.GetResourceStream(new Uri(file.path, UriKind.Relative));
-
- if (fileResourceStreamInfo != null)
- {
- using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
- {
- byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
-
- string strBaseDir = AppRoot + file.path.Substring(0, file.path.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
-
- if (!appStorage.DirectoryExists(strBaseDir))
- {
- Debug.WriteLine("INFO: Creating Directory :: " + strBaseDir);
- appStorage.CreateDirectory(strBaseDir);
- }
-
- // This will truncate/overwrite an existing file, or
- using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + file.path, FileMode.Create))
- {
- Debug.WriteLine("INFO: Writing data for " + AppRoot + file.path + " and length = " + data.Length);
- using (var writer = new BinaryWriter(outFile))
- {
- writer.Write(data);
- }
- }
- }
- }
- else
- {
- Debug.WriteLine("ERROR: Failed to write file :: " + file.path + " did you forget to add it to the project?");
- }
- }
- }
- }
+ /*
+ * 11/08/12 Ruslan Kokorev
+ * Copying files to isolated storage is no more required in WP8. WebBrowser control now works with files located in XAP.
+ */
+ //StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative));
+
+ //if (streamInfo != null)
+ //{
+ // StreamReader sr = new StreamReader(streamInfo.Stream);
+ // //This will Read Keys Collection for the xml file
+
+ // XDocument document = XDocument.Parse(sr.ReadToEnd());
+
+ // var files = from results in document.Descendants("FilePath")
+ // select new
+ // {
+ // path = (string)results.Attribute("Value")
+ // };
+ // StreamResourceInfo fileResourceStreamInfo;
+
+ // using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
+ // {
+
+ // foreach (var file in files)
+ // {
+ // fileResourceStreamInfo = Application.GetResourceStream(new Uri(file.path, UriKind.Relative));
+
+ // if (fileResourceStreamInfo != null)
+ // {
+ // using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
+ // {
+ // byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
+
+ // string strBaseDir = AppRoot + file.path.Substring(0, file.path.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
+
+ // if (!appStorage.DirectoryExists(strBaseDir))
+ // {
+ // Debug.WriteLine("INFO: Creating Directory :: " + strBaseDir);
+ // appStorage.CreateDirectory(strBaseDir);
+ // }
+
+ // // This will truncate/overwrite an existing file, or
+ // using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + file.path, FileMode.Create))
+ // {
+ // Debug.WriteLine("INFO: Writing data for " + AppRoot + file.path + " and length = " + data.Length);
+ // using (var writer = new BinaryWriter(outFile))
+ // {
+ // writer.Write(data);
+ // }
+ // }
+ // }
+ // }
+ // else
+ // {
+ // Debug.WriteLine("ERROR: Failed to write file :: " + file.path + " did you forget to add it to the project?");
+ // }
+ // }
+ // }
+ //}
CordovaBrowser.Navigate(StartPageUri);
IsBrowserInitialized = true;