diff options
author | Struan Donald <struan@exo.org.uk> | 2014-10-03 15:07:08 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-08-28 14:27:15 +0100 |
commit | a69d425c0e5c004145ac1ab70e2f7f9fc329b54c (patch) | |
tree | 8eb7ff0ff7aaa0fce8bc7214ec6e15b694fddbdc /src/js/files.js | |
parent | 8fd15b58733c51d7f001f9eac66b7d03830ec0b4 (diff) |
update Android to Cordova 3.6
Required due to security issue
Remove Android directory as no longer required, move src -> www to match
standard layout, update .gitignore to avoid including the standard
platform files, update README based on Steve's zurich one
Diffstat (limited to 'src/js/files.js')
-rw-r--r-- | src/js/files.js | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/src/js/files.js b/src/js/files.js deleted file mode 100644 index eea38c3..0000000 --- a/src/js/files.js +++ /dev/null @@ -1,173 +0,0 @@ -/** - * Things to do with Phonegap files - * Mainly wrappers around their async functions to return Promises - */ - - (function (FMS, Backbone, _, $) { - _.extend(FMS, { - files: { - // move a file at from a uri to a desination directory. maintains file name - moveURI: function (srcURI, newName ) { - - var fileEntry; - return getFileFromURI(srcURI) - .pipe( function (file) { - fileEntry = file; - - return getFileSystem(); - }) - .pipe( function (filesystem) { - FMS.printDebug('Filesystem returned: ' + filesystem); - - return getDirectory(filesystem.root, CONFIG.FILES_DIR, {create: true}); - }) - .pipe( function(directory) { - return moveFile( fileEntry, directory, newName ); - }); - }, - - copyURI: function (srcURI, newName ) { - - var fileEntry; - return getFileFromURI(srcURI) - .pipe( function (file) { - fileEntry = file; - - return getFileSystem(); - }) - .pipe( function (filesystem) { - FMS.printDebug('Filesystem returned: ' + filesystem); - - return getDirectory(filesystem.root, CONFIG.FILES_DIR, {create: true}); - }) - .pipe( function(directory) { - return copyFile( fileEntry, directory, newName ); - }); - }, - - deleteURI: function (uri) { - FMS.printDebug('Deleting URI: ' + uri); - - return getFileFromURI(uri) - .pipe( function (file) { - var deletingFile = $.Deferred(); - file.remove(deletingFile.resolve, deletingFile.reject); - return deletingFile; - }); - - }, - - // Delete a file from the filesystem - deleteFile: function (path) { - - FMS.printDebug('Deleting file: ' + path); - - // Turn path into a filename - var filename = path.split('/').pop(); - - return getFileSystem() - .pipe(function (filesystem) { - return getDirectory(filesystem.root, CONFIG.FILES_DIR); - }) - .pipe(function (directory) { - return getFile(directory, filename, {}); - }) - .pipe(function (file) { - var deletingFile = $.Deferred(); - file.remove(deletingFile.resolve, deletingFile.reject); - return deletingFile; - }); - - } - } - }); - - // Wrap the async Phonegap way of getting a filesystem in a promise - function getFileSystem() { - - FMS.printDebug('Getting the file system'); - - var filesystem = $.Deferred(); - - window.requestFileSystem( - LocalFileSystem.PERSISTENT, - 0, - filesystem.resolve, - filesystem.reject ); - - return filesystem.promise(); - } - - // Wrap the async Phonegap way of getting a directory in a promise - function getDirectory (rootDirectory, path, options) { - - FMS.printDebug('Getting a directory: ' + path); - - var directory = $.Deferred(); - - rootDirectory.getDirectory(path, options, directory.resolve, directory.reject); - - return directory.promise(); - } - - // Wrap the async Phonegap way of getting a file in a promise - function getFile (directory, path, options) { - - FMS.printDebug('Getting a file with path: ' + path + ' in directory: ' + directory.fullPath); - - var file = $.Deferred(); - - directory.getFile(path, options, file.resolve, file.reject); - - return file.promise(); - } - - function moveFile (src, dest, newName) { - - FMS.printDebug( 'moveing file ' + src.fullPath + ' to ' + dest.fullPath ); - - var move = $.Deferred(); - - var destPath = dest.fullPath + '/' + src.name; - var srcPath = src.fullPath + ''; - if ( srcPath === destPath ) { - FMS.printDebug('not moving because files are the same'); - move.resolve( src ); - } else { - FMS.printDebug('paths differ so moving'); - src.moveTo( dest, newName, move.resolve, move.reject); - } - - return move.promise(); - } - - function copyFile (src, dest, newName) { - - FMS.printDebug( 'copying file ' + src.fullPath + ' to ' + dest.fullPath ); - - var copy = $.Deferred(); - - var destPath = dest.fullPath + '/' + src.name; - var srcPath = src.fullPath + ''; - if ( srcPath === destPath ) { - FMS.printDebug('not copying because files are the same'); - copy.resolve( src ); - } else { - FMS.printDebug('paths differ so copying'); - src.copyTo( dest, newName, copy.resolve, copy.reject); - } - - return copy.promise(); - } - - function getFileFromURI(uri) { - - FMS.printDebug( 'getting file from uri ' + uri ); - - var file = $.Deferred(); - - window.resolveLocalFileSystemURI( uri, file.resolve, file.reject); - - return file.promise(); - } -})(FMS, Backbone, _, $); |