From 0ec148485dbaea0570d11009b0bd85cbc5573481 Mon Sep 17 00:00:00 2001 From: Lockl00p <97256723+Lockl00p@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:31:27 -0500 Subject: [PATCH] File Upload support added. --- misc/buildfiles/emscripten/prejs.js | 34 +++++++-------------------- misc/buildfiles/emscripten/shell.html | 32 +++++++++++++++++++++++++ misc/tools/all/xonotic.subr | 2 +- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/misc/buildfiles/emscripten/prejs.js b/misc/buildfiles/emscripten/prejs.js index ca4ce9a8..cb1e820e 100644 --- a/misc/buildfiles/emscripten/prejs.js +++ b/misc/buildfiles/emscripten/prejs.js @@ -1,38 +1,22 @@ //current command in ascii decimal let currentcmd = [0,0,0] +let currentfile = ""; +const sleep = ms => new Promise(r => setTimeout(r,ms)); + let isready = function(){ - if(FS.analyzePath("/data/",false).exists == true){return 1} + if(FS.analyzePath("/save/data",false).exists == true){return 1} return 0 } let cmditerate = 0 -console.log("Run Terminal Commands by running cmd(\"command to run here\")") -cmd = function(input){ - for (let i = 0; i < input.length; i++){ - - currentcmd[i] = input.charCodeAt(i) - - } - currentcmd[input.length] = 10; - return 0 -} -Module['arguments'] = ["-xonotic"] +Module['arguments'] = ["-xonotic","-basedir /save/data"] Module['print'] = function(text){console.log(text);} Module['preRun'] = function(){ - function stdin(){ - /*//if current command is default, it just returns 0, code for null - if(currentcmd == [0,0,0]){ - return 0 - } - //it iterates through the cmd - cmditerate++; - if(cmditerate - 1 > currentcmd.length - 1) {currentcmd = [0,0,0]; return 10} - return currentcmd[cmditerate - 1] - - */ return 10}; + function stdin(){return 10}; var stdout = null; var stderr = null; FS.init(stdin,stdout,stderr); - FS.mkdir('/config') - FS.mount(IDBFS,{},"/config"); + FS.mkdir('/save') + FS.mount(IDBFS,{},"/save"); + } \ No newline at end of file diff --git a/misc/buildfiles/emscripten/shell.html b/misc/buildfiles/emscripten/shell.html index b7d7f4e9..2d51563c 100644 --- a/misc/buildfiles/emscripten/shell.html +++ b/misc/buildfiles/emscripten/shell.html @@ -17,6 +17,38 @@ var Module = { canvas: (function() { return document.getElementById('canvas'); })() }; + const file_reader = new FileReader(); + file_reader.addEventListener("load", readf); + function readf(event){ + //also heavily derivative of Riot's code on Stack Overflow cause I sure as hell don't udnerstand it. + const uint8Arr = new Uint8Array(file_reader.result); + console.log(currentname+fname); + try { + stream = FS.open(currentname+fname,'w'); + } catch (error) { + alert(error.toString() + "... Was that not a directory?"); + return; + } + + FS.write(stream, uint8Arr, 0, uint8Arr.length, 0); + FS.close(stream); + } + + var currentname = ""; + var fname = "" + + function save_files(){ + fname = this.files[0].name; + file_reader.readAsArrayBuffer(this.files[0]); + }; + + + var file_selector = document.createElement('input'); + file_selector.setAttribute('type', 'file'); + file_selector.addEventListener("change", save_files, false); + + + diff --git a/misc/tools/all/xonotic.subr b/misc/tools/all/xonotic.subr index 2fcfe99a..cbc6b448 100755 --- a/misc/tools/all/xonotic.subr +++ b/misc/tools/all/xonotic.subr @@ -312,7 +312,7 @@ case "$cmd" in verbose emmake make $MAKEFLAGS clean fi for T in $TARGETS; do - verbose emmake make $MAKEFLAGS LDFLAGS_EXTRA=' -sENVIRONMENT=web --pre-js ../../../../misc/buildfiles/emscripten/prejs.js -lidbfs.js --preload-file ../../../../.tmp/data@/config/ -sSINGLE_FILE -sUSE_ZLIB -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=1500MB -sMAXIMUM_MEMORY=4GB' EXE_UNIXSDL="darkplaces-emscripten.html" DP_SSE=0 CFLAGS_EXTRA="-I../../../../misc/builddeps/emscripten/d0_blind_id/include -L../../../../misc/builddeps/emscripten/d0_blind_id/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/d0_blind_id/lib -I../../../../misc/builddeps/emscripten/gmp/include -L../../../../misc/builddeps/emscripten/gmp/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/gmp/lib -L../../../../misc/builddeps/emscripten/jpeg/lib/ -Wl,-rpath,../../../../misc/builddeps/emscripten/jpeg/lib/ -I../../../../misc/builddeps/emscripten/jpeg/include/ -sUSE_SDL=2 -sUSE_ZLIB=1 -DUSE_GLES2" LIBM="" LIBZ="" LIB_JPEG="../../../../misc/builddeps/emscripten/jpeg/lib/libjpeg.a" STRIP=: "$@" "$T" + verbose emmake make $MAKEFLAGS LDFLAGS_EXTRA=' -sENVIRONMENT=web --pre-js ../../../../misc/buildfiles/emscripten/prejs.js --shell-file ../../../../misc/buildfiles/emscripten/shell.html -lidbfs.js -sSINGLE_FILE -sUSE_ZLIB -sALLOW_MEMORY_GROWTH -sINITIAL_MEMORY=1500MB -sMAXIMUM_MEMORY=4GB' EXE_UNIXSDL="darkplaces-emscripten.html" DP_SSE=0 CFLAGS_EXTRA="-I../../../../misc/builddeps/emscripten/d0_blind_id/include -L../../../../misc/builddeps/emscripten/d0_blind_id/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/d0_blind_id/lib -I../../../../misc/builddeps/emscripten/gmp/include -L../../../../misc/builddeps/emscripten/gmp/lib -Wl,-rpath,../../../../misc/builddeps/emscripten/gmp/lib -L../../../../misc/builddeps/emscripten/jpeg/lib/ -Wl,-rpath,../../../../misc/builddeps/emscripten/jpeg/lib/ -I../../../../misc/builddeps/emscripten/jpeg/include/ -sUSE_SDL=2 -sUSE_ZLIB=1 -DUSE_GLES2" LIBM="" LIBZ="" LIB_JPEG="../../../../misc/builddeps/emscripten/jpeg/lib/libjpeg.a" STRIP=: "$@" "$T" done for T in $BAD_TARGETS; do $ECHO "Warning: discarded invalid client $T." -- 2.39.2