Skip to content

Commit

Permalink
(RS-90) Move appdata (retroarch) base directory to external microsd card
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgleaver committed Jul 15, 2021
1 parent 23b8652 commit 9e100b7
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 19 deletions.
92 changes: 89 additions & 3 deletions dingux/dingux_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@

#include <file/file_path.h>
#include <streams/file_stream.h>

#if defined(DINGUX_BETA)
#include <string/stdstring.h>
#include <stdlib.h>
#if defined(RS90)
#include <lists/dir_list.h>
#endif

#include <stdlib.h>

#include "dingux_utils.h"

#define DINGUX_ALLOW_DOWNSCALING_FILE "/sys/devices/platform/jz-lcd.0/allow_downscaling"
Expand All @@ -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"
Expand Down Expand Up @@ -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);
}
4 changes: 4 additions & 0 deletions dingux/dingux_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 6 additions & 7 deletions file_path_special.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#include <kernel/image.h>
#endif

#if defined(DINGUX)
#include "dingux/dingux_utils.h"
#endif

#include <stdlib.h>
#include <boolean.h>
#include <string.h>
Expand Down Expand Up @@ -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");
Expand Down
19 changes: 10 additions & 9 deletions frontend/drivers/platform_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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]));
Expand Down Expand Up @@ -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));
Expand All @@ -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)
Expand Down

0 comments on commit 9e100b7

Please sign in to comment.