From c52e6628cdf9c53e9143e903ab793bf59987a0ea Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 7 Oct 2013 17:09:09 +0200 Subject: [PATCH] Introduce plat_get_skin_dir and update plat_get_root_dir functions On GP2X and Pandora, plat_get_root_dir points to the directory in which the PicoDrive executable is found. On regular Linux, it now points to the '.picodrive' directory inside the user's home folder. plat_get_skin_dir now points to the 'skin' directory inside the data directory. The data directory can be set with PICO_DATA_DIR at compile time. If that variable is not set, the data directory is set to the directory of the PicoDrive executable. --- linux/plat.c | 43 +++++++++++++++++++++++++++++++++++++------ menu.c | 9 +++++---- plat.h | 3 +++ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/linux/plat.c b/linux/plat.c index c34beea..ec381fa 100644 --- a/linux/plat.c +++ b/linux/plat.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "../plat.h" @@ -40,24 +41,54 @@ int plat_is_dir(const char *path) return 0; } -int plat_get_root_dir(char *dst, int len) +static int plat_get_data_dir(char *dst, int len) { - int j, ret; - - ret = readlink("/proc/self/exe", dst, len - 1); +#ifdef PICO_DATA_DIR + memcpy(dst, PICO_DATA_DIR, sizeof PICO_DATA_DIR); + return sizeof(PICO_DATA_DIR) - 1; +#else + int j, ret = readlink("/proc/self/exe", dst, len - 1); if (ret < 0) { perror("readlink"); ret = 0; } dst[ret] = 0; - for (j = strlen(dst); j > 0; j--) + for (j = ret - 1; j > 0; j--) if (dst[j] == '/') { dst[++j] = 0; break; } - return j; +#endif +} + +int plat_get_skin_dir(char *dst, int len) +{ + int ret = plat_get_data_dir(dst, len); + if (ret < 0) + return ret; + + memcpy(dst + ret, "skin/", sizeof "skin/"); + return ret + sizeof("skin/") - 1; +} + +#ifndef PICO_HOME_DIR +#define PICO_HOME_DIR "/.picodrive/" +#endif +int plat_get_root_dir(char *dst, int len) +{ +#if defined(__GP2X__) || defined(PANDORA) + return plat_get_data_dir(dst, len); +#else + char *home = getenv("HOME"); + size_t nb = strlen(home); + + memcpy(dst, home, nb); + memcpy(dst + nb, PICO_HOME_DIR, sizeof PICO_HOME_DIR); + mkdir(dst, 0755); + return nb + sizeof(PICO_HOME_DIR) - 1; +#endif } #ifdef __GP2X__ diff --git a/menu.c b/menu.c index 2e97f06..470ca3d 100644 --- a/menu.c +++ b/menu.c @@ -239,7 +239,7 @@ static char tolower_simple(char c) void menu_init_base(void) { - int i, c, l; + int i, c, l, pos; unsigned char *fd, *fds; char buff[256]; FILE *f; @@ -294,17 +294,18 @@ void menu_init_base(void) } // load custom font and selector (stored as 1st symbol in font table) - emu_make_path(buff, "skin/font.png", sizeof(buff)); + pos = plat_get_skin_dir(buff, sizeof(buff)); + strcpy(buff + pos, "font.png"); readpng(menu_font_data, buff, READPNG_FONT, MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160); // default selector symbol is '>' memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2, me_mfont_w * me_mfont_h / 2); - emu_make_path(buff, "skin/selector.png", sizeof(buff)); + strcpy(buff + pos, "selector.png"); readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h); // load custom colors - emu_make_path(buff, "skin/skin.txt", sizeof(buff)); + strcpy(buff + pos, "skin.txt"); f = fopen(buff, "r"); if (f != NULL) { diff --git a/plat.h b/plat.h index ad26595..d48a541 100644 --- a/plat.h +++ b/plat.h @@ -104,6 +104,9 @@ void plat_video_wait_vsync(void); /* return the dir/ where configs, saves, bios, etc. are found */ int plat_get_root_dir(char *dst, int len); +/* return the dir/ where skin files are found */ +int plat_get_skin_dir(char *dst, int len); + int plat_is_dir(const char *path); int plat_wait_event(int *fds_hnds, int count, int timeout_ms); void plat_sleep_ms(int ms); -- 2.39.5