Add module.saveBlob function for web client

Also try to avoid terminating game when invalid huffman code is read when inflating data
This commit is contained in:
UnknownShadow200 2020-08-03 23:12:58 +10:00
parent 4072b62439
commit 68f4144cc9
4 changed files with 23 additions and 19 deletions

View File

@ -291,7 +291,7 @@ static int Huffman_Decode(struct InflateState* state, struct HuffmanTable* table
}
}
Logger_Abort("DEFLATE - Invalid huffman code");
Inflate_Fail(state, INF_ERR_INVALID_CODE);
return -1;
}

View File

@ -51,6 +51,7 @@ enum ERRORS_ALL {
/* OpenAL initing errors */
AL_ERR_INIT_DEVICE, AL_ERR_INIT_CONTEXT,
/* Inflate errors */
INF_ERR_BLOCKTYPE, INF_ERR_LEN_VERIFY, INF_ERR_REPEAT_BEG, INF_ERR_REPEAT_END
INF_ERR_BLOCKTYPE, INF_ERR_LEN_VERIFY, INF_ERR_REPEAT_BEG, INF_ERR_REPEAT_END,
INF_ERR_INVALID_CODE
};
#endif

View File

@ -1272,23 +1272,7 @@ static void DownloadMap(const String* path) {
var data = HEAPU8.subarray($1, $1 + $2);
var blob = new Blob([data], { type: 'application/octet-stream' });
var name = UTF8ToString($0);
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, name);
return;
}
var url = window.URL.createObjectURL(blob);
var elem = document.createElement('a');
elem.href = url;
elem.download = name;
elem.style.display = 'none';
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
window.URL.revokeObjectURL(url);
Module.saveBlob(blob, name);
}, str, ptr, len);
Chat_Add1("&eDownloaded map: %s", &file);

View File

@ -1659,6 +1659,25 @@ void Platform_Init(void) {
/* Check if an error occurred when pre-loading IndexedDB */
EM_ASM_({ if (window.cc_idbErr) stringToUTF8(window.cc_idbErr, $0, 64); }, tmp);
EM_ASM({
Module.saveBlob = function(blob, name) {
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(blob, name); return;
}
var url = window.URL.createObjectURL(blob);
var elem = document.createElement('a');
elem.href = url;
elem.download = name;
elem.style.display = 'none';
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
window.URL.revokeObjectURL(url);
}
});
if (!tmp[0]) return;
Chat_Add1("&cError preloading IndexedDB: %c", tmp);
Chat_AddRaw("&cPreviously saved settings/maps will be lost");