*/
(function(gal) {
- var ROOT_DIR = 'gal';
+ var ROOT_DIR;
var DEFAULT_QUOTA = 1024 * 1024 * 100;
function onError(error) {
* initialized.
* @param {string} opt_quota The quota (in bytes) to request (optional).
*/
- GALFS.prototype.init = function(callback, opt_quota) {
+ GALFS.prototype.init = function(fsprefix, callback, opt_quota) {
+ if (fsprefix == undefined) {
+ fsprefix = '';
+ }
+ if (fsprefix != '') {
+ fsprefix += '/';
+ }
+ ROOT_DIR = fsprefix + "gal";
// requestFileSystem and storageInfo shims
var requestFileSystem = window.requestFileSystem ||
window.webkitRequestFileSystem;
var onInitFs = function(fs) {
that.fs = fs;
- // Create a directory for the root of the GAL
- fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
- that.root = dirEntry;
- callback();
- }, onError);
+ createDir_(fs.root, ROOT_DIR.split('/'), function(res) {
+ // Create a directory for the root of the GAL
+ fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
+ that.root = dirEntry;
+ callback();
+ }, onError);
+ });
+
+
};
// Callback when the filesystem API has granted quota
/**
* Clears everything out of the root directory. Mostly for unit testing.
*/
- GALFS.prototype.clear = function() {
+ GALFS.prototype.clear = function(cb) {
// Remove the root directory
this.root.removeRecursively(function() {
}, onError);
var that = this;
- this.lookupTable = {};
// And then recreate it
- this.fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
- that.root = dirEntry;
- }, onError);
+ fs = this.fs;
+
+ createDir_(fs.root, ROOT_DIR.split('/'), function(res) {
+ // Create a directory for the root of the GAL
+ fs.root.getDirectory(ROOT_DIR, {create: true}, function(dirEntry) {
+ that.root = dirEntry;
+ callback();
+ }, onError);
+ });
+
+ cb();
};
if (!gal) {
* @constructor
* @param {Object} manifest URL to manifest file.
*/
- var GAL = function(manifest) {
+ var GAL = function(manifest, fsprefix) {
+ if (fsprefix == undefined) {
+ fsprefix = '';
+ }
+
+ this._fsprefix = fsprefix;
this._manifest = manifest;
// Dictionary of arrays of all of the bundles contained in the manifest.
this.bundles = {};
this.loaded = {};
this.progress = {};
this.error = {};
+ this.adapter = null;
};
/**
return this.adapter.root.toURL();
};
+ GAL.prototype.initAdapter = function(callback) {
+ if (null == this.adapter) {
+ initAdapter_(callback);
+ } else {
+ callback(this.adapter);
+ }
+ };
GAL.prototype.downloadAll = function() {
- console.log('downloadAll');
downloadAll_.call(this);
};
+ GAL.prototype.clear = function(callback) {
+ var $this = this;
+
+ this.initAdapter(
+ function(adapter) {
+ adapter.clear(callback);
+ }
+ );
+ };
/**
* @private
* @param {function} callback Called when the adapter has initialized.
*/
function initAdapter_(callback) {
+ var $this = this;
+
+ if (this.adapter != null) {
+ callback(this.adapter);
+ return;
+ }
+
this.adapter = new GAL.adapterClass();
- this.adapter.init(function() {
- callback();
+ this.adapter.init(this._fsprefix, function() {
+ callback($this.adapter);
});
}
initAdapter_.call(context, function() {
setManifest_.call(context, manifest);
// Optionally, start auto-download.
+ console.log('autodownload ' + manifest.autoDownload);
if (manifest.autoDownload && context.online()) {
downloadAll_.call(context);
}
}
/**
- *
+ * @private
* Starts downloading all of the assets in the manifest, in order.
*/
function downloadAll_() {
var that = this;
// Start by downloading the first bundle, then download subsequent ones.
(function loop(bundleIndex) {
+ console.log(bundleIndex);
if (bundleIndex == that.bundleOrder.length) {
// We're done downloading stuff!
+ console.log('ok !');
return;
}
+
var bundleName = that.bundleOrder[bundleIndex];
+ console.log('loading ' + bundleName);
that.onLoaded(bundleName, function() {
// Once bundle is loaded, load the next bundle.
loop(bundleIndex + 1);