Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A56C8D90E for ; Fri, 15 Feb 2013 00:41:51 +0000 (UTC) Received: (qmail 84257 invoked by uid 500); 15 Feb 2013 00:41:51 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 84203 invoked by uid 500); 15 Feb 2013 00:41:51 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 83996 invoked by uid 99); 15 Feb 2013 00:41:51 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Feb 2013 00:41:51 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0C2E782B0AB; Fri, 15 Feb 2013 00:41:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: purplecabbage@apache.org To: commits@cordova.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/5] git commit: detect instances where item is a resource, and use a stream instead of iso-store, wip Message-Id: <20130215004151.0C2E782B0AB@tyr.zones.apache.org> Date: Fri, 15 Feb 2013 00:41:51 +0000 (UTC) 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 Authored: Fri Feb 1 00:33:14 2013 -0800 Committer: Jesse MacFadyen 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; + //} + /// /// Creates object and sets necessary properties /// /// - 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)))