cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [4/5] git commit: checks app resources if iso file does not exist, added mime types for html+js
Date Fri, 15 Feb 2013 00:41:50 GMT
checks app resources if iso file does not exist, added mime types for html+js


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/871efd9b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/871efd9b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/871efd9b

Branch: refs/heads/master
Commit: 871efd9b35f09fae1e3f290fc322404e22b5c9f9
Parents: 60256d1
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Thu Feb 14 16:39:09 2013 -0800
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Thu Feb 14 16:39:09 2013 -0800

----------------------------------------------------------------------
 templates/standalone/cordovalib/Commands/File.cs   |   44 +++++++++++----
 .../cordovalib/Commands/MimeTypeMapper.cs          |    6 +-
 2 files changed, 37 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/871efd9b/templates/standalone/cordovalib/Commands/File.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/File.cs b/templates/standalone/cordovalib/Commands/File.cs
index 71c7e1e..a4ad427 100644
--- a/templates/standalone/cordovalib/Commands/File.cs
+++ b/templates/standalone/cordovalib/Commands/File.cs
@@ -235,19 +235,41 @@ namespace WPCordovaClassLib.Cordova.Commands
             {
                 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                 {
-                    if ((string.IsNullOrEmpty(filePath)) || (!isoFile.FileExists(filePath)))
+                    if (string.IsNullOrEmpty(filePath))
                     {
                         throw new FileNotFoundException("File doesn't exist");
                     }
-                    //TODO get file size the other way if possible                
-                    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath,
FileMode.Open, FileAccess.Read, isoFile))
+                    else if (!isoFile.FileExists(filePath))
+                    {
+                        // attempt to get it from the resources
+                        if (filePath.IndexOf("www") == 0)
+                        {
+                            Uri fileUri = new Uri(filePath, UriKind.Relative);
+                            StreamResourceInfo streamInfo = Application.GetResourceStream(fileUri);
+                            if (streamInfo != null)
+                            {
+                                this.Size = streamInfo.Stream.Length;
+                                this.FileName = filePath.Substring(filePath.LastIndexOf("/")
+ 1);
+                                this.FullPath = filePath;
+                            }
+                        }
+                        else
+                        {
+                            throw new FileNotFoundException("File doesn't exist");
+                        }
+                    }
+                    else
                     {
-                        this.Size = stream.Length;
+                        //TODO get file size the other way if possible                
+                        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath,
FileMode.Open, FileAccess.Read, isoFile))
+                        {
+                            this.Size = stream.Length;
+                        }
+                        this.FullPath = filePath;
+                        this.FileName = System.IO.Path.GetFileName(filePath);
+                        this.LastModifiedDate = isoFile.GetLastWriteTime(filePath).DateTime.ToString();
                     }
-                    this.FullPath = filePath;
-                    this.FileName = System.IO.Path.GetFileName(filePath);
-                    this.Type = MimeTypeMapper.GetMimeType(filePath);
-                    this.LastModifiedDate = isoFile.GetLastWriteTime(filePath).DateTime.ToString();
+                    this.Type = MimeTypeMapper.GetMimeType(this.FileName);
                 }
             }
         }
@@ -620,7 +642,6 @@ namespace WPCordovaClassLib.Cordova.Commands
             string filePath = optStrings[0];
             string encStr = optStrings[1];
 
-
             try
             {
                 string text;
@@ -629,7 +650,8 @@ namespace WPCordovaClassLib.Cordova.Commands
                 {
                     if (!isoFile.FileExists(filePath))
                     {
-                        DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
NOT_FOUND_ERR));
+                        //DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
NOT_FOUND_ERR));
+                        readResourceAsText(options);
                         return;
                     }
                     Encoding encoding = Encoding.GetEncoding(encStr);
@@ -676,7 +698,7 @@ namespace WPCordovaClassLib.Cordova.Commands
                     pathToResource = pathToResource.Remove(0, 1);
                 }
                 
-                var resource = System.Windows.Application.GetResourceStream(new Uri(pathToResource,
UriKind.Relative));
+                var resource = Application.GetResourceStream(new Uri(pathToResource, UriKind.Relative));
                 
                 if (resource == null)
                 {

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/871efd9b/templates/standalone/cordovalib/Commands/MimeTypeMapper.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/MimeTypeMapper.cs b/templates/standalone/cordovalib/Commands/MimeTypeMapper.cs
index 01ba4cb..a2794f5 100644
--- a/templates/standalone/cordovalib/Commands/MimeTypeMapper.cs
+++ b/templates/standalone/cordovalib/Commands/MimeTypeMapper.cs
@@ -35,10 +35,12 @@ namespace WPCordovaClassLib.Cordova.Commands
                                                                              {          
                                                                     
                                                                                  {"avi",
"video/x-msvideo"},
                                                                                  {"bmp",
"image/bmp"},                                                                            
                                                                                   
-                                                                                 {"gif",
"image/gif"},                                                                            
                                                                                  
+                                                                                 {"gif",
"image/gif"},
+                                                                                 {"html","text/html"},
                                                                             
                                                                                  {"jpe",
"image/jpeg"},
                                                                                  {"jpeg",
"image/jpeg"},
-                                                                                 {"jpg",
"image/jpeg"},                                                                           
                                                                                 
+                                                                                 {"jpg",
"image/jpeg"},     
+                                                                                 {"js","text/javascript"},
                                                                        
                                                                                  {"mov",
"video/quicktime"},
                                                                                  {"mp2",
"audio/mpeg"},
                                                                                  {"mp3",
"audio/mpeg"},


Mime
View raw message