aboutsummaryrefslogtreecommitdiff
path: root/tools/file_packager.py
diff options
context:
space:
mode:
authorjonas echterhoff <jonas@unity3d.com>2014-02-11 12:40:34 +0100
committerAlon Zakai <alonzakai@gmail.com>2014-02-12 11:06:43 -0800
commitaf5e9738ff7ac11ca0bc0c380a531965fe61df3c (patch)
tree100fffbf590ee2fcbab418ad0745d34e4cf07309 /tools/file_packager.py
parent073bf29d3e09cae0e6405747b0ecba0120ae954c (diff)
Make download progress be correctly displayed when the browser cannot report total size of files (as is the case in compressed downloads), but writing full size to the generated js.
Diffstat (limited to 'tools/file_packager.py')
-rw-r--r--tools/file_packager.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 448bb994..2c70767a 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -469,6 +469,8 @@ if has_preloaded:
package_uuid = uuid.uuid4();
remote_package_name = os.path.basename(Compression.compressed_name(data_target) if Compression.on else data_target)
+ statinfo = os.stat(remote_package_name)
+ remote_package_size = statinfo.st_size
ret += r'''
var PACKAGE_PATH;
if (typeof window === 'object') {
@@ -479,8 +481,9 @@ if has_preloaded:
}
var PACKAGE_NAME = '%s';
var REMOTE_PACKAGE_NAME = (Module['filePackagePrefixURL'] || '') + '%s';
+ var REMOTE_PACKAGE_SIZE = '%s';
var PACKAGE_UUID = '%s';
- ''' % (data_target, remote_package_name, package_uuid)
+ ''' % (data_target, remote_package_name, remote_package_size, package_uuid)
if use_preload_cache:
code += r'''
@@ -574,19 +577,22 @@ if has_preloaded:
'''
ret += r'''
- function fetchRemotePackage(packageName, callback, errback) {
+ function fetchRemotePackage(packageName, packageSize, callback, errback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', packageName, true);
xhr.responseType = 'arraybuffer';
xhr.onprogress = function(event) {
var url = packageName;
- if (event.loaded && event.total) {
+ var size = packageSize;
+ if (event.total)
+ size = event.total;
+ if (event.loaded) {
if (!xhr.addedTotal) {
xhr.addedTotal = true;
if (!Module.dataFileDownloads) Module.dataFileDownloads = {};
Module.dataFileDownloads[url] = {
loaded: event.loaded,
- total: event.total
+ total: packageSize
};
} else {
Module.dataFileDownloads[url].loaded = event.loaded;
@@ -638,7 +644,7 @@ if has_preloaded:
function preloadFallback(error) {
console.error(error);
console.error('falling back to default preload behavior');
- fetchRemotePackage(REMOTE_PACKAGE_NAME, processPackageData, handleError);
+ fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, handleError);
};
openDatabase(
@@ -651,7 +657,7 @@ if has_preloaded:
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, processPackageData, preloadFallback);
} else {
console.info('loading ' + PACKAGE_NAME + ' from remote');
- fetchRemotePackage(REMOTE_PACKAGE_NAME,
+ fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE,
function(packageData) {
cacheRemotePackage(db, PACKAGE_PATH + PACKAGE_NAME, packageData, {uuid:PACKAGE_UUID}, processPackageData,
function(error) {
@@ -673,7 +679,7 @@ if has_preloaded:
# Only tricky bit is the fetch is async, but also when runWithFS is called is async, so we handle both orderings.
ret += r'''
var fetched = null, fetchedCallback = null;
- fetchRemotePackage(REMOTE_PACKAGE_NAME, function(data) {
+ fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) {
if (fetchedCallback) {
fetchedCallback(data);
fetchedCallback = null;