mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-08 14:56:12 -04:00
Webclient: Get 'download size for texture packs' to work in firefox for some sites at least
This commit is contained in:
parent
adb314458e
commit
408cb1726e
@ -65,24 +65,3 @@ and change to
|
||||
```
|
||||
eventHandler.target.addEventListener(eventHandler.eventTypeString, jsEventHandler, { useCapture: eventHandler.useCapture, passive: false });
|
||||
```
|
||||
|
||||
#### Texture pack confirm dialog always shows *Download size: Determining*..
|
||||
Unfortunately emscripten doesn't store content-length for HEAD http requests. This can be fixed.
|
||||
|
||||
First you need to find at what offset emscripten stores content-length. Look for something like:
|
||||
```
|
||||
xhr.onprogress = function(e) {
|
||||
...
|
||||
Fetch.setu64(fetch + 32, e.total);
|
||||
```
|
||||
then look for
|
||||
```
|
||||
xhr.onload = function(e) {
|
||||
...
|
||||
```
|
||||
and finally change that to
|
||||
```
|
||||
xhr.onload = function(e) {
|
||||
Fetch.setu64(fetch + 32, e.total);
|
||||
...
|
||||
```
|
||||
|
@ -124,7 +124,7 @@ NOTE: You have to change entry->d_type == DT_DIR to Directory_Exists(&path) (TOD
|
||||
|
||||
#### Web
|
||||
|
||||
```emcc *.c -s FETCH=1 -s ALLOW_MEMORY_GROWTH=1 --preload-file texpacks/default.zip```
|
||||
```emcc *.c -s ALLOW_MEMORY_GROWTH=1 --preload-file texpacks/default.zip```
|
||||
|
||||
The generated javascript file has some issues. [See here for how to fix](doc/compile-fixes.md#webclient-patches)
|
||||
|
||||
|
17
src/Http.c
17
src/Http.c
@ -354,17 +354,26 @@ static void Http_DownloadAsync(struct HttpRequest* req) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open(reqMethod, url);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
|
||||
var getContentLength = function(e) {
|
||||
if (e.total) return e.total;
|
||||
|
||||
try {
|
||||
var len = xhr.getResponseHeader('Content-Length');
|
||||
return parseInt(len, 10);
|
||||
} catch (ex) { return 0; }
|
||||
};
|
||||
|
||||
xhr.onload = function(e) {
|
||||
var src = new Uint8Array(xhr.response);
|
||||
var len = src.byteLength;
|
||||
var data = _malloc(len);
|
||||
HEAPU8.set(src, data);
|
||||
onFinished(data, len || e.total, xhr.status);
|
||||
onFinished(data, len || getContentLength(e), xhr.status);
|
||||
};
|
||||
xhr.onerror = function(e) { onFinished(0, 0, xhr.status); };
|
||||
xhr.ontimeout = function(e) { onFinished(0, 0, xhr.status); };
|
||||
xhr.onprogress = function(e) { onProgress(e.loaded, e.total); };
|
||||
xhr.onerror = function(e) { onFinished(0, 0, xhr.status); };
|
||||
xhr.ontimeout = function(e) { onFinished(0, 0, xhr.status); };
|
||||
xhr.onprogress = function(e) { onProgress(e.loaded, e.total); };
|
||||
|
||||
try { xhr.send(); } catch (e) { onFinished(0, 0, 0); }
|
||||
}, urlStr, req->requestType, OnFinishedAsync, OnUpdateProgress);
|
||||
|
Loading…
x
Reference in New Issue
Block a user