diff --git a/dingux/dingux_utils.c b/dingux/dingux_utils.c index c13649d1b5..ec4eca19f1 100644 --- a/dingux/dingux_utils.c +++ b/dingux/dingux_utils.c @@ -17,12 +17,13 @@ #include #include - -#if defined(DINGUX_BETA) #include -#include +#if defined(RS90) +#include #endif +#include + #include "dingux_utils.h" #define DINGUX_ALLOW_DOWNSCALING_FILE "/sys/devices/platform/jz-lcd.0/allow_downscaling" @@ -32,6 +33,14 @@ #define DINGUX_SHARPNESS_DOWNSCALING_FILE "/sys/devices/platform/jz-lcd.0/sharpness_downscaling" #define DINGUX_BATTERY_CAPACITY_FILE "/sys/class/power_supply/battery/capacity" +/* Base path defines */ +#define DINGUX_HOME_ENVAR "HOME" +#define DINGUX_BASE_DIR "retroarch" +#define DINGUX_BASE_DIR_HIDDEN ".retroarch" +#define DINGUX_RS90_MEDIA_PATH "/media" +#define DINGUX_RS90_DEFAULT_SD_PATH "/media/mmcblk0p1" +#define DINGUX_RS90_DATA_PATH "/media/data" + /* OpenDingux Beta defines */ #define DINGUX_BATTERY_VOLTAGE_MIN "/sys/class/power_supply/jz-battery/voltage_min_design" #define DINGUX_BATTERY_VOLTAGE_MAX "/sys/class/power_supply/jz-battery/voltage_max_design" @@ -302,3 +311,80 @@ int dingux_get_battery_level(void) return dingux_read_battery_sys_file(DINGUX_BATTERY_CAPACITY_FILE); #endif } + +/* Fetches the path of the base 'retroarch' + * directory */ +void dingux_get_base_path(char *path, size_t len) +{ + const char *home = NULL; +#if defined(RS90) + struct string_list *dir_list = NULL; +#endif + + if (!path || (len < 1)) + return; + +#if defined(RS90) + /* The RS-90 home directory is located on the + * device's internal storage. This has limited + * space (a total of only 256MB), such that it + * is impractical to store cores and user files + * here. We therefore attempt to use a base + * path on the external microsd card */ + + /* Get list of directories in /media */ + dir_list = dir_list_new(DINGUX_RS90_MEDIA_PATH, + NULL, true, true, false, false); + + if (dir_list) + { + size_t i; + bool path_found = false; + + for (i = 0; i < dir_list->size; i++) + { + const char *dir_path = dir_list->elems[i].data; + int dir_type = dir_list->elems[i].attr.i; + + /* Skip files and invalid entries */ + if ((dir_type != RARCH_DIRECTORY) || + string_is_empty(dir_path) || + string_is_equal(dir_path, DINGUX_RS90_DATA_PATH)) + continue; + + /* Build 'retroarch' subdirectory path */ + snprintf(path, len, "%s%c%s", dir_path, + PATH_DEFAULT_SLASH_C(), DINGUX_BASE_DIR); + + /* We can use this subdirectory path if: + * - Directory corresponds to an unlabelled + * microsd card + * - Subdirectory already exists */ + if (string_is_equal(dir_path, DINGUX_RS90_DEFAULT_SD_PATH) || + path_is_directory(path)) + { + path_found = true; + break; + } + } + + dir_list_free(dir_list); + + if (path_found) + return; + } +#endif + /* Get home directory */ + home = getenv(DINGUX_HOME_ENVAR); + + /* If a home directory is found (which should + * always be the case), base path is "$HOME/.retroarch" + * > If home path is unset, use existing UNIX frontend + * driver default of "retroarch" (this will ultimately + * fail, but there is nothing else we can do...) */ + if (home) + snprintf(path, len, "%s%c%s", home, + PATH_DEFAULT_SLASH_C(), DINGUX_BASE_DIR_HIDDEN); + else + strlcpy(path, DINGUX_BASE_DIR, len); +} diff --git a/dingux/dingux_utils.h b/dingux/dingux_utils.h index bf13140fca..4aa71b578a 100644 --- a/dingux/dingux_utils.h +++ b/dingux/dingux_utils.h @@ -101,6 +101,10 @@ bool dingux_ipu_reset(void); /* Fetches internal battery level */ int dingux_get_battery_level(void); +/* Fetches the path of the base 'retroarch' + * directory */ +void dingux_get_base_path(char *path, size_t len); + RETRO_END_DECLS #endif diff --git a/file_path_special.c b/file_path_special.c index 9b5b7d567b..153bde3018 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -37,6 +37,10 @@ #include #endif +#if defined(DINGUX) +#include "dingux/dingux_utils.h" +#endif + #include #include #include @@ -104,13 +108,8 @@ bool fill_pathname_application_data(char *s, size_t len) return true; } #elif defined(DINGUX) - const char *appdata = getenv("HOME"); - - if (appdata) - { - fill_pathname_join(s, appdata, "/.retroarch", len); - return true; - } + dingux_get_base_path(s, len); + return true; #elif !defined(RARCH_CONSOLE) const char *xdg = getenv("XDG_CONFIG_HOME"); const char *appdata = getenv("HOME"); diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c index b50bce688c..44946f9c93 100644 --- a/frontend/drivers/platform_unix.c +++ b/frontend/drivers/platform_unix.c @@ -1792,6 +1792,9 @@ static void frontend_unix_get_env(int *argc, } #else char base_path[PATH_MAX] = {0}; +#if defined(DINGUX) + dingux_get_base_path(base_path, sizeof(base_path)); +#else const char *xdg = getenv("XDG_CONFIG_HOME"); const char *home = getenv("HOME"); @@ -1803,14 +1806,11 @@ static void frontend_unix_get_env(int *argc, else if (home) { strlcpy(base_path, home, sizeof(base_path)); -#if defined(DINGUX) - strlcat(base_path, "/.retroarch", sizeof(base_path)); -#else strlcat(base_path, "/.config/retroarch", sizeof(base_path)); -#endif } else strcpy_literal(base_path, "retroarch"); +#endif fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE], base_path, "cores", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE])); @@ -2154,10 +2154,14 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content) #else char base_path[PATH_MAX] = {0}; char udisks_media_path[PATH_MAX] = {0}; - const char *xdg = getenv("XDG_CONFIG_HOME"); const char *home = getenv("HOME"); const char *user = getenv("USER"); +#if defined(DINGUX) + dingux_get_base_path(base_path, sizeof(base_path)); +#else + const char *xdg = getenv("XDG_CONFIG_HOME"); + if (xdg) { strlcpy(base_path, xdg, sizeof(base_path)); @@ -2166,12 +2170,9 @@ static int frontend_unix_parse_drive_list(void *data, bool load_content) else if (home) { strlcpy(base_path, home, sizeof(base_path)); -#if defined(DINGUX) - strlcat(base_path, "/.retroarch", sizeof(base_path)); -#else strlcat(base_path, "/.config/retroarch", sizeof(base_path)); -#endif } +#endif strlcpy(udisks_media_path, "/run/media", sizeof(udisks_media_path)); if (user)