(menu_explore) Simplification of explore_load_icons

fill_pathname_application_special - return size_t
This commit is contained in:
LibretroAdmin 2024-12-30 10:07:58 +01:00
parent 28f6ee9c26
commit 8ebedcb6bd
5 changed files with 29 additions and 28 deletions

View File

@ -189,9 +189,10 @@ bool fill_pathname_application_data(char *s, size_t len)
const char* xmb_theme_ident(void); const char* xmb_theme_ident(void);
#endif #endif
void fill_pathname_application_special(char *s, size_t fill_pathname_application_special(char *s,
size_t len, enum application_special_type type) size_t len, enum application_special_type type)
{ {
size_t _len = 0;
switch (type) switch (type)
{ {
case APPLICATION_SPECIAL_DIRECTORY_CONFIG: case APPLICATION_SPECIAL_DIRECTORY_CONFIG:
@ -202,9 +203,9 @@ void fill_pathname_application_special(char *s,
/* Try config directory setting first, /* Try config directory setting first,
* fallback to the location of the current configuration file. */ * fallback to the location of the current configuration file. */
if (!string_is_empty(dir_menu_config)) if (!string_is_empty(dir_menu_config))
strlcpy(s, dir_menu_config, len); _len = strlcpy(s, dir_menu_config, len);
else if (!path_is_empty(RARCH_PATH_CONFIG)) else if (!path_is_empty(RARCH_PATH_CONFIG))
fill_pathname_basedir(s, path_get(RARCH_PATH_CONFIG), len); _len = fill_pathname_basedir(s, path_get(RARCH_PATH_CONFIG), len);
} }
break; break;
case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS: case APPLICATION_SPECIAL_DIRECTORY_ASSETS_XMB_ICONS:
@ -216,7 +217,7 @@ void fill_pathname_application_special(char *s,
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir));
fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path)); fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path));
fill_pathname_join_special(s, tmp_path, "png", len); _len = fill_pathname_join_special(s, tmp_path, "png", len);
} }
#endif #endif
break; break;
@ -227,7 +228,7 @@ void fill_pathname_application_special(char *s,
const char *path_menu_wallpaper = settings->paths.path_menu_wallpaper; const char *path_menu_wallpaper = settings->paths.path_menu_wallpaper;
if (!string_is_empty(path_menu_wallpaper)) if (!string_is_empty(path_menu_wallpaper))
strlcpy(s, path_menu_wallpaper, len); _len = strlcpy(s, path_menu_wallpaper, len);
else else
{ {
char tmp_dir[DIR_MAX_LENGTH]; char tmp_dir[DIR_MAX_LENGTH];
@ -237,7 +238,7 @@ void fill_pathname_application_special(char *s,
fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir));
fill_pathname_join_special(tmp_dir2, tmp_dir, xmb_theme_ident(), sizeof(tmp_dir2)); fill_pathname_join_special(tmp_dir2, tmp_dir, xmb_theme_ident(), sizeof(tmp_dir2));
fill_pathname_join_special(tmp_path, tmp_dir2, "png", sizeof(tmp_path)); fill_pathname_join_special(tmp_path, tmp_dir2, "png", sizeof(tmp_path));
fill_pathname_join_special(s, tmp_path, FILE_PATH_BACKGROUND_IMAGE, len); _len = fill_pathname_join_special(s, tmp_path, FILE_PATH_BACKGROUND_IMAGE, len);
} }
} }
#endif #endif
@ -258,7 +259,7 @@ void fill_pathname_application_special(char *s,
char tmp_path[PATH_MAX_LENGTH]; char tmp_path[PATH_MAX_LENGTH];
fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir));
fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path)); fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path));
fill_pathname_join_special(s, tmp_path, "sounds", len); _len = fill_pathname_join_special(s, tmp_path, "sounds", len);
} }
else else
#endif #endif
@ -268,12 +269,12 @@ void fill_pathname_application_special(char *s,
{ {
char tmp_dir[DIR_MAX_LENGTH]; char tmp_dir[DIR_MAX_LENGTH];
fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "sounds", len); _len = fill_pathname_join_special(s, tmp_dir, "sounds", len);
} }
else else
#endif #endif
{ {
fill_pathname_join_special( _len = fill_pathname_join_special(
s, dir_assets, "sounds", len); s, dir_assets, "sounds", len);
} }
#endif #endif
@ -296,7 +297,7 @@ void fill_pathname_application_special(char *s,
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, menu_ident, sizeof(tmp_dir));
fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path)); fill_pathname_join_special(tmp_path, tmp_dir, xmb_theme_ident(), sizeof(tmp_path));
fill_pathname_join_special(s, tmp_path, "png", len); _len = fill_pathname_join_special(s, tmp_path, "png", len);
} }
else else
#endif #endif
@ -317,7 +318,7 @@ void fill_pathname_application_special(char *s,
fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir));
fill_pathname_join_special(tmp_path, "monochrome", "png", sizeof(tmp_path)); fill_pathname_join_special(tmp_path, "monochrome", "png", sizeof(tmp_path));
#endif #endif
fill_pathname_join_special(s, tmp_dir, tmp_path, len); _len = fill_pathname_join_special(s, tmp_dir, tmp_path, len);
} }
else else
#endif #endif
@ -342,7 +343,7 @@ void fill_pathname_application_special(char *s,
fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir));
fill_pathname_join_special(tmp_path, "monochrome", "png", sizeof(tmp_path)); fill_pathname_join_special(tmp_path, "monochrome", "png", sizeof(tmp_path));
#endif #endif
fill_pathname_join_special(s, tmp_dir, tmp_path, len); _len = fill_pathname_join_special(s, tmp_dir, tmp_path, len);
} }
#endif #endif
break; break;
@ -354,7 +355,7 @@ void fill_pathname_application_special(char *s,
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
fill_pathname_join_special(tmp_dir, dir_assets, "rgui", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, "rgui", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "font", len); _len = fill_pathname_join_special(s, tmp_dir, "font", len);
} }
#endif #endif
break; break;
@ -366,7 +367,7 @@ void fill_pathname_application_special(char *s,
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_assets, "xmb", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, xmb_theme_ident(), len); _len = fill_pathname_join_special(s, tmp_dir, xmb_theme_ident(), len);
} }
#endif #endif
break; break;
@ -377,7 +378,7 @@ void fill_pathname_application_special(char *s,
const char *path_menu_xmb_font = settings->paths.path_menu_xmb_font; const char *path_menu_xmb_font = settings->paths.path_menu_xmb_font;
if (!string_is_empty(path_menu_xmb_font)) if (!string_is_empty(path_menu_xmb_font))
strlcpy(s, path_menu_xmb_font, len); _len = strlcpy(s, path_menu_xmb_font, len);
else else
{ {
char tmp_dir[DIR_MAX_LENGTH]; char tmp_dir[DIR_MAX_LENGTH];
@ -388,18 +389,18 @@ void fill_pathname_application_special(char *s,
case RETRO_LANGUAGE_PERSIAN: case RETRO_LANGUAGE_PERSIAN:
fill_pathname_join_special(tmp_dir, fill_pathname_join_special(tmp_dir,
settings->paths.directory_assets, "pkg", sizeof(tmp_dir)); settings->paths.directory_assets, "pkg", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "fallback-font.ttf", len); _len = fill_pathname_join_special(s, tmp_dir, "fallback-font.ttf", len);
break; break;
case RETRO_LANGUAGE_CHINESE_SIMPLIFIED: case RETRO_LANGUAGE_CHINESE_SIMPLIFIED:
case RETRO_LANGUAGE_CHINESE_TRADITIONAL: case RETRO_LANGUAGE_CHINESE_TRADITIONAL:
fill_pathname_join_special(tmp_dir, fill_pathname_join_special(tmp_dir,
settings->paths.directory_assets, "pkg", sizeof(tmp_dir)); settings->paths.directory_assets, "pkg", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "chinese-fallback-font.ttf", len); _len = fill_pathname_join_special(s, tmp_dir, "chinese-fallback-font.ttf", len);
break; break;
case RETRO_LANGUAGE_KOREAN: case RETRO_LANGUAGE_KOREAN:
fill_pathname_join_special(tmp_dir, fill_pathname_join_special(tmp_dir,
settings->paths.directory_assets, "pkg", sizeof(tmp_dir)); settings->paths.directory_assets, "pkg", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "korean-fallback-font.ttf", len); _len = fill_pathname_join_special(s, tmp_dir, "korean-fallback-font.ttf", len);
break; break;
default: default:
{ {
@ -408,7 +409,7 @@ void fill_pathname_application_special(char *s,
const char *dir_assets = settings->paths.directory_assets; const char *dir_assets = settings->paths.directory_assets;
fill_pathname_join_special(tmp_dir2, dir_assets, "xmb", sizeof(tmp_dir2)); fill_pathname_join_special(tmp_dir2, dir_assets, "xmb", sizeof(tmp_dir2));
fill_pathname_join_special(tmp_dir, tmp_dir2, xmb_theme_ident(), sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, tmp_dir2, xmb_theme_ident(), sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, FILE_PATH_TTF_FONT, len); _len = fill_pathname_join_special(s, tmp_dir, FILE_PATH_TTF_FONT, len);
} }
break; break;
} }
@ -422,7 +423,7 @@ void fill_pathname_application_special(char *s,
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_thumbnails = settings->paths.directory_thumbnails; const char *dir_thumbnails = settings->paths.directory_thumbnails;
fill_pathname_join_special(tmp_dir, dir_thumbnails, "discord", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_thumbnails, "discord", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "avatars", len); _len = fill_pathname_join_special(s, tmp_dir, "avatars", len);
} }
break; break;
@ -432,7 +433,7 @@ void fill_pathname_application_special(char *s,
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const char *dir_thumbnails = settings->paths.directory_thumbnails; const char *dir_thumbnails = settings->paths.directory_thumbnails;
fill_pathname_join_special(tmp_dir, dir_thumbnails, "cheevos", sizeof(tmp_dir)); fill_pathname_join_special(tmp_dir, dir_thumbnails, "cheevos", sizeof(tmp_dir));
fill_pathname_join_special(s, tmp_dir, "badges", len); _len = fill_pathname_join_special(s, tmp_dir, "badges", len);
} }
break; break;
@ -440,4 +441,5 @@ void fill_pathname_application_special(char *s,
default: default:
break; break;
} }
return _len;
} }

View File

@ -143,7 +143,7 @@ enum application_special_type
bool fill_pathname_application_data(char *s, size_t len); bool fill_pathname_application_data(char *s, size_t len);
void fill_pathname_application_special(char *s, size_t len, enum application_special_type type); size_t fill_pathname_application_special(char *s, size_t len, enum application_special_type type);
RETRO_END_DECLS RETRO_END_DECLS

View File

@ -1579,7 +1579,7 @@ static bool video_shader_write_referenced_preset(
* loaded presets are located * loaded presets are located
* and where Save Game Preset, Save Core Preset, * and where Save Game Preset, Save Core Preset,
* Save Global Preset save to */ * Save Global Preset save to */
fill_pathname_application_special(config_dir, DIR_MAX_LENGTH, fill_pathname_application_special(config_dir, sizeof(config_dir),
APPLICATION_SPECIAL_DIRECTORY_CONFIG); APPLICATION_SPECIAL_DIRECTORY_CONFIG);
/* If there is no initial preset path loaded */ /* If there is no initial preset path loaded */

View File

@ -426,10 +426,10 @@ static void explore_load_icons(explore_state_t *state)
{ {
struct texture_image ti; struct texture_image ti;
size_t __len = _len; size_t __len = _len;
__len += strlcpy(path + _len, __len += fill_pathname(path + _len,
state->by[EXPLORE_BY_SYSTEM][i]->str, state->by[EXPLORE_BY_SYSTEM][i]->str,
".png",
sizeof(path) - _len); sizeof(path) - _len);
strlcpy(path + __len, ".png", sizeof(path) - __len);
if (!path_is_valid(path)) if (!path_is_valid(path))
continue; continue;
@ -1680,8 +1680,7 @@ SKIP_ENTRY:;
const struct playlist_entry *pl_entry = const struct playlist_entry *pl_entry =
state->entries[current_type - EXPLORE_TYPE_FIRSTITEM].playlist_entry; state->entries[current_type - EXPLORE_TYPE_FIRSTITEM].playlist_entry;
strlcpy(state->title, strlcpy(state->title, pl_entry->label, sizeof(state->title));
pl_entry->label, sizeof(state->title));
for (pl_idx = 0; pl_idx != (int)RBUF_LEN(state->playlists); pl_idx++) for (pl_idx = 0; pl_idx != (int)RBUF_LEN(state->playlists); pl_idx++)
{ {