Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
|
|
@ -0,0 +1,78 @@
|
|||
/* global Components */
|
||||
'use strict';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
/**
|
||||
* Device storage helper.
|
||||
*
|
||||
* Currently the type includes:
|
||||
* - DesktopClient
|
||||
* TODO: We could have one for device host.
|
||||
* The type name could be called "Device".
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} client Marionette client to use.
|
||||
*/
|
||||
function DesktopClientDeviceStorage(client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
DesktopClientDeviceStorage.prototype = {
|
||||
/**
|
||||
* Get the path to the directory contain the specified type of files.
|
||||
* If the the specificed type directory is not existed yet,
|
||||
* the function will create it.
|
||||
*
|
||||
* @param {String} type the media type, like "pictures", "music", or "videos".
|
||||
* @return {String} path to the directory of the specified type files.
|
||||
*/
|
||||
getMediaFilePath: function(type) {
|
||||
var filePath = path.join(this.getDeviceStoragePath(), type);
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.mkdirSync(filePath);
|
||||
}
|
||||
return filePath;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get device storage path.
|
||||
*
|
||||
* @return {String} path to device storage directory.
|
||||
*/
|
||||
getDeviceStoragePath: function() {
|
||||
// The device-storage-testing directory is also created by FF.
|
||||
// If it doesn't exsit before we get the its path,
|
||||
// we will create it manually.
|
||||
var filePath = path.join(this._getTemporaryPath(),
|
||||
'device-storage-testing');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.mkdirSync(filePath);
|
||||
}
|
||||
return filePath;
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines the temporary directory that
|
||||
* is created by FF because of the prefs.
|
||||
*
|
||||
* @return {String} path to temporary directory.
|
||||
*/
|
||||
_getTemporaryPath: function() {
|
||||
var chrome = this.client.scope({ context: 'chrome' }),
|
||||
tmpDir;
|
||||
|
||||
tmpDir = chrome.executeScript(function() {
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var directoryService =
|
||||
Cc['@mozilla.org/file/directory_service;1'].
|
||||
getService(Ci.nsIProperties);
|
||||
return directoryService.get('TmpD', Ci.nsIFile).path;
|
||||
});
|
||||
|
||||
return tmpDir;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = DesktopClientDeviceStorage;
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
'use strict';
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
/**
|
||||
* The file manager for desktop client.
|
||||
*
|
||||
* @constructor
|
||||
* @param {DeviceStorageFactory.DeviceStorage} deviceStorage
|
||||
* the implementation of the device storage.
|
||||
*/
|
||||
function DesktopClientFileManager(deviceStorage) {
|
||||
this.deviceStorage = deviceStorage;
|
||||
}
|
||||
|
||||
DesktopClientFileManager.prototype = {
|
||||
// TODO: Support blob param.
|
||||
/**
|
||||
* Add files by specified type.
|
||||
* The param is structured as
|
||||
* { type: 'videos', filePath: 'path/to/file', filename: 'filename' }.
|
||||
* { type: 'videos', dirPath: 'path/to/folder' }.
|
||||
*
|
||||
* @param {Array|Object} file would like to add.
|
||||
*/
|
||||
add: function(files) {
|
||||
var that = this;
|
||||
if (!Array.isArray(files)) {
|
||||
files = [files];
|
||||
}
|
||||
|
||||
files.forEach(function(file) {
|
||||
var dirPath = file.dirPath;
|
||||
var type = file.type;
|
||||
if (file.filePath) {
|
||||
that._addFile(file);
|
||||
} else {
|
||||
fs.readdirSync(dirPath).forEach(function(filename) {
|
||||
that._addFile({
|
||||
type: type,
|
||||
filePath: path.join(dirPath, filename)
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_addFile: function(file) {
|
||||
var filename = file.filename || path.basename(file.filePath);
|
||||
var targetPath = this.deviceStorage.getMediaFilePath(file.type);
|
||||
if (!fs.existsSync(targetPath)) {
|
||||
fs.mkdirSync(targetPath);
|
||||
}
|
||||
this._copyFile(file.filePath, path.join(targetPath, filename));
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove files by specified type.
|
||||
* The param is structured as
|
||||
* { type: 'videos', filename: 'filename' }.
|
||||
*
|
||||
* @param {Array|Object} files would like to remove.
|
||||
*/
|
||||
remove: function(files) {
|
||||
var filePaths;
|
||||
if (Array.isArray(files)) {
|
||||
filePaths = files;
|
||||
} else {
|
||||
filePaths = [files];
|
||||
}
|
||||
|
||||
filePaths.forEach(function(file) {
|
||||
var filePath = this.deviceStorage.getMediaFilePath(file.type);
|
||||
fs.unlinkSync(path.join(filePath, file.filename));
|
||||
// Remove the directory if no file in it.
|
||||
if (fs.readdirSync(filePath).length === 0) {
|
||||
fs.rmdirSync(filePath);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all files and directories in device storage.
|
||||
*/
|
||||
removeAllFiles: function() {
|
||||
var deviceStoragePath = this.deviceStorage.getDeviceStoragePath(),
|
||||
fileList = [];
|
||||
|
||||
if (fs.existsSync(deviceStoragePath)) {
|
||||
fileList = fs.readdirSync(deviceStoragePath);
|
||||
fileList.forEach(function(item) {
|
||||
this._removeFile(path.join(deviceStoragePath, item));
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a file or a directory even inclued files.
|
||||
*
|
||||
* @param {String} filePath a file path or directory path.
|
||||
*/
|
||||
_removeFile: function(filePath) {
|
||||
var fileList = [],
|
||||
fileNumber = 0,
|
||||
dirname = '';
|
||||
|
||||
if (fs.statSync(filePath).isDirectory()) {
|
||||
fileList = fs.readdirSync(filePath);
|
||||
fileNumber = fileList.length;
|
||||
|
||||
if (fileNumber === 0) {
|
||||
fs.rmdirSync(filePath);
|
||||
}
|
||||
|
||||
fileList.forEach(function(item) {
|
||||
this._removeFile(path.join(filePath, item));
|
||||
}.bind(this));
|
||||
} else {
|
||||
fs.unlinkSync(filePath);
|
||||
dirname = path.dirname(filePath);
|
||||
if (fs.readdirSync(dirname).length === 0) {
|
||||
fs.rmdirSync(dirname);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy a single file to a specified path.
|
||||
*
|
||||
* @param {String} source the path of the source file.
|
||||
* @param {String} target the path you would like to copy to.
|
||||
*/
|
||||
_copyFile: function(source, target) {
|
||||
var BUF_LENGTH = 64 * 1024,
|
||||
buffer = new Buffer(BUF_LENGTH),
|
||||
fdr = fs.openSync(source, 'r'),
|
||||
fdw = fs.openSync(target, 'w'),
|
||||
bytesRead = 1,
|
||||
position = 0;
|
||||
|
||||
while (bytesRead > 0) {
|
||||
bytesRead = fs.readSync(fdr, buffer, 0, BUF_LENGTH, position);
|
||||
fs.writeSync(fdw, buffer, 0, bytesRead);
|
||||
position += bytesRead;
|
||||
}
|
||||
fs.closeSync(fdr);
|
||||
fs.closeSync(fdw);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = DesktopClientFileManager;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Generate the file manager for each type of host.
|
||||
* Currently the type includes:
|
||||
* - DesktopClient
|
||||
* TODO: We could have one for device host.
|
||||
* The type name could be called "Device".
|
||||
*/
|
||||
var DeviceStorageFactory = {
|
||||
/**
|
||||
* Generate a instance of device storage.
|
||||
*
|
||||
* @return {Object} instance of device storage.
|
||||
*/
|
||||
generate: function(client, type) {
|
||||
return DeviceStorageFactory[type](client);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate the DesktopClient instance.
|
||||
*
|
||||
* @param {Object} client the marionette client.
|
||||
* @return {Object} instance of DesktopClientDeviceStorage.
|
||||
*/
|
||||
DeviceStorageFactory.DesktopClient = function(client) {
|
||||
var DesktopClient = require('./desktop_client_device_storage');
|
||||
return new DesktopClient(client);
|
||||
};
|
||||
|
||||
module.exports = DeviceStorageFactory;
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
/**
|
||||
* Generate the file manager for each type of host.
|
||||
* Currently the type includes:
|
||||
* - DesktopClient
|
||||
* TODO: We could have one for device host.
|
||||
* The type name could be called "Device".
|
||||
*/
|
||||
var FileManagerFactory = {
|
||||
/**
|
||||
* Generate a instance of file manager.
|
||||
*
|
||||
* @return {Object} instance of file manager.
|
||||
*/
|
||||
generate: function(deviceStorage, type) {
|
||||
return FileManagerFactory[type](deviceStorage);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate the DesktopClient instance.
|
||||
*
|
||||
* @param {Object} deviceStorage desktop client deviceStorage.
|
||||
* @return {Object} instance of DesktopClientFileManager.
|
||||
*/
|
||||
FileManagerFactory.DesktopClient = function(deviceStorage) {
|
||||
var DesktopClient = require('./desktop_client_file_manager');
|
||||
return new DesktopClient(deviceStorage);
|
||||
};
|
||||
|
||||
module.exports = FileManagerFactory;
|
||||
Loading…
Reference in a new issue