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 2014/08/29 03:05:08 UTC

[1/4] git commit: [CB-7419][WP8] Added support to get metada from dir

Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 73a5173d1 -> f432e646a


[CB-7419][WP8] Added support to get metada from dir

The error CODE 1, in the callback it was about the a failed attempt to
get the size of a directory using IsolatedStorageFileStream, get that
information, throwing a SystemException 'DirectoryNotFoundException'.
Instead IsolatedStorageFileStream to get that information from a
directory, now uses Application.GetResourceStream, to that information
from the provided path, only if directory. If other file it would use
'IsolatedStorageFileStream'


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/1dd70b3f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/1dd70b3f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/1dd70b3f

Branch: refs/heads/master
Commit: 1dd70b3fe92f2371dc2f8ab3666fc25c1ce488c8
Parents: 99ade61
Author: Martin Gonzalez <ma...@gmail.com>
Authored: Wed Aug 27 17:54:27 2014 -0500
Committer: Martin Gonzalez <ma...@gmail.com>
Committed: Wed Aug 27 17:54:27 2014 -0500

----------------------------------------------------------------------
 src/wp/File.cs | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/1dd70b3f/src/wp/File.cs
----------------------------------------------------------------------
diff --git a/src/wp/File.cs b/src/wp/File.cs
index 0f2fe50..bce78fd 100644
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -235,13 +235,16 @@ namespace WPCordovaClassLib.Cordova.Commands
             {
                 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                 {
+                    bool IsFile = isoFile.FileExists(filePath);
+                    bool IsDirectory = isoFile.DirectoryExists(filePath);
+
                     if (string.IsNullOrEmpty(filePath))
                     {
                         throw new FileNotFoundException("File doesn't exist");
                     }
-                    else if (!isoFile.FileExists(filePath))
+                    else if (!IsFile && !IsDirectory)
                     {
-                        // attempt to get it from the resources
+                    // attempt to get it from the resources
                         if (filePath.IndexOf("www") == 0)
                         {
                             Uri fileUri = new Uri(filePath, UriKind.Relative);
@@ -260,11 +263,25 @@ namespace WPCordovaClassLib.Cordova.Commands
                     }
                     else
                     {
-                        //TODO get file size the other way if possible                
-                        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.Open, FileAccess.Read, isoFile))
+                        //TODO get file size the other way if possible
+                        //Use StreamResourceInfo to get directory Size.
+                        if (IsDirectory)
                         {
-                            this.Size = stream.Length;
+                            Uri fileUri = new Uri(filePath, UriKind.Relative);
+                            StreamResourceInfo streamInfo = Application.GetResourceStream(fileUri);
+                            if (streamInfo != null)
+                            {
+                                this.Size = streamInfo.Stream.Length;
+                            }
                         }
+                        else
+                        {
+                            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();


[2/4] git commit: Merge branch 'CB-7419' of https://github.com/martincgg/cordova-plugin-file

Posted by pu...@apache.org.
Merge branch 'CB-7419' of https://github.com/martincgg/cordova-plugin-file


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/9618aa31
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/9618aa31
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/9618aa31

Branch: refs/heads/master
Commit: 9618aa31be4b4b90a5b5d034a1ebeb5d7b70c611
Parents: da50f49 1dd70b3
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Aug 27 17:02:26 2014 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Aug 27 17:02:26 2014 -0700

----------------------------------------------------------------------
 src/wp/File.cs | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[4/4] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-file

Posted by pu...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-plugin-file


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/f432e646
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/f432e646
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/f432e646

Branch: refs/heads/master
Commit: f432e646aa77a6ffa8f3e91b5f6eb0d7e6d82006
Parents: b9a5016 73a5173
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Aug 28 18:05:33 2014 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Aug 28 18:05:33 2014 -0700

----------------------------------------------------------------------
 tests/tests.js                   | 5 +++--
 www/resolveLocalFileSystemURI.js | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------



[3/4] git commit: Refactored much of the logic in FileMetadata constructor. Directory.size will return 0

Posted by pu...@apache.org.
Refactored much of the logic in FileMetadata constructor.  Directory.size will return 0


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/b9a50169
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/b9a50169
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/b9a50169

Branch: refs/heads/master
Commit: b9a5016960272b19f88f4cf9234fb675f7e860fd
Parents: 9618aa3
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Aug 28 18:04:48 2014 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Aug 28 18:04:48 2014 -0700

----------------------------------------------------------------------
 src/wp/File.cs | 103 +++++++++++++++++++++++++---------------------------
 1 file changed, 49 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b9a50169/src/wp/File.cs
----------------------------------------------------------------------
diff --git a/src/wp/File.cs b/src/wp/File.cs
index bce78fd..c0f6795 100644
--- a/src/wp/File.cs
+++ b/src/wp/File.cs
@@ -1,15 +1,15 @@
 /*  
-	Licensed under the Apache License, Version 2.0 (the "License");
-	you may not use this file except in compliance with the License.
-	You may obtain a copy of the License at
-	
-	http://www.apache.org/licenses/LICENSE-2.0
-	
-	Unless required by applicable law or agreed to in writing, software
-	distributed under the License is distributed on an "AS IS" BASIS,
-	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-	See the License for the specific language governing permissions and
-	limitations under the License.
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
 */
 
 using System;
@@ -233,59 +233,50 @@ namespace WPCordovaClassLib.Cordova.Commands
 
             public FileMetadata(string filePath)
             {
+                if (string.IsNullOrEmpty(filePath))
+                {
+                    throw new FileNotFoundException("File doesn't exist");
+                }
+
+                this.FullPath = filePath;
+                this.Size = 0;
+                this.FileName = string.Empty;
+
                 using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                 {
                     bool IsFile = isoFile.FileExists(filePath);
                     bool IsDirectory = isoFile.DirectoryExists(filePath);
 
-                    if (string.IsNullOrEmpty(filePath))
-                    {
-                        throw new FileNotFoundException("File doesn't exist");
-                    }
-                    else if (!IsFile && !IsDirectory)
-                    {
-                    // attempt to get it from the resources
-                        if (filePath.IndexOf("www") == 0)
+                        if (!IsDirectory)
                         {
-                            Uri fileUri = new Uri(filePath, UriKind.Relative);
-                            StreamResourceInfo streamInfo = Application.GetResourceStream(fileUri);
-                            if (streamInfo != null)
+                            if (!IsFile)      // special case, if isoFile cannot find it, it might still be part of the app-package
                             {
-                                this.Size = streamInfo.Stream.Length;
-                                this.FileName = filePath.Substring(filePath.LastIndexOf("/") + 1);
-                                this.FullPath = filePath;
-                            }
-                        }
-                        else
-                        {
-                            throw new FileNotFoundException("File doesn't exist");
-                        }
-                    }
-                    else
-                    {
-                        //TODO get file size the other way if possible
-                        //Use StreamResourceInfo to get directory Size.
-                        if (IsDirectory)
-                        {
-                            Uri fileUri = new Uri(filePath, UriKind.Relative);
-                            StreamResourceInfo streamInfo = Application.GetResourceStream(fileUri);
-                            if (streamInfo != null)
-                            {
-                                this.Size = streamInfo.Stream.Length;
+                                // attempt to get it from the resources
+
+                                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);
+                                }
+                                else
+                                {
+                                    throw new FileNotFoundException("File doesn't exist");
+                                }
                             }
-                        }
-                        else
-                        {
-                            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.Open, FileAccess.Read, isoFile))
+                            else
                             {
-                                this.Size = stream.Length;
+                                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.Open, FileAccess.Read, isoFile))
+                                {
+                                    this.Size = stream.Length;
+                                }
+
+                                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.LastModifiedDate = isoFile.GetLastWriteTime(filePath).DateTime.ToString();
-                    }
                     this.Type = MimeTypeMapper.GetMimeType(this.FileName);
                 }
             }
@@ -917,7 +908,7 @@ namespace WPCordovaClassLib.Cordova.Commands
             string filePath = optStings[0];
             string callbackId = optStings[1];
 
-            if (filePath != null)
+            if (!string.IsNullOrEmpty(filePath))
             {
                 try
                 {
@@ -936,6 +927,10 @@ namespace WPCordovaClassLib.Cordova.Commands
                     }
                 }
             }
+            else
+            {
+                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR), callbackId);
+            }
         }
 
         /// <summary>
@@ -1609,7 +1604,7 @@ namespace WPCordovaClassLib.Cordova.Commands
 
                         // 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++)