/*
* Copyright 2011 Google Inc. All Rights Reserved.
-
+
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
var file = basename_(key);
dir.getFile(file, {create: true}, function(fileEntry) {
var fileTransfer = new FileTransfer();
- fileTransfer.download(url, fileEntry.fullPath, function(entry) {
+ fileTransfer.download(url, fileEntry.toURL(), function(entry) {
lookupTable[key] = entry.toURL();
entry.setMetadata(function(entry) {
- callback();
}, failCallback, {'com.apple.MobileBackup': 1});
-
+ callback();
}, failCallback);
}, failCallback);
});
callback();
}, onError);
});
+
}
if (!gal) {
/*
* Copyright 2011 Google Inc. All Rights Reserved.
-
+
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
// Array of bundle names in the order that they appear in the manifest.
this.bundleOrder = [];
// Table of callbacks, per bundle.
- this.loadingBundles = {};
- this.loadedBundles = {};
-
this.loaded = {};
this.progress = {};
this.error = {};
* Downloads assets contained in the named bundle.
* @param {string} bundleName name of single bundle to download.
*/
- GAL.prototype.download = function(bundleName, callback, timeout) {
- if (timeout == undefined) {
- timeout = 0;
- }
-
+ GAL.prototype.download = function(bundleName, callback) {
var bundle = this.bundles[bundleName];
if (callback == undefined) {
callback = function() {
if (!bundle) {
// Attempting to download invalid bundle.
- throw "Invalid bundle specified";
+ throw "Invalid bundle specified :: " + bundleName;
}
var that = this;
this.check(bundleName, function(result) {
if (result.success) {
// Already downloaded. Success!
- that.loadedBundles[bundleName] = true;
- that.loadingBundles[bundleName] = false;
fireCallback_(that.loaded, bundleName, {
success: true,
cached: true,
bundleName: bundleName
});
-
callback();
+
} else {
if (!that.online()) {
// Otherwise, since we're offline, error out.
callback();
} else {
// Setup a loop via callback chaining.
- that.loadedBundles[bundleName] = false;
- that.loadingBundles[bundleName] = true;
(function loop(index) {
// If we've finished loading all of the assets in the bundle.
if (index == bundle.length) {
- that.loadedBundles[bundleName] = true;
- that.loadingBundles[bundleName] = false;
fireCallback_(that.loaded, bundleName, {
bundleName: bundleName,
success: true
});
- setTimeout(function() {
- callback();
- }, timeout);
+ callback();
return;
}
var key = bundle[index];
// Get the full url to the asset.
- var url = that.manifest.assetRoot + key;
+ var url = encodeURI(that.manifest.assetRoot + key);
// Fetch full url and store it locally.
that.adapter.saveAsset(key, url, function() {
fireCallback_(that.progress, bundleName, {
addCallback_(this.error, opt_bundleName, callback);
};
- GAL.prototype.downloadAndCall = function(bundleName, callback, timeoutIfNotLoaded) {
+ GAL.prototype.downloadAndCall = function(bundleName, callback) {
var $this = this;
-
- if ($this.loadedBundles[bundleName]) {
- callback();
- } else if ($this.loadingBundles[bundleName]) {
- $this.onLoaded(bundleName, function() {
+ this.check(bundleName, function(info) {
+ if (info.success) {
callback();
- });
- } else {
- this.check(bundleName, function(info) {
- if (info.success) {
- callback();
- } else {
- $this.download(bundleName, callback, timeoutIfNotLoaded);
- }
- });
- }
+ } else {
+ $this.download(bundleName, callback);
+ }
+ });
};
/**
// Set this.bundles object and this.bundleOrder array
for (var i = 0, bundle; bundle = manifest.bundles[i]; ++i) {
this.bundles[bundle.name] = bundle.contents;
- this.loadedBundles[bundle.name] = false;
- this.loadingBundles[bundle.name] = false;
this.bundleOrder.push(bundle.name);
}
}
this.initAdapter_.call(context, function() {
setManifest_.call(context, manifest);
// Optionally, start auto-download.
- if (manifest.autoDownload && context.online()) {
+ if (manifest.autoDownload) {
downloadAll_.call(context);
}
callback();
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!
return;