Skip to content

Commit

Permalink
allow configuring home path
Browse files Browse the repository at this point in the history
resolves #62
  • Loading branch information
skyfloogle committed May 5, 2024
1 parent f776ce2 commit 20e88a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions include/vb_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct VB_OPT {
char *RAM_PATH;
char *ROM_NAME; // Path\Name of game to open
char *PROG_NAME; // Path\Name of program
char HOME_PATH[240];
unsigned long CRC32; // CRC32 of ROM
bool PERF_INFO;
bool VSYNC;
Expand Down
16 changes: 10 additions & 6 deletions source/common/vb_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,23 @@ char * get_savestate_path(int state, bool write) {
char *last_slash = strrchr(tVBOpt.ROM_PATH, '/');
if (last_slash == NULL) return NULL;
// maxpath measured to be around 260, but pick 300 just to be safe
const int MAX_PATH_LEN = 300;
#define MAX_PATH_LEN 300
// $HOME/savestates
char sshome[MAX_PATH_LEN - 20];
snprintf(sshome, sizeof(sshome), "%s/savestates", tVBOpt.HOME_PATH);
// $HOME/savestates/game
char *sspath = (char *) malloc(MAX_PATH_LEN * sizeof(char));
snprintf(sspath, MAX_PATH_LEN, "sdmc:/red-viper/savestates/%s", last_slash + 1);
snprintf(sspath, MAX_PATH_LEN, "%s/%s", sshome, last_slash + 1);
int sspath_len = strlen(sspath);
char *end = strrchr(sspath, '.');
if (!end) end = sspath + strlen(sspath);
if (end - sspath + 20 >= MAX_PATH_LEN) goto bail;
*end = 0;
if (stat("sdmc:/red-viper", &st) == -1) {
if (!write || mkdir("sdmc:/red-viper", 0777)) goto bail;
if (stat(tVBOpt.HOME_PATH, &st) == -1) {
if (!write || mkdir(tVBOpt.HOME_PATH, 0777)) goto bail;
}
if (stat("sdmc:/red-viper/savestates", &st) == -1) {
if (!write || mkdir("sdmc:/red-viper/savestates", 0777)) goto bail;
if (stat(sshome, &st) == -1) {
if (!write || mkdir(sshome, 0777)) goto bail;
}
if (stat(sspath, &st) == -1) {
if (!write || mkdir(sspath, 0777)) goto bail;
Expand Down
9 changes: 9 additions & 0 deletions source/common/vb_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void setDefaults(void) {
tVBOpt.VSYNC = true;
tVBOpt.N3DS_SPEEDUP = true;
tVBOpt.ANAGLYPH = false;
strcpy(tVBOpt.HOME_PATH, "sdmc:/red-viper");

// Default keys
#ifdef __3DS__
Expand Down Expand Up @@ -106,6 +107,13 @@ static int handler(void* user, const char* section, const char* name,
pconfig->ZLZR_MODE = atoi(value) % 4;
} else if (MATCH("vbopt", "n3ds_speedup")) {
pconfig->N3DS_SPEEDUP = atoi(value);
} else if (MATCH("vbopt", "homepath")) {
strncpy(pconfig->HOME_PATH, value, sizeof(pconfig->HOME_PATH));
pconfig->HOME_PATH[sizeof(pconfig->HOME_PATH)-1] = 0;
// remove trailing slash
char *last_slash = strrchr(pconfig->HOME_PATH, '/');
if (last_slash != NULL && last_slash[1] == 0)
*last_slash = 0;
} else if (MATCH("touch", "ax")) {
tVBOpt.TOUCH_AX = atoi(value);
} else if (MATCH("touch", "ay")) {
Expand Down Expand Up @@ -146,6 +154,7 @@ int saveFileOptions(void) {
fprintf(f, "abxy=%d\n", tVBOpt.ABXY_MODE);
fprintf(f, "zlzr=%d\n", tVBOpt.ZLZR_MODE);
fprintf(f, "n3ds_speedup=%d\n", tVBOpt.N3DS_SPEEDUP);
fprintf(f, "homepath=%s\n", tVBOpt.HOME_PATH);
fprintf(f, "[touch]\n");
fprintf(f, "ax=%d\n", tVBOpt.TOUCH_AX);
fprintf(f, "ay=%d\n", tVBOpt.TOUCH_AY);
Expand Down

0 comments on commit 20e88a4

Please sign in to comment.