Rework extension files to only consider basename.

Only consider last '.' in the basename of a file.
This commit is contained in:
Themaister 2013-10-06 12:16:44 +02:00
parent fa42aaf9cb
commit 34ce65d9c4
3 changed files with 12 additions and 21 deletions

View File

@ -47,31 +47,18 @@ core_info_list_t *core_info_list_new(const char *modules_path)
for (size_t i = 0; i < contents->size; i++)
{
#if 0
char buffer[PATH_MAX];
char info_path[PATH_MAX];
core_info[i].path = strdup(contents->elems[i].data);
// FIXME: Need to do something about this logic.
// fill_pathname() *should* be sufficient.
//
// NOTE: This assumes all modules are named module_name_{tag}.ext
// {tag} must not contain an underscore. (This isn't true for PC versions)
#if defined(IOS) || defined(HAVE_BB10) || defined(__QNX__)
// Libs are deployed with a suffix (*_ios.dylib, *_qnx.so, etc).
char buffer[PATH_MAX];
strlcpy(buffer, contents->elems[i].data, sizeof(buffer));
char *substr = strrchr(buffer, '_');
if (substr)
*substr = '\0';
// NOTE: Can't just use fill_pathname on iOS as it will cut at RetroArch.app;
// perhaps fill_pathname shouldn't cut before the last path element.
if (substr)
snprintf(info_path, PATH_MAX, "%s.info", buffer);
else
fill_pathname(info_path, buffer, ".info", sizeof(info_path));
fill_pathname(info_path, buffer, ".info", sizeof(info_path));
#else
core_info[i].path = strdup(contents->elems[i].data);
char info_path[PATH_MAX];
fill_pathname(info_path, core_info[i].path, ".info", sizeof(info_path));
#endif

6
file.h
View File

@ -74,11 +74,14 @@ void string_list_free(struct string_list *list);
bool path_is_directory(const char *path);
bool path_file_exists(const char *path);
// Gets extension of file. Only '.'s after the last slash are considered.
const char *path_get_extension(const char *path);
bool path_mkdir(const char *dir);
// Removes all text after and including the last '.'
// Removes all text after and including the last '.'.
// Only '.'s after the last slash are considered.
char *path_remove_extension(char *path);
// Returns basename from path.
@ -102,6 +105,7 @@ bool path_is_absolute(const char *path);
// Replaces filename extension with 'replace' and outputs result to out_path.
// The extension here is considered to be the string from the last '.' to the end.
// Only '.'s after the last slash are considered as extensions.
// If no '.' is present, in_path and replace will simply be concatenated.
// 'size' is buffer size of 'out_path'.
// E.g.: in_path = "/foo/bar/baz/boo.c", replace = ".asm" => out_path = "/foo/bar/baz/boo.asm"

View File

@ -180,7 +180,7 @@ bool string_list_find_elem_prefix(const struct string_list *list, const char *pr
const char *path_get_extension(const char *path)
{
const char *ext = strrchr(path, '.');
const char *ext = strrchr(path_basename(path), '.');
if (ext)
return ext + 1;
else
@ -189,7 +189,7 @@ const char *path_get_extension(const char *path)
char *path_remove_extension(char *path)
{
char *last = strrchr(path, '.');
char *last = strrchr(path_basename(path), '.');
if (*last)
*last = '\0';
return last;
@ -417,7 +417,7 @@ void fill_pathname(char *out_path, const char *in_path, const char *replace, siz
char tmp_path[PATH_MAX];
rarch_assert(strlcpy(tmp_path, in_path, sizeof(tmp_path)) < sizeof(tmp_path));
char *tok = strrchr(tmp_path, '.');
char *tok = strrchr(path_basename(tmp_path), '.');
if (tok)
*tok = '\0';