mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 06:47:45 -04:00
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.
This commit is contained in:
parent
39014486f9
commit
c52e6628cd
3 changed files with 45 additions and 10 deletions
43
linux/plat.c
43
linux/plat.c
|
@ -19,6 +19,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "../plat.h"
|
#include "../plat.h"
|
||||||
|
|
||||||
|
@ -40,24 +41,54 @@ int plat_is_dir(const char *path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_get_root_dir(char *dst, int len)
|
static int plat_get_data_dir(char *dst, int len)
|
||||||
{
|
{
|
||||||
int j, ret;
|
#ifdef PICO_DATA_DIR
|
||||||
|
memcpy(dst, PICO_DATA_DIR, sizeof PICO_DATA_DIR);
|
||||||
ret = readlink("/proc/self/exe", dst, len - 1);
|
return sizeof(PICO_DATA_DIR) - 1;
|
||||||
|
#else
|
||||||
|
int j, ret = readlink("/proc/self/exe", dst, len - 1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
perror("readlink");
|
perror("readlink");
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
dst[ret] = 0;
|
dst[ret] = 0;
|
||||||
|
|
||||||
for (j = strlen(dst); j > 0; j--)
|
for (j = ret - 1; j > 0; j--)
|
||||||
if (dst[j] == '/') {
|
if (dst[j] == '/') {
|
||||||
dst[++j] = 0;
|
dst[++j] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return j;
|
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__
|
#ifdef __GP2X__
|
||||||
|
|
9
menu.c
9
menu.c
|
@ -239,7 +239,7 @@ static char tolower_simple(char c)
|
||||||
|
|
||||||
void menu_init_base(void)
|
void menu_init_base(void)
|
||||||
{
|
{
|
||||||
int i, c, l;
|
int i, c, l, pos;
|
||||||
unsigned char *fd, *fds;
|
unsigned char *fd, *fds;
|
||||||
char buff[256];
|
char buff[256];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -294,17 +294,18 @@ void menu_init_base(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// load custom font and selector (stored as 1st symbol in font table)
|
// 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,
|
readpng(menu_font_data, buff, READPNG_FONT,
|
||||||
MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160);
|
MENU_X2 ? 256 : 128, MENU_X2 ? 320 : 160);
|
||||||
// default selector symbol is '>'
|
// default selector symbol is '>'
|
||||||
memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,
|
memcpy(menu_font_data, menu_font_data + ((int)'>') * me_mfont_w * me_mfont_h / 2,
|
||||||
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);
|
readpng(menu_font_data, buff, READPNG_SELECTOR, me_mfont_w, me_mfont_h);
|
||||||
|
|
||||||
// load custom colors
|
// load custom colors
|
||||||
emu_make_path(buff, "skin/skin.txt", sizeof(buff));
|
strcpy(buff + pos, "skin.txt");
|
||||||
f = fopen(buff, "r");
|
f = fopen(buff, "r");
|
||||||
if (f != NULL)
|
if (f != NULL)
|
||||||
{
|
{
|
||||||
|
|
3
plat.h
3
plat.h
|
@ -104,6 +104,9 @@ void plat_video_wait_vsync(void);
|
||||||
/* return the dir/ where configs, saves, bios, etc. are found */
|
/* return the dir/ where configs, saves, bios, etc. are found */
|
||||||
int plat_get_root_dir(char *dst, int len);
|
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_is_dir(const char *path);
|
||||||
int plat_wait_event(int *fds_hnds, int count, int timeout_ms);
|
int plat_wait_event(int *fds_hnds, int count, int timeout_ms);
|
||||||
void plat_sleep_ms(int ms);
|
void plat_sleep_ms(int ms);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue