diff options
Diffstat (limited to 'tools/file_packager.py')
-rw-r--r-- | tools/file_packager.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py index 9699730f..aa70ac6a 100644 --- a/tools/file_packager.py +++ b/tools/file_packager.py @@ -13,6 +13,9 @@ Usage: file_packager.py TARGET [--preload A [B..]] [--embed C [D..]] [--exclude E [F..]] [--compress COMPRESSION_DATA] [--crunch[=X]] [--js-output=OUTPUT.js] [--no-force] [--use-preload-cache] [--no-heap-copy] + --preload , + --embed See emcc --help for more details on those options. + --crunch=X Will compress dxt files to crn with quality level X. The crunch commandline tool must be present and CRUNCH should be defined in ~/.emscripten that points to it. JS crunch decompressing code will be added to convert the crn to dds in the browser. @@ -107,7 +110,11 @@ for arg in sys.argv[2:]: jsoutput = arg.split('=')[1] if '=' in arg else None leading = '' elif arg.startswith('--crunch'): - from shared import CRUNCH + try: + from shared import CRUNCH + except Exception, e: + print >> sys.stderr, 'count not import CRUNCH (make sure it is defined properly in ~/.emscripten)' + raise e crunch = arg.split('=')[1] if '=' in arg else '128' leading = '' elif arg.startswith('--plugin'): @@ -462,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') { @@ -472,8 +481,9 @@ if has_preloaded: } var PACKAGE_NAME = '%s'; var REMOTE_PACKAGE_NAME = (Module['filePackagePrefixURL'] || '') + '%s'; + var REMOTE_PACKAGE_SIZE = %d; 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''' @@ -567,19 +577,21 @@ 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: size }; } else { Module.dataFileDownloads[url].loaded = event.loaded; @@ -631,7 +643,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( @@ -644,7 +656,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) { @@ -666,7 +678,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; |