diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 734e7a573b..2faed5f1c7 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -214,6 +214,26 @@ const char *path_get_extension(const char *path) return ""; } +/** + * path_get_extension_mutable: + * @path : path + * + * Specialized version of path_get_extension(). Return + * value is mutable. + * + * Gets extension of file. Only '.'s + * after the last slash are considered. + * + * @return extension part from the path. + **/ +char *path_get_extension_mutable(const char *path) +{ + char *ext = NULL; + if (!string_is_empty(path) && ((ext = strrchr(path_basename(path), '.')))) + return ext; + return NULL; +} + /** * path_remove_extension: * @path : path diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index cbc89a8abd..5a81aa2365 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -126,6 +126,20 @@ const char *path_get_archive_delim(const char *path); **/ const char *path_get_extension(const char *path); +/** + * path_get_extension_mutable: + * @path : path + * + * Specialized version of path_get_extension(). Return + * value is mutable. + * + * Gets extension of file. Only '.'s + * after the last slash are considered. + * + * @return extension part from the path. + **/ +char *path_get_extension_mutable(const char *path); + /** * path_remove_extension: * @path : path diff --git a/menu/menu_explore.c b/menu/menu_explore.c index 613df2d187..ca84024956 100644 --- a/menu/menu_explore.c +++ b/menu/menu_explore.c @@ -522,8 +522,9 @@ explore_state_t *menu_explore_build_list(const char *directory_playlist, rdb_num = RHMAP_GET(rdb_indices, rdb_hash); if (!rdb_num) { - struct explore_rdb newrdb; size_t systemname_len; + struct explore_rdb newrdb; + char *ext_path = NULL; newrdb.handle = libretrodb_new(); newrdb.count = 0; @@ -538,8 +539,18 @@ explore_state_t *menu_explore_build_list(const char *directory_playlist, fill_pathname_join_special( tmp, directory_database, db_name, sizeof(tmp)); - path_remove_extension(tmp); - strlcat(tmp, ".rdb", sizeof(tmp)); + + /* Replace the extension - change 'lpl' to 'rdb' */ + if (( ext_path = path_get_extension_mutable(tmp)) + && ext_path[0] == '.' + && ext_path[1] == 'l' + && ext_path[2] == 'p' + && ext_path[3] == 'l') + { + ext_path[1] = 'r'; + ext_path[2] = 'd'; + ext_path[3] = 'b'; + } if (libretrodb_open(tmp, newrdb.handle) != 0) {