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 2013/02/15 01:41:51 UTC
[1/5] git commit: detect instances where item is a resource,
and use a stream instead of iso-store, wip
detect instances where item is a resource, and use a stream instead of iso-store, wip
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/54e66064
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/54e66064
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/54e66064
Branch: refs/heads/master
Commit: 54e66064efba7b9a65901aafc48977dcbb8aac06
Parents: d9bd6ab
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Feb 1 00:33:14 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Feb 1 00:33:14 2013 -0800
----------------------------------------------------------------------
templates/standalone/cordovalib/Commands/File.cs | 72 ++++++++++++++---
1 files changed, 61 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/54e66064/templates/standalone/cordovalib/Commands/File.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/File.cs b/templates/standalone/cordovalib/Commands/File.cs
index 0a0efa1..71c7e1e 100644
--- a/templates/standalone/cordovalib/Commands/File.cs
+++ b/templates/standalone/cordovalib/Commands/File.cs
@@ -20,6 +20,8 @@ using System.Runtime.Serialization;
using System.Security;
using System.Text;
using System.Diagnostics;
+using System.Windows.Resources;
+using System.Windows;
namespace WPCordovaClassLib.Cordova.Commands
{
@@ -294,12 +296,14 @@ namespace WPCordovaClassLib.Cordova.Commands
[DataMember(Name = "fullPath")]
public string FullPath { get; set; }
- public static FileEntry GetEntry(string filePath)
+ public bool IsResource { get; set; }
+
+ public static FileEntry GetEntry(string filePath, bool bIsRes=false)
{
FileEntry entry = null;
try
{
- entry = new FileEntry(filePath);
+ entry = new FileEntry(filePath, bIsRes);
}
catch (Exception ex)
@@ -309,11 +313,23 @@ namespace WPCordovaClassLib.Cordova.Commands
return entry;
}
+ //public static FileEntry GetEntry(Uri uri)
+ //{
+ // FileEntry entry = null;
+ // //try
+ // //{
+ // // this.Name = Path.GetFileName(uri.OriginalString);
+ // // entry = new FileEntry(uri.OriginalString);
+ // // entry
+ // //}
+ // return entry;
+ //}
+
/// <summary>
/// Creates object and sets necessary properties
/// </summary>
/// <param name="filePath"></param>
- public FileEntry(string filePath)
+ public FileEntry(string filePath, bool bIsRes = false)
{
if (string.IsNullOrEmpty(filePath))
{
@@ -327,8 +343,9 @@ namespace WPCordovaClassLib.Cordova.Commands
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
- this.IsFile = isoFile.FileExists(filePath);
- this.IsDirectory = isoFile.DirectoryExists(filePath);
+ IsResource = bIsRes;
+ IsFile = isoFile.FileExists(filePath);
+ IsDirectory = isoFile.DirectoryExists(filePath);
if (IsFile)
{
this.Name = Path.GetFileName(filePath);
@@ -343,7 +360,14 @@ namespace WPCordovaClassLib.Cordova.Commands
}
else
{
- throw new FileNotFoundException();
+ if (IsResource)
+ {
+ this.Name = Path.GetFileName(filePath);
+ }
+ else
+ {
+ throw new FileNotFoundException();
+ }
}
try
@@ -1442,7 +1466,7 @@ namespace WPCordovaClassLib.Cordova.Commands
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ENCODING_ERR));
return;
- }
+ }
using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
@@ -1458,10 +1482,9 @@ namespace WPCordovaClassLib.Cordova.Commands
return;
}
-
// need to make sure the parent exists
// it is an error to create a directory whose immediate parent does not yet exist
- // see issue: https://issues.apache.org/jira/browse/CB-339
+ // see issue: https://issues.apache.org/jira/browse/CB-339
string[] pathParts = path.Split('/');
string builtPath = pathParts[0];
for (int n = 1; n < pathParts.Length - 1; n++)
@@ -1489,11 +1512,38 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
}
- else
+ else // (not create)
{
if ((!isFile) && (!isDirectory))
{
- DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
+ if (path.IndexOf("//www") == 0)
+ {
+ Uri fileUri = new Uri(path.Remove(0,2), UriKind.Relative);
+ StreamResourceInfo streamInfo = Application.GetResourceStream(fileUri);
+ if (streamInfo != null)
+ {
+ FileEntry _entry = FileEntry.GetEntry(fileUri.OriginalString,true);
+
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, _entry));
+
+ //using (BinaryReader br = new BinaryReader(streamInfo.Stream))
+ //{
+ // byte[] data = br.ReadBytes((int)streamInfo.Stream.Length);
+
+ //}
+
+ }
+ else
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
+ }
+
+
+ }
+ else
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
+ }
return;
}
if (((getDirectory) && (!isDirectory)) || ((!getDirectory) && (!isFile)))