diff --git a/assets/apiClient.js b/assets/apiClient.js index 15dba1c..576e12a 100644 --- a/assets/apiClient.js +++ b/assets/apiClient.js @@ -45,9 +45,10 @@ class ApiClient { /** * @param {string} path * @param {(string | string[])?} [args] + * @param {(string | string[])?} [env] * @returns {Promise?>} only returns true, throws error if not success code */ - static async launchApp(path, args = null) { + static async launchApp(path, args = null, env = null) { let params = new URLSearchParams({ "pipe": "1", "path": path @@ -61,6 +62,13 @@ class ApiClient { params.append("args", args.map(arg => arg.replaceAll(" ", "\\ ")).join(" ")); } + if (env != null) { + // @ts-ignore + params.append("env", Object.entries(env).map(([key, val]) => + `${key}=${val}`.replaceAll(" ", "\\ ") + ).join(" ")); + } + let uri = baseURL + "/hbldr?" + params.toString(); let response = await fetch(uri); diff --git a/assets/carouselView.js b/assets/carouselView.js index 222261d..486db13 100644 --- a/assets/carouselView.js +++ b/assets/carouselView.js @@ -206,7 +206,7 @@ async function renderMainContentCarousel(items, fadeout = true) { let logStream = null; if (res && res.path) { - logStream = await ApiClient.launchApp(res.path, res.args); + logStream = await ApiClient.launchApp(res.path, res.args, res.env); res = logStream != null; } diff --git a/assets/modalView.js b/assets/modalView.js index 73e9313..7bc4aa1 100644 --- a/assets/modalView.js +++ b/assets/modalView.js @@ -69,7 +69,7 @@ function renderModalOverlay(items) { let logStream = null; if (res && res.path) { - logStream = await ApiClient.launchApp(res.path, res.args); + logStream = await ApiClient.launchApp(res.path, res.args, res.env); res = logStream != null; } diff --git a/homebrew/Mednafen/homebrew.js b/homebrew/Mednafen/homebrew.js index 0233590..5b2c7b6 100644 --- a/homebrew/Mednafen/homebrew.js +++ b/homebrew/Mednafen/homebrew.js @@ -17,6 +17,8 @@ along with this program; see the file COPYING. If not, see async function main() { const PAYLOAD = window.workingDir + '/mednafen.elf'; + const ENVVARS = {MEDNAFEN_HOME: window.workingDir}; + const ROMDIR = window.workingDir + '/roms/'; const ROMTYPES = ['cue', 'dsk', 'gb', 'gba', 'gbc', 'gen', 'gg', 'lnx', 'nes', 'ngp', 'pce', 'psx', 'sfc', 'smc', 'sms', 'vb', @@ -92,7 +94,8 @@ async function main() { onclick: async() => { return { path: PAYLOAD, - args: ROMDIR + entry.name + args: ROMDIR + entry.name, + env: ENVVARS } } }; @@ -115,7 +118,8 @@ async function main() { if(await checkApiVersion()) { return { path: PAYLOAD, - args: await pickFile(window.workingDir) + args: await pickFile(window.workingDir), + env: ENVVARS }; } } diff --git a/homebrew/Mednafen/.mednafen/mednafen.cfg b/homebrew/Mednafen/mednafen.cfg similarity index 99% rename from homebrew/Mednafen/.mednafen/mednafen.cfg rename to homebrew/Mednafen/mednafen.cfg index 7f30d30..25af2ca 100755 --- a/homebrew/Mednafen/.mednafen/mednafen.cfg +++ b/homebrew/Mednafen/mednafen.cfg @@ -10878,16 +10878,16 @@ snes_faust.input.port1.gamepad.left joystick 0xe4e9845b887ab7fd0006001100010000 snes_faust.input.port1.gamepad.r joystick 0xe4e9845b887ab7fd0006001100010000 button_10 ;snes_faust, Virtual Port 1, Gamepad: Rapid A (right) -snes_faust.input.port1.gamepad.rapid_a keyboard 0x0 94 +snes_faust.input.port1.gamepad.rapid_a joystick 0xe4e9845b887ab7fd0006001100010000 button_1 ;snes_faust, Virtual Port 1, Gamepad: Rapid B (center, lower) -snes_faust.input.port1.gamepad.rapid_b keyboard 0x0 90 +snes_faust.input.port1.gamepad.rapid_b joystick 0xe4e9845b887ab7fd0006001100010000 button_0 ;snes_faust, Virtual Port 1, Gamepad: Rapid X (center, upper) -snes_faust.input.port1.gamepad.rapid_x keyboard 0x0 96 +snes_faust.input.port1.gamepad.rapid_x joystick 0xe4e9845b887ab7fd0006001100010000 button_3 ;snes_faust, Virtual Port 1, Gamepad: Rapid Y (left) -snes_faust.input.port1.gamepad.rapid_y keyboard 0x0 92 +snes_faust.input.port1.gamepad.rapid_y joystick 0xe4e9845b887ab7fd0006001100010000 button_2 ;snes_faust, Virtual Port 1, Gamepad: RIGHT → snes_faust.input.port1.gamepad.right joystick 0xe4e9845b887ab7fd0006001100010000 button_14 diff --git a/src/pc/sys.c b/src/pc/sys.c index aa92bc7..9e54139 100644 --- a/src/pc/sys.c +++ b/src/pc/sys.c @@ -26,7 +26,7 @@ sys_launch_title(const char* title_id, char* args) { int -sys_launch_homebrew(const char* path, char* args) { +sys_launch_homebrew(const char* path, const char* args, const char* env) { char cmd[255]; FILE *pf; diff --git a/src/ps5/sys.c b/src/ps5/sys.c index 2644731..a79a5c0 100644 --- a/src/ps5/sys.c +++ b/src/ps5/sys.c @@ -163,23 +163,22 @@ ps5_find_pid(const char* name) { int -sys_launch_homebrew(const char* path, const char* args) { - char home[PATH_MAX]; - char pwd[PATH_MAX]; - char buf[PATH_MAX]; +sys_launch_homebrew(const char* path, const char* args, const char* env) { char* argv[255]; + char* envp[255]; int optval = 1; - char* envp[3]; - int argc = 0; int fds[2]; pid_t pid; - char* dir; if(!args) { args = ""; } - printf("launch homebrew: %s %s\n", path, args); + if(!env) { + env = ""; + } + + printf("launch homebrew: %s %s %s\n", env, path, args); if(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) { perror("socketpair"); @@ -193,24 +192,18 @@ sys_launch_homebrew(const char* path, const char* args) { return -11; } - strncpy(buf, path, sizeof(buf)); - dir = dirname(buf); - - snprintf(pwd, sizeof(pwd), "PWD=%s", dir); - snprintf(home, sizeof(home), "HOME=%s", dir); - - envp[0] = pwd; - envp[1] = home; - envp[2] = 0; - - argc = args_split(args, argv, 255); + args_split(args, argv, 255); + args_split(env, envp, 255); pid = hbldr_launch(path, fds[1], argv, envp); - close(fds[1]); - for(int i=0; i