fix bugs in file.js & MediaFile

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/8b3291ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/8b3291ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/8b3291ec

Branch: refs/heads/master
Commit: 8b3291ec4239e22b7fde69197f51884c06a195bc
Parents: dabfb65
Author: mingfeng <mingfengwan...@gmail.com>
Authored: Wed Sep 26 16:01:56 2012 +0800
Committer: mingfeng <mingfengwan...@gmail.com>
Committed: Wed Sep 26 16:01:56 2012 +0800

----------------------------------------------------------------------
 lib/windows8/exec.js                         |    2 +-
 lib/windows8/platform.js                     |    7 +-
 lib/windows8/plugin/windows8/CaptureProxy.js |   37 ++
 lib/windows8/plugin/windows8/MediaFile.js    |   42 --
 lib/windows8/plugin/windows8/file.js         |  532 +++++++++++----------
 5 files changed, 310 insertions(+), 310 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8b3291ec/lib/windows8/exec.js
----------------------------------------------------------------------
diff --git a/lib/windows8/exec.js b/lib/windows8/exec.js
index c53e74a..6a53247 100644
--- a/lib/windows8/exec.js
+++ b/lib/windows8/exec.js
@@ -31,7 +31,7 @@ var CommandProxy  = {
     "Capture":require('cordova/plugin/windows8/CaptureProxy'),
     "Compass":require('cordova/plugin/windows8/CompassProxy'),
     "Device":require('cordova/plugin/windows8/DeviceProxy'),
-    //"File":require('cordova/plugin/windows8/FileProxy'),
+    "File":require('cordova/plugin/windows8/file'),
     "FileTransfer":require('cordova/plugin/windows8/FileTransferProxy'),
     "Media":require('cordova/plugin/windows8/MediaProxy'),
     "NetworkStatus":require('cordova/plugin/windows8/NetworkStatusProxy'),

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8b3291ec/lib/windows8/platform.js
----------------------------------------------------------------------
diff --git a/lib/windows8/platform.js b/lib/windows8/platform.js
index 4b11026..4e91599 100644
--- a/lib/windows8/platform.js
+++ b/lib/windows8/platform.js
@@ -25,12 +25,7 @@ module.exports = {
         }
     },
     merges: {
-       File: {
-           path: "cordova/plugin/windows8/file"
-       },
-        MediaFile: {
-            path: "cordova/plugin/windows8/MediaFile"
-        },
+       
         navigator: {
             children: {
                 geolocation: {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8b3291ec/lib/windows8/plugin/windows8/CaptureProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/CaptureProxy.js 
b/lib/windows8/plugin/windows8/CaptureProxy.js
index 82e3706..33cfdd4 100644
--- a/lib/windows8/plugin/windows8/CaptureProxy.js
+++ b/lib/windows8/plugin/windows8/CaptureProxy.js
@@ -98,5 +98,42 @@ module.exports = {
             });
         }, function () { errorCallback(new 
CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES)); });
 
+    },
+
+    getFormatData: function (successCallback, errorCallback, args) {
+        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
+            function (storageFile) {
+                var mediaTypeFlag = 
String(args[1]).split("/")[0].toLowerCase();
+                if (mediaTypeFlag === "audio") {
+                    storageFile.properties.getMusicPropertiesAsync().then(
+                        function (audioProperties) {
+                            successCallback(new MediaFileData(null, 
audioProperties.bitrate, 0, 0, audioProperties.duration / 1000));
+                        }, function () {
+                            errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+                        }
+                    );
+                } else if (mediaTypeFlag === "video") {
+                    storageFile.properties.getVideoPropertiesAsync().then(
+                        function (videoProperties) {
+                            successCallback(new MediaFileData(null, 
videoProperties.bitrate, videoProperties.height, videoProperties.width, 
videoProperties.duration / 1000));
+                        }, function () {
+                            errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+                        }
+                    );
+                } else if (mediaTypeFlag === "image") {
+                    storageFile.properties.getImagePropertiesAsync().then(
+                        function (imageProperties) {
+                            successCallback(new MediaFileData(null, 0, 
imageProperties.height, imageProperties.width, 0));
+                        }, function () {
+                            errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+                        }
+                    );
+                } else {
+                    errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+                }
+            }, function () {
+                errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
+            }
+        );
     }
 };

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8b3291ec/lib/windows8/plugin/windows8/MediaFile.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/MediaFile.js 
b/lib/windows8/plugin/windows8/MediaFile.js
deleted file mode 100644
index 4096275..0000000
--- a/lib/windows8/plugin/windows8/MediaFile.js
+++ /dev/null
@@ -1,42 +0,0 @@
-var MediaFileData = require('cordova/plugin/MediaFileData');
-var CaptureError = require('cordova/plugin/CaptureError');
-
-module.exports = { // merges with common
-
-    getFormatData: function (successCallback, errorCallback, args) {
-        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
-            function (storageFile) {
-                var mediaTypeFlag = 
String(args[1]).split("/")[0].toLowerCase();
-                if (mediaTypeFlag === "audio") {
-                    storageFile.properties.getMusicPropertiesAsync().then(
-                        function (audioProperties) {
-                            successCallback(new MediaFileData(null, 
audioProperties.bitrate, 0, 0, audioProperties.duration / 1000));
-                        }, function () {
-                            errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
-                        }
-                    );
-                } else if (mediaTypeFlag === "video") {
-                    storageFile.properties.getVideoPropertiesAsync().then(
-                        function (videoProperties) {
-                            successCallback(new MediaFileData(null, 
videoProperties.bitrate, videoProperties.height, videoProperties.width, 
videoProperties.duration / 1000));
-                        }, function () {
-                            errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
-                        }
-                    );
-                } else if (mediaTypeFlag === "image") {
-                    storageFile.properties.getImagePropertiesAsync().then(
-                        function (imageProperties) {
-                            successCallback(new MediaFileData(null, 0, 
imageProperties.height, imageProperties.width, 0));
-                        }, function () {
-                            errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
-                        }
-                    );
-                } else {
-                    errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
-                }
-            }, function () {
-                errorCallback(new 
CaptureError(CaptureError.CAPTURE_INVALID_ARGUMENT));
-            }
-        );
-    }
-};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/8b3291ec/lib/windows8/plugin/windows8/file.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/file.js 
b/lib/windows8/plugin/windows8/file.js
index 17d41d7..c69ca6f 100644
--- a/lib/windows8/plugin/windows8/file.js
+++ b/lib/windows8/plugin/windows8/file.js
@@ -4,8 +4,6 @@ var cordova = require('cordova');
 module.exports = { //Merges with common
 
     getFileMetaData:function(win,fail,args) {
-
-
         Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).done(
             function (storageFile) {
                 storageFile.getBasicPropertiesAsync().then(
@@ -22,44 +20,48 @@ module.exports = { //Merges with common
     },
 
     getMetadata:function(success,fail,args) {
-        // this.fullPath
-        // this.isDirectory
-        // this.isFile
-        if (this.isFile) {
-            Windows.Storage.StorageFile.getFilFromPathAsync(args[0]).done(
-                function (storageFile) {
-                    storageFile.getBasicPropertiesAsync().then(
-                        function (basicProperties) {
-                            success(basicProperties.dateModified);
-                        },
-                        function () {
-                            fail(FileError.NOT_READABLE_ERR);
-                        }
-                    );
-                },
-                function () {
-                    fail(FileError.NOT_READABLE_ERR);
-                }
-            );
-        }
-
-        if (this.isDirectory) {
-            
Windows.Storage.StorageFolder.getFolderFromPathAsync(this.fullPath).done(
-                function (storageFolder) {
-                    storageFolder.getBasicPropertiesAsync().then(
-                        function (basicProperties) {
-                            success(basicProperties.dateModified);
-                        },
-                        function () {
-                            fail(FileError.NOT_FOUND_ERR);
-                        }
-                    );
-                },
-                function () {
-                    fail(FileError.NOT_READABLE_ERR);
-                }
-            );
-        }
+        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
+            function (sFile) {
+                Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).done(
+                    function (storageFile) {
+                        storageFile.getBasicPropertiesAsync().then(
+                            function (basicProperties) {
+                                success(basicProperties.dateModified);
+                            },
+                            function () {
+                                fail(FileError.NOT_READABLE_ERR);
+                            }
+                        );
+                    },
+                    function () {
+                        fail(FileError.NOT_READABLE_ERR);
+                    }
+                );
+            },
+            function () {
+                
Windows.Storage.StorageFolder.getFolderFromPathAsync(args[0]).then(
+                    function (sFolder) {
+                        
Windows.Storage.StorageFolder.getFolderFromPathAsync(args[0]).done(
+                            function (storageFolder) {
+                                storageFolder.getBasicPropertiesAsync().then(
+                                    function (basicProperties) {
+                                        success(basicProperties.dateModified);
+                                    },
+                                    function () {
+                                        fail(FileError.NOT_FOUND_ERR);
+                                    }
+                                );
+                            },
+                            function () {
+                                fail(FileError.NOT_READABLE_ERR);
+                            }
+                        );
+                    }, function () {
+                        fail(FileError.NOT_FOUND_ERR);
+                    }
+                )
+            }
+        );
     },
 
     getParent:function(win,fail,args) { // ["fullPath"]
@@ -192,65 +194,71 @@ module.exports = { //Merges with common
 
     remove:function(win,fail,args) {
         var fullPath = args[0];
-        // this.isDirectory
-        // this.isFile
+     
 
-        if (this.isFile) {
-            
Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).done(function 
(storageFile) {
-                storageFile.deleteAsync().done(win, function () {
-                    fail(FileError.INVALID_MODIFICATION_ERR);
+        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
+            function (sFile) {
+                
Windows.Storage.StorageFile.getFileFromPathAsync(fullPath).done(function 
(storageFile) {
+                    storageFile.deleteAsync().done(win, function () {
+                        fail(FileError.INVALID_MODIFICATION_ERR);
 
+                    });
                 });
-            });
-        }
-        if (this.isDirectory) {
-
-            var removeEntry = function () {
-                var storageFolder = null;
+            },
+            function () {
+                
Windows.Storage.StorageFolder.getFolderFromPathAsync(args[0]).then(
+                    function (sFolder) {
+                        var removeEntry = function () {
+                            var storageFolder = null;
+
+                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(function 
(storageFolder) {
+                                //FileSystem root can't be removed!
+                                var storageFolderPer = 
Windows.Storage.ApplicationData.current.localFolder;
+                                var storageFolderTem = 
Windows.Storage.ApplicationData.current.temporaryFolder;
+                                if (fullPath == storageFolderPer.path || 
fullPath == storageFolderTem.path) {
+                                    
fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
+                                    return;
+                                }
+                                
storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
 
-                
Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).then(function 
(storageFolder) {
-                    //FileSystem root can't be removed!
-                    var storageFolderPer = 
Windows.Storage.ApplicationData.current.localFolder;
-                    var storageFolderTem = 
Windows.Storage.ApplicationData.current.temporaryFolder;
-                    if (fullPath == storageFolderPer.path || fullPath == 
storageFolderTem.path) {
-                        fail(FileError.NO_MODIFICATION_ALLOWED_ERR);
-                        return;
-                    }
-                    
storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
+                                    if (fileList.length === 0) {
+                                        
storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
 
-                        if (fileList.length === 0) {
-                            
storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
+                                            if (folderList.length === 0) {
+                                                
storageFolder.deleteAsync().done(win, function () {
+                                                    
fail(FileError.INVALID_MODIFICATION_ERR);
 
-                                if (folderList.length === 0) {
-                                    storageFolder.deleteAsync().done(win, 
function () {
+                                                });
+                                            } else {
+                                                
fail(FileError.INVALID_MODIFICATION_ERR);
+                                            }
+                                        });
+                                    } else {
                                         
fail(FileError.INVALID_MODIFICATION_ERR);
+                                    }
+                                });
 
-                                    });
-                                } else {
-                                    fail(FileError.INVALID_MODIFICATION_ERR);
-                                }
-                            });
-                        } else {
-                            fail(FileError.INVALID_MODIFICATION_ERR);
-                        }
-                    });
-
-                }, function () {
-                    fail(FileError.INVALID_MODIFICATION_ERR);
+                            }, function () {
+                                fail(FileError.INVALID_MODIFICATION_ERR);
 
-                });
+                            });
 
 
-            };
-            removeEntry();
-        }
+                        };
+                        removeEntry();
+                    }, function () {
+                        fail(FileError.NOT_FOUND_ERR);
+                    }
+                )
+            }
+        )
 
     },
 
     removeRecursively:function(successCallback,fail,args) { // ["fullPath"]
         var fullPath = args[0];
 
-        
Windows.Storage.StorageFolder.getFolderFromPathAsync(this.fullPath).done(function
 (storageFolder) {
+        
Windows.Storage.StorageFolder.getFolderFromPathAsync(fullPath).done(function 
(storageFolder) {
         var storageFolderPer = 
Windows.Storage.ApplicationData.current.localFolder;
         var storageFolderTem = 
Windows.Storage.ApplicationData.current.temporaryFolder;
 
@@ -309,7 +317,7 @@ module.exports = { //Merges with common
         var options = args[2];
 
         var flag = "";
-        if (options !=- null) {
+        if (options != null) {
             flag = new Flags(options.create, options.exclusive);
         } else {
             flag = new Flags(false, false);
@@ -459,101 +467,103 @@ module.exports = { //Merges with common
         }
         // copy
         var copyFiles = "";
-        if (this.isFile) {
-            copyFiles = function (srcPath, parentPath) {
-                
Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(function 
(storageFile) {
-                    
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
-                        storageFile.copyAsync(storageFolder, name, 
Windows.Storage.NameCollisionOption.failIfExists).then(function (storageFile) {
+        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
+            function (sFile) {
+                copyFiles = function (srcPath, parentPath) {
+                    
Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(function 
(storageFile) {
+                        
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
+                            storageFile.copyAsync(storageFolder, name, 
Windows.Storage.NameCollisionOption.failIfExists).then(function (storageFile) {
+
+                                success(new FileEntry(storageFile.name, 
storageFile.path));
+                            }, function () {
 
-                            success(new FileEntry(storageFile.name, 
storageFile.path));
+                                fail(FileError.INVALID_MODIFICATION_ERR);
+                            });
                         }, function () {
 
-                            fail(FileError.INVALID_MODIFICATION_ERR);
+                            fail(FileError.NOT_FOUND_ERR);
                         });
                     }, function () {
 
                         fail(FileError.NOT_FOUND_ERR);
                     });
-                }, function () {
-
-                    fail(FileError.NOT_FOUND_ERR);
-                });
-            };
-        }
-
-        if (this.isDirectory) {
-            copyFiles = function (srcPath, parentPath) {
-                return new WinJS.Promise(function (complete) {
-                    
Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function 
(storageFolder) {
-                        
storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
-                            var filePromiseArr = [];
-                            if (fileList) {
-                                
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(targetStorageFolder) {
-                                    for (var i = 0; i < fileList.length; i++) {
-                                        
filePromiseArr.push(fileList[i].copyAsync(targetStorageFolder));
-                                    }
-                                    
WinJS.Promise.join(filePromiseArr).then(function () {
-                                        
storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
-                                            var folderPromiseArr = [];
-                                            if (folderList.length === 0) { 
complete(); }
-                                            else {
-
-                                                
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolderTarget) {
-                                                    var tempPromiseArr = [];
-                                                    var index = 0;
-                                                    for (var j = 0; j < 
folderList.length; j++) {
-                                                        
tempPromiseArr[index++] = 
storageFolderTarget.createFolderAsync(folderList[j].name).then(function 
(targetFolder) {
-                                                            
folderPromiseArr.push(copyFiles(folderList[j].path, targetFolder.path));
-                                                        });
-                                                    }
-                                                    
WinJS.Promise.join(tempPromiseArr).then(function () {
-                                                        
WinJS.Promise.join(folderPromiseArr).then(complete);
+                };
+                var copyFinish = function (srcPath, parentPath) {
+                    copyFiles(srcPath, parentPath);
+                };
+                copyFinish(srcPath, parentFullPath);
+            },
+            function () {
+                
Windows.Storage.StorageFolder.getFolderFromPathAsync(args[0]).then(
+                    function (sFolder) {
+                        copyFiles = function (srcPath, parentPath) {
+                            return new WinJS.Promise(function (complete) {
+                                
Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function 
(storageFolder) {
+                                    
storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
+                                        var filePromiseArr = [];
+                                        if (fileList) {
+                                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(targetStorageFolder) {
+                                                for (var i = 0; i < 
fileList.length; i++) {
+                                                    
filePromiseArr.push(fileList[i].copyAsync(targetStorageFolder));
+                                                }
+                                                
WinJS.Promise.join(filePromiseArr).then(function () {
+                                                    
storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
+                                                        var folderPromiseArr = 
[];
+                                                        if (folderList.length 
=== 0) { complete(); }
+                                                        else {
+
+                                                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolderTarget) {
+                                                                var 
tempPromiseArr = [];
+                                                                var index = 0;
+                                                                for (var j = 
0; j < folderList.length; j++) {
+                                                                    
tempPromiseArr[index++] = 
storageFolderTarget.createFolderAsync(folderList[j].name).then(function 
(targetFolder) {
+                                                                        
folderPromiseArr.push(copyFiles(folderList[j].path, targetFolder.path));
+                                                                    });
+                                                                }
+                                                                
WinJS.Promise.join(tempPromiseArr).then(function () {
+                                                                    
WinJS.Promise.join(folderPromiseArr).then(complete);
+                                                                });
+                                                            });
+                                                        }
                                                     });
                                                 });
-                                            }
-                                        });
+                                            });
+                                        }
                                     });
                                 });
-                            }
-                        });
-                    });
-                });
-            };
-        }
-
-        // copy
-        var isFile = this.isFile;
-        var isDirectory = this.isDirectory;
-        var copyFinish = function (srcPath, parentPath) {
-            if (isFile) {
-                copyFiles(srcPath, parentPath);
-            }
-            if (isDirectory) {
-                
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function(storageFolder){
-                    storageFolder.createFolderAsync(name, 
Windows.Storage.CreationCollisionOption.openIfExists).then(function 
(newStorageFolder) {
-                        //can't copy onto itself
-                        if (srcPath == newStorageFolder.path) {
-                            fail(FileError.INVALID_MODIFICATION_ERR);
-                            return;
-                        }
-                        //can't copy into itself
-                        if (srcPath == parentPath) {
-                            fail(FileError.INVALID_MODIFICATION_ERR);
-                            return;
+                            });
+                        };
+                        var copyFinish = function (srcPath, parentPath) {
+                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
+                                storageFolder.createFolderAsync(name, 
Windows.Storage.CreationCollisionOption.openIfExists).then(function 
(newStorageFolder) {
+                                    //can't copy onto itself
+                                    if (srcPath == newStorageFolder.path) {
+                                        
fail(FileError.INVALID_MODIFICATION_ERR);
+                                        return;
+                                    }
+                                    //can't copy into itself
+                                    if (srcPath == parentPath) {
+                                        
fail(FileError.INVALID_MODIFICATION_ERR);
+                                        return;
+                                    }
+                                    copyFiles(srcPath, 
newStorageFolder.path).then(function () {
+                                        
Windows.Storage.StorageFolder.getFolderFromPathAsync(newStorageFolder.path).done(
+                                            function (storageFolder) {
+                                                success(new 
DirectoryEntry(storageFolder.name, storageFolder.path));
+                                            },
+                                            function () { 
fail(FileError.NOT_FOUND_ERR); }
+                                        );
+                                    });
+                                }, function () { 
fail(FileError.INVALID_MODIFICATION_ERR); });
+                            }, function () { 
fail(FileError.INVALID_MODIFICATION_ERR); });
                         }
-                        copyFiles(srcPath, 
newStorageFolder.path).then(function () {
-                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(newStorageFolder.path).done(
-                                function (storageFolder) {
-                                success(new DirectoryEntry(storageFolder.name, 
storageFolder.path));
-                                },
-                                function () { fail(FileError.NOT_FOUND_ERR); }
-                            );
-                        });
-                    }, function () { fail(FileError.INVALID_MODIFICATION_ERR); 
});
-                }, function () { fail(FileError.INVALID_MODIFICATION_ERR);});
+                        copyFinish(srcPath, parentFullPath);
+                    }, function () {
+                        fail(FileError.NOT_FOUND_ERR);
+                    }
+                )
             }
-        };
-        copyFinish(srcPath, parentFullPath);
+        );
     },
 
     moveTo:function(success,fail,args) { // ["fullPath","parent", "newName"]
@@ -569,115 +579,115 @@ module.exports = { //Merges with common
         }
 
         var moveFiles = "";
-
-
-        if (this.isFile) {
-            moveFiles = function (srcPath, parentPath) {
-                
Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(function 
(storageFile) {
-                    
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
-                        storageFile.moveAsync(storageFolder, name, 
Windows.Storage.NameCollisionOption.replaceExisting).then(function () {
-                            success(new FileEntry(name, storageFile.path));
+        Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(
+            function (sFile) {
+                moveFiles = function (srcPath, parentPath) {
+                    
Windows.Storage.StorageFile.getFileFromPathAsync(srcPath).then(function 
(storageFile) {
+                        
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
+                            storageFile.moveAsync(storageFolder, name, 
Windows.Storage.NameCollisionOption.replaceExisting).then(function () {
+                                success(new FileEntry(name, storageFile.path));
+                            }, function () {
+                                fail(FileError.INVALID_MODIFICATION_ERR);
+                            });
                         }, function () {
-                            fail(FileError.INVALID_MODIFICATION_ERR);
+                            fail(FileError.NOT_FOUND_ERR);
                         });
                     }, function () {
                         fail(FileError.NOT_FOUND_ERR);
                     });
-                },function () {
-                    fail(FileError.NOT_FOUND_ERR);
-                });
-            };
-        }
-
-        if (this.isDirectory) {
-            moveFiles = function (srcPath, parentPath) {
-                return new WinJS.Promise(function (complete) {
-                    
Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function 
(storageFolder) {
-                        
storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
-                            var filePromiseArr = [];
-                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(dstStorageFolder) {
-                                if (fileList) {
-                                    for (var i = 0; i < fileList.length; i++) {
-                                        
filePromiseArr.push(fileList[i].moveAsync(dstStorageFolder));
-                                    }
-                                }
-                                
WinJS.Promise.join(filePromiseArr).then(function () {
-                                    
storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
-                                        var folderPromiseArr = [];
-                                        if (folderList.length === 0) {
-                                            // If failed, we must cancel the 
deletion of folders & files.So here wo can't delete the folder.
-                                            complete();
-                                        }
-                                        else {
-                                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolderTarget) {
-                                                var tempPromiseArr = [];
-                                                var index = 0;
-                                                for (var j = 0; j < 
folderList.length; j++) {
-                                                    tempPromiseArr[index++] = 
storageFolderTarget.createFolderAsync(folderList[j].name).then(function 
(targetFolder) {
-                                                        
folderPromiseArr.push(moveFiles(folderList[j].path, targetFolder.path));
-                                                    });
+                };
+                var moveFinish = function (srcPath, parentPath) {
+                    //can't copy onto itself
+                    if (srcPath == parentPath + "\\" + name) {
+                        fail(FileError.INVALID_MODIFICATION_ERR);
+                        return;
+                    }
+                    moveFiles(srcPath, parentFullPath);
+                }
+                moveFinish(srcPath, parentFullPath);
+            },
+            function () {
+                
Windows.Storage.StorageFolder.getFolderFromPathAsync(args[0]).then(
+                    function (sFolder) {
+                        moveFiles = function (srcPath, parentPath) {
+                            return new WinJS.Promise(function (complete) {
+                                
Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function 
(storageFolder) {
+                                    
storageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
+                                        var filePromiseArr = [];
+                                        
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(dstStorageFolder) {
+                                            if (fileList) {
+                                                for (var i = 0; i < 
fileList.length; i++) {
+                                                    
filePromiseArr.push(fileList[i].moveAsync(dstStorageFolder));
                                                 }
-                                                
WinJS.Promise.join(tempPromiseArr).then(function () {
-                                                    
WinJS.Promise.join(folderPromiseArr).then(complete);
+                                            }
+                                            
WinJS.Promise.join(filePromiseArr).then(function () {
+                                                
storageFolder.createFolderQuery().getFoldersAsync().then(function (folderList) {
+                                                    var folderPromiseArr = [];
+                                                    if (folderList.length === 
0) {
+                                                        // If failed, we must 
cancel the deletion of folders & files.So here wo can't delete the folder.
+                                                        complete();
+                                                    }
+                                                    else {
+                                                        
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolderTarget) {
+                                                            var tempPromiseArr 
= [];
+                                                            var index = 0;
+                                                            for (var j = 0; j 
< folderList.length; j++) {
+                                                                
tempPromiseArr[index++] = 
storageFolderTarget.createFolderAsync(folderList[j].name).then(function 
(targetFolder) {
+                                                                    
folderPromiseArr.push(moveFiles(folderList[j].path, targetFolder.path));
+                                                                });
+                                                            }
+                                                            
WinJS.Promise.join(tempPromiseArr).then(function () {
+                                                                
WinJS.Promise.join(folderPromiseArr).then(complete);
+                                                            });
+                                                        });
+                                                    }
                                                 });
-                                            });
-                                        }
+                                            }, function () { });
+                                        });
                                     });
-                                }, function () { });
+                                });
                             });
-                        });
-                    });
-                });
-            };
-        }
-
-        // move
-        var isDirectory = this.isDirectory;
-        var isFile = this.isFile;
-        var moveFinish = function (srcPath, parentPath) {
+                        };
+                        var moveFinish = function (srcPath, parentPath) {
+                            
Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function 
(originFolder) {
+                                
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
+                                    storageFolder.createFolderAsync(name, 
Windows.Storage.CreationCollisionOption.openIfExists).then(function 
(newStorageFolder) {
+                                        //can't move onto directory that is 
not empty
+                                        
newStorageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
+                                            
newStorageFolder.createFolderQuery().getFoldersAsync().then(function 
(folderList) {
+                                                if (fileList.length !== 0 || 
folderList.length !== 0) {
+                                                    
fail(FileError.INVALID_MODIFICATION_ERR);
+                                                    return;
+                                                }
+                                                //can't copy onto itself
+                                                if (srcPath == 
newStorageFolder.path) {
+                                                    
fail(FileError.INVALID_MODIFICATION_ERR);
+                                                    return;
+                                                }
+                                                //can't copy into itself
+                                                if (srcPath == parentPath) {
+                                                    
fail(FileError.INVALID_MODIFICATION_ERR);
+                                                    return;
+                                                }
+                                                moveFiles(srcPath, 
newStorageFolder.path).then(function () {
+                                                    var successCallback = 
function () { success(new DirectoryEntry(name, newStorageFolder.path)); }
+                                                    new 
DirectoryEntry(originFolder.name, 
originFolder.path).removeRecursively(successCallback, fail);
 
-            if (isFile) {
-                //can't copy onto itself
-                if (srcPath == parentPath + "\\" + name) {
-                    fail(FileError.INVALID_MODIFICATION_ERR);
-                    return;
-                }
-                moveFiles(srcPath, parentFullPath);
-            }
-            if (isDirectory) {
-                
Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function 
(originFolder) {
-                    
Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function 
(storageFolder) {
-                        storageFolder.createFolderAsync(name, 
Windows.Storage.CreationCollisionOption.openIfExists).then(function 
(newStorageFolder) {
-                            //can't move onto directory that is not empty
-                            
newStorageFolder.createFileQuery().getFilesAsync().then(function (fileList) {
-                                
newStorageFolder.createFolderQuery().getFoldersAsync().then(function 
(folderList) {
-                                    if (fileList.length !== 0 || 
folderList.length !== 0) {
-                                        
fail(FileError.INVALID_MODIFICATION_ERR);
-                                        return;
-                                    }
-                                    //can't copy onto itself
-                                    if (srcPath == newStorageFolder.path) {
-                                        
fail(FileError.INVALID_MODIFICATION_ERR);
-                                        return;
-                                    }
-                                    //can't copy into itself
-                                    if (srcPath == parentPath) {
-                                        
fail(FileError.INVALID_MODIFICATION_ERR);
-                                        return;
-                                    }
-                                    moveFiles(srcPath, 
newStorageFolder.path).then(function () {
-                                        var successCallback = function () { 
success(new DirectoryEntry(name, newStorageFolder.path)); }
-                                        new DirectoryEntry(originFolder.name, 
originFolder.path).removeRecursively(successCallback, fail);
+                                                }, function () { 
console.log("error!"); });
+                                            });
+                                        });
+                                    }, function () { 
fail(FileError.INVALID_MODIFICATION_ERR); });
+                                }, function () { 
fail(FileError.INVALID_MODIFICATION_ERR); });
+                            }, function () { 
fail(FileError.INVALID_MODIFICATION_ERR); });
 
-                                    }, function () { console.log("error!"); });
-                                });
-                            });
-                        }, function () { 
fail(FileError.INVALID_MODIFICATION_ERR); });
-                    }, function () { fail(FileError.INVALID_MODIFICATION_ERR); 
});
-                }, function () { fail(FileError.INVALID_MODIFICATION_ERR); });
+                        }
+                        moveFinish(srcPath, parentFullPath);
+                    }, function () {
+                        fail(FileError.NOT_FOUND_ERR);
+                    }
+                )
             }
-        };
-        moveFinish(srcPath, parentFullPath);
+        );
     },
 
     tempFileSystem:null,

Reply via email to