mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 01:55:19 -04:00
Webclient: Fix downloading map still leaving behind file in IndexedDB
Prints an error message to console now. Not ideal but better than before.
This commit is contained in:
parent
12b6752f62
commit
dbbf0cbc66
52
src/Menus.c
52
src/Menus.c
@ -1259,44 +1259,38 @@ static void SaveLevelScreen_RemoveOverwrites(struct SaveLevelScreen* s) {
|
|||||||
|
|
||||||
#ifdef CC_BUILD_WEB
|
#ifdef CC_BUILD_WEB
|
||||||
#include <emscripten.h>
|
#include <emscripten.h>
|
||||||
extern int unlink(const char* path);
|
|
||||||
|
|
||||||
static void DownloadMap(const cc_string* path) {
|
static void DownloadMap(const cc_string* path) {
|
||||||
struct Stream s;
|
char strPath[NATIVE_STR_LEN];
|
||||||
|
char strFile[NATIVE_STR_LEN];
|
||||||
cc_string file;
|
cc_string file;
|
||||||
char str[NATIVE_STR_LEN];
|
cc_result res;
|
||||||
cc_uint8* ptr = NULL;
|
Platform_ConvertString(strPath, path);
|
||||||
cc_uint32 len;
|
|
||||||
|
|
||||||
if (Stream_OpenFile(&s, path)) return;
|
|
||||||
if (File_Length(s.Meta.File, &len)) goto finished;
|
|
||||||
ptr = Mem_TryAlloc(len, 1);
|
|
||||||
if (!ptr || Stream_Read(&s, ptr, len)) goto finished;
|
|
||||||
|
|
||||||
/* maps/aaa.schematic -> aaa.cw */
|
/* maps/aaa.schematic -> aaa.cw */
|
||||||
file = String_UNSAFE_SubstringAt(path, 5);
|
file = String_UNSAFE_SubstringAt(path, 5);
|
||||||
file.length = String_LastIndexOf(&file, '.');
|
file.length = String_LastIndexOf(&file, '.');
|
||||||
String_AppendConst(&file, ".cw");
|
String_AppendConst(&file, ".cw");
|
||||||
Platform_ConvertString(str, &file);
|
Platform_ConvertString(strFile, &file);
|
||||||
|
|
||||||
EM_ASM_({
|
res = EM_ASM_({
|
||||||
var data = HEAPU8.subarray($1, $1 + $2);
|
try {
|
||||||
var blob = new Blob([data], { type: 'application/octet-stream' });
|
var name = UTF8ToString($0);
|
||||||
var name = UTF8ToString($0);
|
var data = FS.readFile(name);
|
||||||
Module.saveBlob(blob, name);
|
var blob = new Blob([data], { type: 'application/octet-stream' });
|
||||||
}, str, ptr, len);
|
Module.saveBlob(blob, UTF8ToString($1));
|
||||||
|
FS.unlink(name);
|
||||||
|
return 0;
|
||||||
|
} catch (e) {
|
||||||
|
if (!(e instanceof FS.ErrnoError)) abort(e);
|
||||||
|
return -e.errno;
|
||||||
|
}
|
||||||
|
}, strPath, strFile);
|
||||||
|
|
||||||
Chat_Add1("&eDownloaded map: %s", &file);
|
if (res) {
|
||||||
finished:
|
Logger_SysWarn2(res, "Downloading map", &file);
|
||||||
s.Close(&s);
|
} else {
|
||||||
/* TODO: Don't free ptr until download is saved?? */
|
Chat_Add1("&eDownloaded map: %s", &file);
|
||||||
/* TODO: Make save map dialog prettier */
|
}
|
||||||
Mem_Free(ptr);
|
|
||||||
|
|
||||||
/* Cleanup the schematic file left behind */
|
|
||||||
Platform_ConvertString(str, path);
|
|
||||||
/* TODO: This doesn't seem to work properly */
|
|
||||||
unlink(str);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user