From a820aeadeccbacf39ca8705cb5b19cbb5c35e70a Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 28 Aug 2016 22:50:56 -0500 Subject: [PATCH] try to use XDG for emscripten --- frontend/drivers/platform_emscripten.c | 68 +++++++++++++++++++++++++- pkg/emscripten/webplayer.js | 1 + 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index 909b621140..fd63f39bc6 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -63,6 +63,72 @@ void cmd_take_screenshot(void) command_event(CMD_EVENT_TAKE_SCREENSHOT, NULL); } +static void frontend_emscripten_get_env(int *argc, char *argv[], + void *args, void *params_data) +{ + (void)args; + + char base_path[PATH_MAX] = {0}; + const char *xdg = getenv("XDG_CONFIG_HOME"); + const char *home = getenv("HOME"); + + if (xdg) + snprintf(base_path, sizeof(base_path), + "%s/retroarch", xdg); + else if (home) + snprintf(base_path, sizeof(base_path), + "%s/.config/retroarch", home); + else + snprintf(base_path, sizeof(base_path), "retroarch"); + + fill_pathname_join(g_defaults.dir.core, base_path, + "cores", sizeof(g_defaults.dir.core)); + fill_pathname_join(g_defaults.dir.core_info, base_path, + "cores", sizeof(g_defaults.dir.core_info)); + fill_pathname_join(g_defaults.dir.autoconfig, base_path, + "autoconfig", sizeof(g_defaults.dir.autoconfig)); + + if (path_is_directory("/usr/local/share/retroarch/assets")) + fill_pathname_join(g_defaults.dir.assets, "/usr/local/share/retroarch", + "assets", sizeof(g_defaults.dir.assets)); + else if (path_is_directory("/usr/share/retroarch/assets")) + fill_pathname_join(g_defaults.dir.assets, "/usr/share/retroarch", + "assets", sizeof(g_defaults.dir.assets)); + else if (path_is_directory("/usr/local/share/games/retroarch/assets")) + fill_pathname_join(g_defaults.dir.assets, "/usr/local/share/games/retroarch", + "assets", sizeof(g_defaults.dir.assets)); + else if (path_is_directory("/usr/share/games/retroarch/assets")) + fill_pathname_join(g_defaults.dir.assets, "/usr/share/games/retroarch", + "assets", sizeof(g_defaults.dir.assets)); + else + fill_pathname_join(g_defaults.dir.assets, base_path, + "assets", sizeof(g_defaults.dir.assets)); + + fill_pathname_join(g_defaults.dir.menu_config, base_path, + "config", sizeof(g_defaults.dir.menu_config)); + fill_pathname_join(g_defaults.dir.remap, g_defaults.dir.menu_config, + "remaps", sizeof(g_defaults.dir.remap)); + fill_pathname_join(g_defaults.dir.playlist, base_path, + "playlists", sizeof(g_defaults.dir.playlist)); + fill_pathname_join(g_defaults.dir.cursor, base_path, + "database/cursors", sizeof(g_defaults.dir.cursor)); + fill_pathname_join(g_defaults.dir.database, base_path, + "database/rdb", sizeof(g_defaults.dir.database)); + fill_pathname_join(g_defaults.dir.shader, base_path, + "shaders", sizeof(g_defaults.dir.shader)); + fill_pathname_join(g_defaults.dir.cheats, base_path, + "cheats", sizeof(g_defaults.dir.cheats)); + fill_pathname_join(g_defaults.dir.overlay, base_path, + "overlay", sizeof(g_defaults.dir.overlay)); + fill_pathname_join(g_defaults.dir.osk_overlay, base_path, + "overlay", sizeof(g_defaults.dir.osk_overlay)); + fill_pathname_join(g_defaults.dir.core_assets, base_path, + "downloads", sizeof(g_defaults.dir.core_assets)); + fill_pathname_join(g_defaults.dir.screenshot, base_path, + "screenshots", sizeof(g_defaults.dir.screenshot)); + fill_pathname_join(g_defaults.dir.thumbnails, base_path, + "thumbnails", sizeof(g_defaults.dir.thumbnails)); +} int main(int argc, char *argv[]) { @@ -77,7 +143,7 @@ int main(int argc, char *argv[]) } frontend_ctx_driver_t frontend_ctx_emscripten = { - NULL, /* environment_get */ + frontend_emscripten_get_env, /* environment_get */ NULL, /* init */ NULL, /* deinit */ NULL, /* exitspawn */ diff --git a/pkg/emscripten/webplayer.js b/pkg/emscripten/webplayer.js index ed4bbcdc5d..11f53d9aa3 100644 --- a/pkg/emscripten/webplayer.js +++ b/pkg/emscripten/webplayer.js @@ -124,6 +124,7 @@ function setupFolderStructure() FS.createPath('/', '/home/web_user/saves', true, true); FS.createPath('/', '/home/web_user/states', true, true); FS.createPath('/', '/home/web_user/system', true, true); + FS.createPath('/', '/home/web_user/screenshots', true, true); } function stat(path)