}
}
});
-
- // load file native plugin
- tizen.cordova.file(require);
}
};
* limitations under the License.
*/
-//= require('Errors.js');
-//= require('rootsUtils.js');
-//= require('DirectoryEntry.js');
-//= require('DirectoryReader.js');
-//= require('Entry.js');
-//= require('FileReader.js');
-//= require('fileSystemPaths.js');
-//= require('fileSystems-roots.js');
-//= require('FileWriter.js');
-//= require('requestFileSystem.js');
-//= require('resolveLocalFileSystemURI.js');
+var native_ = new xwalk.utils.NativeManager(extension);
-//= require('FileSystem.js');
-//= require('File.js');
+function FileManager() {}
+
+FileManager.prototype.truncate = function(uri, length, successCallback, errorCallback) {
+ var callArgs = {
+ 'uri': uri,
+ 'length': length
+ };
+
+ var result = native_.callSync('File_truncate', callArgs);
+ if (native_.isFailure(result)) {
+ if (errorCallback) {
+ errorCallback(native_.getErrorObject(result));
+ }
+ } else {
+ if (successCallback) {
+ successCallback(length);
+ }
+ }
+};
+
+exports = new FileManager();
modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
- tizen.cordova.load(require);
-
channel.onNativeReady.fire();
// End of bootstrap
"runs": true
},
{
+ "file": "plugins/cordova-plugin-file/tizen/Errors.js",
+ "id": "cordova-plugin-file.tizen.Errors",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/rootUtils.js",
+ "id": "cordova-plugin-file.tizen.rootUtils",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/DirectoryEntry.js",
+ "id": "cordova-plugin-file.tizen.DirectoryEntry",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/DirectoryReader.js",
+ "id": "cordova-plugin-file.tizen.DirectoryReader",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/Entry.js",
+ "id": "cordova-plugin-file.tizen.Entry",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/FileReader.js",
+ "id": "cordova-plugin-file.tizen.FileReader",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/fileSystemPaths.js",
+ "id": "cordova-plugin-file.tizen.fileSystemPaths",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/fileSystems-roots.js",
+ "id": "cordova-plugin-file.tizen.fileSystems-roots",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/FileWriter.js",
+ "id": "cordova-plugin-file.tizen.FileWriter",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/requestFileSystem.js",
+ "id": "cordova-plugin-file.tizen.requestFileSystem",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/resolveLocalFileSystemURI.js",
+ "id": "cordova-plugin-file.tizen.resolveLocalFileSystemURI",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/File.js",
+ "id": "cordova-plugin-file.tizen.File",
+ "runs": true
+ },
+ {
+ "file": "plugins/cordova-plugin-file/tizen/FileSystem.js",
+ "id": "cordova-plugin-file.tizen.FileSystem",
+ "merges": [
+ "window.FileSystem"
+ ]
+ },
+ {
"file": "plugins/cordova-plugin-file-transfer/www/FileTransferError.js",
"id": "cordova-plugin-file-transfer.FileTransferError",
"clobbers": [
cordova.define('cordova-plugin-file.tizen.DirectoryEntry', function(require, exports, module) {
// TODO: remove -> end
+ var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+ var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
function sanitizePath(path) {
var prepend = '/' === path[0];
var input = path.split('/');
}
var getFunction = function(successCallback, errorCallback, args, isDirectory) {
- var uri = rootsUtils.internalUrlToNativePath(args[0]),
- path = rootsUtils.stripTrailingSlash(args[1]),
+ var uri = rootUtils.internalUrlToNativePath(args[0]),
+ path = rootUtils.stripTrailingSlash(args[1]),
options = args[2] || {},
create_flag = !!options.create,
exclusive_flag = !!options.exclusive,
absolute_path = uri + '/' + path;
}
- var root = rootsUtils.findFilesystem(absolute_path).nativeURL;
+ var root = rootUtils.findFilesystem(absolute_path).nativeURL;
var clean_path = sanitizePath(absolute_path);
if (0 !== clean_path.indexOf(root)) {
var parent_path = clean_path.substring(0, clean_path.lastIndexOf('/'));
var child_name = clean_path.substring(clean_path.lastIndexOf('/') + 1);
- if (!rootsUtils.isValidFileName(child_name)) {
+ if (!rootUtils.isValidFileName(child_name)) {
console.error('Disallowed character detected in file name: ' + child_name);
errorCallback && errorCallback(FileError.ENCODING_ERR);
return;
console.error('Error while resolving dir - already exist file');
errorCallback && errorCallback(FileError.TYPE_MISMATCH_ERR);
} else {
- successCallback && successCallback(rootsUtils.createEntry(dir));
+ successCallback && successCallback(rootUtils.createEntry(dir));
}
};
new_obj = dir.createFile(child_name);
}
- successCallback && successCallback(rootsUtils.createEntry(new_obj));
+ successCallback && successCallback(rootUtils.createEntry(new_obj));
},
function () {
console.error('Error - immediate parent does not exist');
);
} catch (err) {
console.error('Error - Could not resolve');
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
}
} else {
console.error('Error - create flag is false - new directory would not be created');
tizen.filesystem.resolve(clean_path, resolveSuccess, resolveError, 'rw');
} catch (err) {
console.error('Error - Could not resolve');
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
}
};
getFunction(successCallback, errorCallback, args, true);
},
removeRecursively: function(successCallback, errorCallback, args) {
- var uri = rootsUtils.internalUrlToNativePath(args[0]);
+ var uri = rootUtils.internalUrlToNativePath(args[0]);
if (!uri) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
return;
}
- if (rootsUtils.isRootUri(uri)) {
+ if (rootUtils.isRootUri(uri)) {
console.error('It is not allowed to remove root directory.');
errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
return;
}
} catch (err) {
console.error('Error - Could not deleteDirectory');
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
}
}, function(e) {
console.error('Error: ' + e.message);
- errorCallback && errorCallback(ConvertTizenFileError(e));
+ errorCallback && errorCallback(convertTizenFileError(e));
}, 'rw'
);
} catch (err) {
console.error('Error - Could not resolve');
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
}
},
getFile: function(successCallback, errorCallback, args) {
cordova.define('cordova-plugin-file.tizen.DirectoryReader', function(require, exports, module) {
// TODO: remove -> end
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
module.exports = {
readEntries: function(successCallback, errorCallback, args) {
- var uri = rootsUtils.internalUrlToNativePath(args[0]);
+ var uri = rootUtils.internalUrlToNativePath(args[0]);
if (!uri) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
}
var fail = function(e) {
- errorCallback && errorCallback(ConvertTizenFileError(e));
+ errorCallback && errorCallback(convertTizenFileError(e));
}
try {
tizen.filesystem.resolve(uri,
f.listFiles(function(v) {
var retVal = [];
for (var i = 0; i < v.length; ++i) {
- var obj = rootsUtils.createEntry(v[i], rootsUtils.findFilesystem(v[i].toURI()).filesystemName);
+ var obj = rootUtils.createEntry(v[i], rootUtils.findFilesystem(v[i].toURI()).filesystemName);
obj.isDirectory = v[i].isDirectory;
obj.isFile = v[i].isFile;
retVal.push(obj);
cordova.define('cordova-plugin-file.tizen.Entry', function(require, exports, module) {
// TODO: remove -> end
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
var resolveParent = function(srcURL, errorCallback, rest){
try {
tizen.filesystem.resolve(
}
}, function (err) {
console.error('Error - resolve file ' + srcURL + ' failed');
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
},
'r');
} catch (exception) {
console.error('Error - resolve ' + srcURL + ' file thrown exception');
- errorCallback && errorCallback(ConvertTizenFileError(exception));
+ errorCallback && errorCallback(convertTizenFileError(exception));
}
};
var changeFile = function(method, successCallback, errorCallback, args) {
- var srcURL = rootsUtils.internalUrlToNativePath(args[0]);
+ var srcURL = rootUtils.internalUrlToNativePath(args[0]);
var name = args[2];
- var destDir = rootsUtils.internalUrlToNativePath(args[1]);
+ var destDir = rootUtils.internalUrlToNativePath(args[1]);
var destURL = destDir + '/' + name;
function fail(e, msg) {
return;
}
- if (!rootsUtils.isValidFileName(name)) {
+ if (!rootUtils.isValidFileName(name)) {
fail(FileError.ENCODING_ERR, 'Error - Disallowed character detected in the file name: ' + name);
return;
}
tizen.filesystem.resolve(
destURL,
function (destFile) {
- var destEntry = rootsUtils.createEntry(destFile);
+ var destEntry = rootUtils.createEntry(destFile);
destEntry.isDirectory = destFile.isDirectory;
successCallback && successCallback(destEntry);
}, function (err) {
- fail(ConvertTizenFileError(err), 'Error - resolve result entry failed');
+ fail(convertTizenFileError(err), 'Error - resolve result entry failed');
}
);
} catch (exception) {
- fail(ConvertTizenFileError(exception), 'Error - resolve result entry thrown exception');
+ fail(convertTizenFileError(exception), 'Error - resolve result entry thrown exception');
}
}, function (err) {
- fail(ConvertTizenFileError(err), 'Error - ' + method + ' operation failed');
+ fail(convertTizenFileError(err), 'Error - ' + method + ' operation failed');
}
);
} catch (exception) {
- fail(ConvertTizenFileError(exception), 'Error - ' + method + ' operation thrown exception');
+ fail(convertTizenFileError(exception), 'Error - ' + method + ' operation thrown exception');
}
}
performAction(srcFile, parentDir);
}, 'r');
} catch (exception) {
- fail(ConvertTizenFileError(exception), 'Error - resolve destination entry threw exception');
+ fail(convertTizenFileError(exception), 'Error - resolve destination entry threw exception');
}
}
);
fail(FileError.NOT_FOUND_ERR, 'Error - destination directory does not exist');
}, 'r');
} catch (e) {
- fail(ConvertTizenFileError(e), 'Error - resolve destination directory threw exception');
+ fail(convertTizenFileError(e), 'Error - resolve destination directory threw exception');
}
};
module.exports = {
getFileMetadata: function(successCallback, errorCallback, args) {
- var uri = rootsUtils.internalUrlToNativePath(args[0]);
+ var uri = rootUtils.internalUrlToNativePath(args[0]);
if (!uri) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
return;
var result = { 'size': file.fileSize, 'lastModifiedDate': file.modified };
successCallback && successCallback(result);
}, function (err) {
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
}, 'r');
} catch (exception) {
console.error('Error - resolve failed');
- errorCallback && errorCallback(ConvertTizenFileError(exception));
+ errorCallback && errorCallback(convertTizenFileError(exception));
}
},
setMetadata: function(successCallback, errorCallback, args) {
changeFile('copyTo', successCallback, errorCallback, args);
},
remove: function(successCallback, errorCallback, args) {
- var url = rootsUtils.internalUrlToNativePath(args[0]);
+ var url = rootUtils.internalUrlToNativePath(args[0]);
if (!url) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
return;
}
- if (rootsUtils.isRootUri(url)) {
+ if (rootUtils.isRootUri(url)) {
console.error('It is not allowed to remove root directory.');
errorCallback && errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
return;
function() {successCallback && successCallback();},
function(err) {
console.error('Error - ' + method + ' failed');
- errorCallback && errorCallback(ConvertTizenFileError(err));
+ errorCallback && errorCallback(convertTizenFileError(err));
}];
if (srcFile.isFile) {
//remove recursive flag
parentDir[method].apply(parentDir, args);
} catch (exception) {
console.error('Error - ' + method + ' thrown exception ' + JSON.stringify(exception));
- errorCallback && errorCallback(ConvertTizenFileError(exception));
+ errorCallback && errorCallback(convertTizenFileError(exception));
}
}
);
},
getParent: function(successCallback, errorCallback, args) {
- var url = rootsUtils.internalUrlToNativePath(args[0]);
+ var url = rootUtils.internalUrlToNativePath(args[0]);
if (!url) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
return;
}
- if (rootsUtils.isRootUri(url)) {
- successCallback && successCallback(rootsUtils.findFilesystem(url));
+ if (rootUtils.isRootUri(url)) {
+ successCallback && successCallback(rootUtils.findFilesystem(url));
return;
}
resolveParent(url, errorCallback,
function(srcFile, parentDir){
- successCallback && successCallback(rootsUtils.createEntry(srcFile.parent));
+ successCallback && successCallback(rootUtils.createEntry(srcFile.parent));
}
);
}
* limitations under the License.
*/
+// TODO: remove when added to public cordova repository -> begin
+cordova.define('cordova-plugin-file.tizen.Errors', function(require, exports, module) {
+// TODO: remove -> end
+
/**
* Function converting a Tizen error to a cordova error
*
* {unsigned short} WebAPIError error
*/
-function ConvertTizenFileError(err) {
+function convertTizenFileError(err) {
switch (err.name) {
case 'InvalidValuesError':
return FileError.ENCODING_ERR;
return FileError.ENCODING_ERR;
}
}
+
+module.exports = convertTizenFileError;
+
+//TODO: remove when added to public cordova repository -> begin
+});
+//TODO: remove -> end
// TODO: remove when added to public cordova repository -> begin
});
-
-exports = function(require) {
- require('cordova-tizen').addPlugin('cordova-plugin-file.File', plugin_name, 'runs');
- require('cordova-tizen').addPlugin('cordova-plugin-file.FileSystem', 'cordova-plugin-file.tizen.FileSystem', 'merges', 'window.FileSystem');
-};
// TODO: remove -> end
cordova.define('cordova-plugin-file.tizen.FileReader', function(require, exports, module) {
// TODO: remove -> end
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
function read(operation, url, start, end, successCallback, errorCallback, encoding) {
- url = rootsUtils.internalUrlToNativePath(url);
+ url = rootUtils.internalUrlToNativePath(url);
if (!url) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
}
var fail = function(e) {
- errorCallback && errorCallback(ConvertTizenFileError(e));
+ errorCallback && errorCallback(convertTizenFileError(e));
}
var win = function(size) {
successCallback && successCallback(size);
cordova.define('cordova-plugin-file.tizen.FileWriter', function(require, exports, module) {
// TODO: remove -> end
-var utils_ = xwalk.utils;
-var native_ = new utils_.NativeManager(extension);
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
// https://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
function toUTF8Array(str) {
module.exports = {
write: function(successCallback, errorCallback, args) {
- var uri = rootsUtils.internalUrlToNativePath(args[0]);
+ var uri = rootUtils.internalUrlToNativePath(args[0]);
var data = args[1];
var position = args[2];
var isBinary = args[3];
successCallback && successCallback(length);
}, errorCallback, [args[0], stream.position]);
} catch (error) {
- errorCallback && errorCallback(ConvertTizenFileError(error));
+ errorCallback && errorCallback(convertTizenFileError(error));
}
}
var openStreamError = function (error) {
- errorCallback && errorCallback(ConvertTizenFileError(error));
+ errorCallback && errorCallback(convertTizenFileError(error));
}
try {
file.openStream('rw', openStreamSuccess, openStreamError);
} catch (error) {
- errorCallback && errorCallback(ConvertTizenFileError(error));
+ errorCallback && errorCallback(convertTizenFileError(error));
}
}
var onError = function (error) {
- errorCallback && errorCallback(ConvertTizenFileError(error));
+ errorCallback && errorCallback(convertTizenFileError(error));
}
try {
tizen.filesystem.resolve(uri, onSuccess, onError, 'rw');
} catch (error) {
- errorCallback && errorCallback(ConvertTizenFileError(error));
+ errorCallback && errorCallback(convertTizenFileError(error));
}
},
truncate: function(successCallback, errorCallback, args) {
- var uri = rootsUtils.internalUrlToNativePath(args[0]);
+ var uri = rootUtils.internalUrlToNativePath(args[0]);
var length = args[1];
if (!uri) {
uri = uri.substring(uriPrefix.length);
}
- var callArgs = {
- 'uri': uri,
- 'length': length
- };
-
- var result = native_.callSync('File_truncate', callArgs);
- if (native_.isFailure(result)) {
- errorCallback && errorCallback(ConvertTizenFileError(native_.getErrorObject(result)));
- } else {
- successCallback && successCallback(length);
- }
+ tizen.cordova.file.truncate(uri, length, successCallback, function(error) {
+ if (errorCallback) {
+ errorCallback(convertTizenFileError(error));
+ }
+ });
}
};
cordova.define('cordova-plugin-file.tizen.fileSystems-roots', function(require, exports, module) {
// TODO: remove -> end
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
var channel = require('cordova/channel');
channel.waitForInitialization('onGetRootsReady');
channel.onCordovaReady.subscribe(function() {
- rootsUtils.getRoots(function () {
+ rootUtils.getRoots(function () {
channel.initializationComplete('onGetRootsReady');
});
});
module.exports = {
requestAllFileSystems: function(successCallback, errorCallback, args) {
- rootsUtils.getRoots(successCallback);
+ rootUtils.getRoots(successCallback);
}
};
cordova.define('cordova-plugin-file.tizen.requestFileSystem', function(require, exports, module) {
// TODO: remove -> end
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
module.exports = {
requestFileSystem: function(successCallback, errorCallback, args) {
var type = args[0];
// both filesystems are located on internal storage
if ('INTERNAL' === r.units[i].type) {
if (size < r.units[i].availableCapacity) {
- rootsUtils.getRoots(function(roots) {
+ rootUtils.getRoots(function(roots) {
for (var i = 0; i < roots.length; ++i) {
if (fsName === roots[i].filesystemName) {
successCallback({ 'name': fsName, 'root': roots[i] });
cordova.define('cordova-plugin-file.tizen.resolveLocalFileSystemURI', function(require, exports, module) {
// TODO: remove -> end
+var convertTizenFileError = require('cordova-plugin-file.tizen.Errors');
+var rootUtils = require('cordova-plugin-file.tizen.rootUtils');
+
var filePrefix = 'file://';
module.exports = {
resolveLocalFileSystemURI: function(successCallback, errorCallback, args) {
- var path = rootsUtils.internalUrlToNativePath(args[0]);
+ var path = rootUtils.internalUrlToNativePath(args[0]);
if (!path) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
}
function onResolve(file) {
- var filesystem = rootsUtils.findFilesystem(file.toURI());
+ var filesystem = rootUtils.findFilesystem(file.toURI());
- var entry = rootsUtils.createEntry(file, filesystem.filesystemName);
+ var entry = rootUtils.createEntry(file, filesystem.filesystemName);
entry.isDirectory = file.isDirectory;
successCallback(entry);
}
function onError(error) {
- errorCallback && errorCallback(ConvertTizenFileError(error));
+ errorCallback && errorCallback(convertTizenFileError(error));
}
tizen.filesystem.resolve(path, onResolve, onError, 'r');
},
_getLocalFilesystemPath: function(successCallback, errorCallback, args) {
- var path = rootsUtils.internalUrlToNativePath(args[0]);
+ var path = rootUtils.internalUrlToNativePath(args[0]);
if (!path) {
errorCallback && errorCallback(FileError.ENCODING_ERR);
* limitations under the License.
*/
-var rootsUtils = (function() {
+// TODO: remove when added to public cordova repository -> begin
+cordova.define('cordova-plugin-file.tizen.rootUtils', function(require, exports, module) {
+// TODO: remove -> end
+
+var rootUtils = (function() {
var filePrefix = 'file:///';
function stripTrailingSlash(str) {
internalUrlToNativePath: internalUrlToNativePath
};
})();
+
+module.exports = rootUtils;
+
+//TODO: remove when added to public cordova repository -> begin
+});
+//TODO: remove -> end