diff --git a/disk_index_file.c b/disk_index_file.c index c35c8739bc2..67b359a34e2 100644 --- a/disk_index_file.c +++ b/disk_index_file.c @@ -226,12 +226,9 @@ bool disk_index_file_init( /* > Get disk index file directory */ if (!string_is_empty(dir_savefile)) strlcpy(disk_index_file_dir, dir_savefile, sizeof(disk_index_file_dir)); - else - { - /* Use content directory */ - strlcpy(disk_index_file_dir, content_path, sizeof(disk_index_file_dir)); - path_basedir(disk_index_file_dir); - } + else /* Use content directory */ + fill_pathname_basedir(disk_index_file_dir, content_path, + sizeof(disk_index_file_dir)); /* > Create directory, if required */ if ( !path_is_directory(disk_index_file_dir) diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 2861d0e2ab6..043b3905a2e 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -86,24 +86,6 @@ struct wildcard_token char token_name[24]; }; -static struct wildcard_token wildcard_tokens[SHADER_NUM_WILDCARDS] = { - {RARCH_WILDCARD_CONTENT_DIR, "$CONTENT-DIR$"}, - {RARCH_WILDCARD_CORE, "$CORE$"}, - {RARCH_WILDCARD_GAME, "$GAME$"}, - {RARCH_WILDCARD_VIDEO_DRIVER, "$VID-DRV$"}, - {RARCH_WILDCARD_VIDEO_DRIVER_PRESET_EXT, "$VID-DRV-PRESET-EXT$"}, - {RARCH_WILDCARD_VIDEO_DRIVER_SHADER_EXT, "$VID-DRV-SHADER-EXT$"}, - {RARCH_WILDCARD_CORE_REQUESTED_ROTATION, "$CORE-REQ-ROT$"}, - {RARCH_WILDCARD_VIDEO_ALLOW_CORE_ROTATION, "$VID-ALLOW-CORE-ROT$"}, - {RARCH_WILDCARD_VIDEO_USER_ROTATION, "$VID-USER-ROT$"}, - {RARCH_WILDCARD_VIDEO_FINAL_ROTATION, "$VID-FINAL-ROT$"}, - {RARCH_WILDCARD_SCREEN_ORIENTATION, "$SCREEN-ORIENT$"}, - {RARCH_WILDCARD_VIEWPORT_ASPECT_ORIENTATION, "$VIEW-ASPECT-ORIENT$"}, - {RARCH_WILDCARD_CORE_ASPECT_ORIENTATION, "$CORE-ASPECT-ORIENT$"}, - {RARCH_WILDCARD_PRESET_DIR, "$PRESET-DIR$"}, - {RARCH_WILDCARD_PRESET, "$PRESET$"}, -}; - /* TODO/FIXME - global state - perhaps move outside this file */ static path_change_data_t *file_change_data = NULL; @@ -231,6 +213,23 @@ static void video_shader_replace_wildcards(char *s, size_t len, char *in_preset_ { int i = 0; char replaced_path[PATH_MAX_LENGTH]; + static struct wildcard_token wildcard_tokens[SHADER_NUM_WILDCARDS] = { + {RARCH_WILDCARD_CONTENT_DIR, "$CONTENT-DIR$"}, + {RARCH_WILDCARD_CORE, "$CORE$"}, + {RARCH_WILDCARD_GAME, "$GAME$"}, + {RARCH_WILDCARD_VIDEO_DRIVER, "$VID-DRV$"}, + {RARCH_WILDCARD_VIDEO_DRIVER_PRESET_EXT, "$VID-DRV-PRESET-EXT$"}, + {RARCH_WILDCARD_VIDEO_DRIVER_SHADER_EXT, "$VID-DRV-SHADER-EXT$"}, + {RARCH_WILDCARD_CORE_REQUESTED_ROTATION, "$CORE-REQ-ROT$"}, + {RARCH_WILDCARD_VIDEO_ALLOW_CORE_ROTATION, "$VID-ALLOW-CORE-ROT$"}, + {RARCH_WILDCARD_VIDEO_USER_ROTATION, "$VID-USER-ROT$"}, + {RARCH_WILDCARD_VIDEO_FINAL_ROTATION, "$VID-FINAL-ROT$"}, + {RARCH_WILDCARD_SCREEN_ORIENTATION, "$SCREEN-ORIENT$"}, + {RARCH_WILDCARD_VIEWPORT_ASPECT_ORIENTATION, "$VIEW-ASPECT-ORIENT$"}, + {RARCH_WILDCARD_CORE_ASPECT_ORIENTATION, "$CORE-ASPECT-ORIENT$"}, + {RARCH_WILDCARD_PRESET_DIR, "$PRESET-DIR$"}, + {RARCH_WILDCARD_PRESET, "$PRESET$"}, + }; if (!strstr(s, RARCH_WILDCARD_DELIMITER)) return; diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 5a968326be4..897d97c619d 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -597,21 +597,18 @@ size_t path_basedir(char *s) char *last_slash = NULL; if (!s || s[0] == '\0' || s[1] == '\0') return (s && s[0] != '\0') ? 1 : 0; - slash = strrchr(s, '/'); - backslash = strrchr(s, '\\'); - last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; + slash = strrchr(s, '/'); + backslash = strrchr(s, '\\'); + last_slash = (!slash || (backslash > slash)) ? (char*)backslash : (char*)slash; if (last_slash) { - last_slash[1] = '\0'; + last_slash[1] = '\0'; return last_slash + 1 - s; } - else - { - s[0] = '.'; - s[1] = PATH_DEFAULT_SLASH_C(); - s[2] = '\0'; - return 2; - } + s[0] = '.'; + s[1] = PATH_DEFAULT_SLASH_C(); + s[2] = '\0'; + return 2; } /** @@ -1446,13 +1443,13 @@ size_t fill_pathname_application_path(char *s, size_t len) return 0; } -void fill_pathname_application_dir(char *s, size_t len) +size_t fill_pathname_application_dir(char *s, size_t len) { #ifdef __WINRT__ - strlcpy(s, uwp_dir_install, len); + return strlcpy(s, uwp_dir_install, len); #else fill_pathname_application_path(s, len); - path_basedir(s); + return path_basedir(s); #endif } diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index ba1782ecf8c..bdaeef3f567 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -636,7 +636,7 @@ size_t fill_pathname_slash(char *path, size_t size); #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) size_t fill_pathname_application_path(char *buf, size_t size); -void fill_pathname_application_dir(char *buf, size_t size); +size_t fill_pathname_application_dir(char *buf, size_t size); size_t fill_pathname_home_dir(char *buf, size_t size); #endif diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index ab9a963b457..512140d664d 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1377,10 +1377,12 @@ int generic_action_ok_displaylist_push( { filebrowser_clear_type(); if (content_get_subsystem_rom_id() > 0) - strlcpy(tmp, content_get_subsystem_rom(content_get_subsystem_rom_id() - 1), sizeof(tmp)); + fill_pathname_basedir(tmp, + content_get_subsystem_rom(content_get_subsystem_rom_id() - 1), + sizeof(tmp)); else - strlcpy(tmp, path_get(RARCH_PATH_CONTENT), sizeof(tmp)); - path_basedir(tmp); + fill_pathname_basedir(tmp, + path_get(RARCH_PATH_CONTENT), sizeof(tmp)); if (content_get_subsystem() != (int)type - MENU_SETTINGS_SUBSYSTEM_ADD) content_clear_subsystem(); diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index f308eb3759e..ccf102220ce 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -500,9 +500,9 @@ static int filebrowser_parse( if (str_list->size <= 0) { char dir[DIR_MAX_LENGTH]; - fill_pathname_application_dir(dir, sizeof(dir)); + size_t _len = fill_pathname_application_dir(dir, sizeof(dir)); if (string_ends_with(full_path, "/") && !string_ends_with(dir, "/")) - strlcat(dir, "/", sizeof(dir)); + strlcpy(dir + _len, "/", sizeof(dir) - _len); if (string_is_equal(dir, full_path)) allow_parent_directory = false; else @@ -5139,13 +5139,21 @@ static unsigned menu_displaylist_parse_content_information( if ( !string_is_empty(content_label) && !string_is_empty(db_name)) { + char *last; char db_path[PATH_MAX_LENGTH]; fill_pathname_join_special(db_path, settings->paths.path_content_database, db_name, sizeof(db_path)); - path_remove_extension(db_path); - strlcat(db_path, ".rdb", sizeof(db_path)); + last = (char*)strrchr(path_basename(db_path), '.'); + if (*last) + { + last[0] = '.'; + last[1] = 'r'; + last[2] = 'd'; + last[3] = 'b'; + last[4] = '\0'; + } if (path_is_valid(db_path)) if (menu_entries_append(info_list, diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 43756410725..254bc73bbea 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -2985,16 +2985,12 @@ static bool menu_shader_manager_save_preset_internal( fill_pathname_join(buffer, target_dirs[i], fullname, sizeof(buffer)); - strlcpy(basedir, buffer, sizeof(basedir)); - path_basedir(basedir); + fill_pathname_basedir(basedir, buffer, sizeof(basedir)); - if (!path_is_directory(basedir)) + if (!path_is_directory(basedir) && !(ret = path_mkdir(basedir))) { - if (!(ret = path_mkdir(basedir))) - { - RARCH_WARN("[Shaders]: Failed to create preset directory \"%s\".\n", basedir); - continue; - } + RARCH_WARN("[Shaders]: Failed to create preset directory \"%s\".\n", basedir); + continue; } preset_path = buffer; diff --git a/runloop.c b/runloop.c index a8079f9fe3b..68715735bdf 100644 --- a/runloop.c +++ b/runloop.c @@ -7928,10 +7928,10 @@ void runloop_path_set_redirect(settings_t *settings, if ( string_is_empty(intermediate_savefile_dir) || savefiles_in_content_dir) { - strlcpy(intermediate_savefile_dir, - runloop_st->runtime_content_path_basename, - sizeof(intermediate_savefile_dir)); - path_basedir(intermediate_savefile_dir); + fill_pathname_basedir( + intermediate_savefile_dir, + runloop_st->runtime_content_path_basename, + sizeof(intermediate_savefile_dir)); if (string_is_empty(intermediate_savefile_dir)) RARCH_LOG("Cannot resolve save file path.\n"); @@ -7941,10 +7941,9 @@ void runloop_path_set_redirect(settings_t *settings, if ( string_is_empty(intermediate_savestate_dir) || savestates_in_content_dir) { - strlcpy(intermediate_savestate_dir, - runloop_st->runtime_content_path_basename, - sizeof(intermediate_savestate_dir)); - path_basedir(intermediate_savestate_dir); + fill_pathname_basedir(intermediate_savestate_dir, + runloop_st->runtime_content_path_basename, + sizeof(intermediate_savestate_dir)); if (string_is_empty(intermediate_savestate_dir)) RARCH_LOG("Cannot resolve save state file path.\n"); diff --git a/tasks/task_content.c b/tasks/task_content.c index 448cb165f1d..ef7ff7f29e8 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -556,6 +556,9 @@ static bool content_file_list_set_info( { char archive_path[PATH_MAX_LENGTH]; size_t _len = 0; + + file_info->file_in_archive = true; + /* Extract path of parent archive */ if ((_len = (size_t)(1 + archive_delim - path)) >= PATH_MAX_LENGTH) @@ -582,9 +585,6 @@ static bool content_file_list_set_info( * this is the basename of the archive file without * extension */ fill_pathname_base(name, archive_path, sizeof(name)); - path_remove_extension(name); - - file_info->file_in_archive = true; } else { @@ -596,8 +596,8 @@ static bool content_file_list_set_info( * is the basename of the content file, without * extension */ fill_pathname_base(name, path, sizeof(name)); - path_remove_extension(name); } + path_remove_extension(name); if (!string_is_empty(dir)) { diff --git a/tasks/task_translation.c b/tasks/task_translation.c index 414d5290222..94680b97637 100644 --- a/tasks/task_translation.c +++ b/tasks/task_translation.c @@ -780,7 +780,6 @@ static const char *ai_service_get_str(enum translation_lang id) bool run_translation_service(settings_t *settings, bool paused) { struct video_viewport vp; - uint8_t header[54]; size_t pitch; unsigned width, height; const void *data = NULL; @@ -947,11 +946,10 @@ bool run_translation_service(settings_t *settings, bool paused) the BMP header as bytes, and then covert that to a b64 encoded array for transport in JSON. */ - form_bmp_header(header, width, height, false); if (!(bmp_buffer = (uint8_t*)malloc(width * height * 3 + 54))) goto finish; - memcpy(bmp_buffer, header, 54 * sizeof(uint8_t)); + form_bmp_header(bmp_buffer, width, height, false); memcpy(bmp_buffer + 54, bit24_image, width * height * 3 * sizeof(uint8_t));