mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-09-21 06:30:47 +02:00
Allow recursing into directories
This commit is contained in:
parent
4c440d304e
commit
ca91cdf86c
@ -10,6 +10,10 @@
|
|||||||
TODO: Handle Run/Stop in virtual keyboard (?)
|
TODO: Handle Run/Stop in virtual keyboard (?)
|
||||||
|
|
||||||
version 10:
|
version 10:
|
||||||
|
* Added ability to recurse into directories (partly by Holger Eilts)
|
||||||
|
|
||||||
|
* Large redesign of menu layout and colors (Holger Eilts)
|
||||||
|
|
||||||
* Implemented sending text messages over the network to "taunt"
|
* Implemented sending text messages over the network to "taunt"
|
||||||
the other player (obviously a very important feature). Pressing
|
the other player (obviously a very important feature). Pressing
|
||||||
ScrLk enables this.
|
ScrLk enables this.
|
||||||
|
@ -115,8 +115,7 @@ void C64::select_disc(Prefs *np)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snprintf(np->DrivePath[0], 255, "%s/%s",
|
strncpy(np->DrivePath[0], name, 255);
|
||||||
IMAGE_PATH, name);
|
|
||||||
strncpy(this->save_game_name, name, 255);
|
strncpy(this->save_game_name, name, 255);
|
||||||
if (strstr(name, ".prg") || strstr(name, ".PRG") ||
|
if (strstr(name, ".prg") || strstr(name, ".PRG") ||
|
||||||
strstr(name, ".p00") || strstr(name, ".P00") ||
|
strstr(name, ".p00") || strstr(name, ".P00") ||
|
||||||
@ -388,7 +387,7 @@ void C64::save_load_state(Prefs *np)
|
|||||||
char save_buf[255];
|
char save_buf[255];
|
||||||
char prefs_buf[255];
|
char prefs_buf[255];
|
||||||
|
|
||||||
snprintf(save_buf, 255, "%s/%s.sav", SAVES_PATH,
|
snprintf(save_buf, 255, "%s.sav",
|
||||||
this->save_game_name);
|
this->save_game_name);
|
||||||
snprintf(prefs_buf, 255, "%s.prefs", save_buf);
|
snprintf(prefs_buf, 255, "%s.prefs", save_buf);
|
||||||
|
|
||||||
@ -405,7 +404,7 @@ void C64::save_load_state(Prefs *np)
|
|||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
snprintf(save_buf, 255, "%s/%s", SAVES_PATH, name);
|
snprintf(save_buf, 255, "%s", name);
|
||||||
snprintf(prefs_buf, 255, "%s.prefs", save_buf);
|
snprintf(prefs_buf, 255, "%s.prefs", save_buf);
|
||||||
if (opt == 2)
|
if (opt == 2)
|
||||||
{
|
{
|
||||||
|
71
Src/menu.cpp
71
Src/menu.cpp
@ -207,7 +207,15 @@ bool msgYesNo(char *text, bool default_opt, int x, int y)
|
|||||||
|
|
||||||
static int cmpstringp(const void *p1, const void *p2)
|
static int cmpstringp(const void *p1, const void *p2)
|
||||||
{
|
{
|
||||||
return strcmp(* (char * const *) p1, * (char * const *) p2);
|
const char *p1_s = *(const char**)p1;
|
||||||
|
const char *p2_s = *(const char**)p2;
|
||||||
|
|
||||||
|
/* Put directories first */
|
||||||
|
if (*p1_s == '[' && *p2_s != '[')
|
||||||
|
return -1;
|
||||||
|
if (*p1_s != '[' && *p2_s == '[')
|
||||||
|
return 1;
|
||||||
|
return strcmp(* (char * const *) p1, * (char * const *) p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return true if name ends with ext (for filenames) */
|
/* Return true if name ends with ext (for filenames) */
|
||||||
@ -254,21 +262,32 @@ static const char **get_file_list(const char *base_dir)
|
|||||||
{
|
{
|
||||||
const char *exts[] = {".d64", ".D64", ".prg", ".PRG",
|
const char *exts[] = {".d64", ".D64", ".prg", ".PRG",
|
||||||
".p00", ".P00", ".s00", ".S00",
|
".p00", ".P00", ".s00", ".S00",
|
||||||
".t64", ".T64", ".sav", ".SAV"};
|
".t64", ".T64", ".sav", ".SAV", NULL};
|
||||||
if (ext_matches_list(de->d_name, exts))
|
if (de->d_type == DT_REG && ext_matches_list(de->d_name, exts))
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
p = strdup(de->d_name);
|
p = strdup(de->d_name);
|
||||||
file_list[cur++] = p;
|
file_list[cur++] = p;
|
||||||
file_list[cur] = NULL;
|
file_list[cur] = NULL;
|
||||||
if (cur > cnt - 2)
|
}
|
||||||
{
|
else if (de->d_type == DT_DIR)
|
||||||
cnt = cnt + 32;
|
{
|
||||||
file_list = (const char**)realloc(file_list, cnt * sizeof(char*));
|
char *p;
|
||||||
if (!file_list)
|
size_t len = strlen(de->d_name) + 4;
|
||||||
return NULL;
|
|
||||||
}
|
p = (char*)malloc( len );
|
||||||
|
snprintf(p, len, "[%s]", de->d_name);
|
||||||
|
file_list[cur++] = p;
|
||||||
|
file_list[cur] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur > cnt - 2)
|
||||||
|
{
|
||||||
|
cnt = cnt + 32;
|
||||||
|
file_list = (const char**)realloc(file_list, cnt * sizeof(char*));
|
||||||
|
if (!file_list)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
@ -915,7 +934,8 @@ int menu_select_sized(char *title, SDL_Rect *rc, const char **msgs, int *submenu
|
|||||||
const char *menu_select_file(const char *dir_path)
|
const char *menu_select_file(const char *dir_path)
|
||||||
{
|
{
|
||||||
const char **file_list = get_file_list(dir_path);
|
const char **file_list = get_file_list(dir_path);
|
||||||
const char *out;
|
char *sel;
|
||||||
|
char *out;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
if (file_list == NULL)
|
if (file_list == NULL)
|
||||||
@ -925,13 +945,40 @@ const char *menu_select_file(const char *dir_path)
|
|||||||
|
|
||||||
if (opt < 0)
|
if (opt < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
out = strdup(file_list[opt]);
|
sel = strdup(file_list[opt]);
|
||||||
|
|
||||||
/* Cleanup everything - file_list is NULL-terminated */
|
/* Cleanup everything - file_list is NULL-terminated */
|
||||||
for ( int i = 0; file_list[i]; i++ )
|
for ( int i = 0; file_list[i]; i++ )
|
||||||
free((void*)file_list[i]);
|
free((void*)file_list[i]);
|
||||||
free(file_list);
|
free(file_list);
|
||||||
|
|
||||||
|
if (!sel)
|
||||||
|
return NULL;
|
||||||
|
/* If this is a folder, enter it recursively */
|
||||||
|
if (sel[0] == '[')
|
||||||
|
{
|
||||||
|
char buf[255];
|
||||||
|
int len = strlen(sel);
|
||||||
|
int s;
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
/* Remove trailing ] */
|
||||||
|
sel[len-1] = '\0';
|
||||||
|
s = snprintf(buf, 128, "%s/%s", dir_path, sel + 1);
|
||||||
|
|
||||||
|
/* We don't need this anymore */
|
||||||
|
free((void*)sel);
|
||||||
|
/* Too deep recursion! */
|
||||||
|
if (s >= sizeof(buf))
|
||||||
|
return NULL;
|
||||||
|
return menu_select_file(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
out = (char*)malloc(strlen(dir_path) + strlen(sel) + 4);
|
||||||
|
snprintf(out, strlen(dir_path) + strlen(sel) + 4,
|
||||||
|
"%s/%s", dir_path, sel);
|
||||||
|
|
||||||
|
free(sel);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user