mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
read_compressed_file - use string_list
This commit is contained in:
parent
f4b22f9fdd
commit
0b74956abe
33
file_ops.c
33
file_ops.c
@ -494,9 +494,9 @@ error:
|
|||||||
int read_compressed_file(const char * path, void **buf,
|
int read_compressed_file(const char * path, void **buf,
|
||||||
const char* optional_filename, ssize_t *length)
|
const char* optional_filename, ssize_t *length)
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
const char* file_ext = NULL;
|
const char* file_ext = NULL;
|
||||||
char *archive_found = NULL;
|
struct string_list *str_list = string_split(path, "#");
|
||||||
char archive_path[PATH_MAX_LENGTH] = {0};
|
|
||||||
|
|
||||||
if (optional_filename)
|
if (optional_filename)
|
||||||
{
|
{
|
||||||
@ -512,50 +512,43 @@ int read_compressed_file(const char * path, void **buf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We split carchive path and relative path: */
|
|
||||||
strlcpy(archive_path, path, sizeof(archive_path));
|
|
||||||
|
|
||||||
archive_found = (char*)strchr(archive_path,'#');
|
|
||||||
retro_assert(archive_found != NULL);
|
|
||||||
|
|
||||||
/* We assure that there is something after the '#' symbol. */
|
/* We assure that there is something after the '#' symbol. */
|
||||||
if (strlen(archive_found) <= 1)
|
if (str_list->size <= 1)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This error condition happens for example, when
|
* This error condition happens for example, when
|
||||||
* path = /path/to/file.7z, or
|
* path = /path/to/file.7z, or
|
||||||
* path = /path/to/file.7z#
|
* path = /path/to/file.7z#
|
||||||
*/
|
*/
|
||||||
RARCH_ERR("Could not extract image path and carchive path from "
|
RARCH_ERR("Could not extract string and substring from "
|
||||||
"path: %s.\n", path);
|
": %s.\n", path);
|
||||||
*length = 0;
|
*length = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We split the string in two, by putting a \0, where the hash was: */
|
|
||||||
*archive_found = '\0';
|
|
||||||
archive_found += 1;
|
|
||||||
#if defined(HAVE_7ZIP) || defined(HAVE_ZLIB)
|
#if defined(HAVE_7ZIP) || defined(HAVE_ZLIB)
|
||||||
file_ext = path_get_extension(archive_path);
|
file_ext = path_get_extension(str_list->elems[0].data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_7ZIP
|
#ifdef HAVE_7ZIP
|
||||||
if (string_is_equal_noncase(file_ext, "7z"))
|
if (string_is_equal_noncase(file_ext, "7z"))
|
||||||
{
|
{
|
||||||
*length = read_7zip_file(archive_path,archive_found,buf,optional_filename);
|
*length = read_7zip_file(str_list->elems[0].data, str_list->elems[1].data, buf, optional_filename);
|
||||||
if (*length != -1)
|
if (*length != -1)
|
||||||
return 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
if (string_is_equal_noncase(file_ext, "zip"))
|
if (string_is_equal_noncase(file_ext, "zip"))
|
||||||
{
|
{
|
||||||
*length = read_zip_file(archive_path,archive_found,buf,optional_filename);
|
*length = read_zip_file(str_list->elems[0].data, str_list->elems[1].data, buf, optional_filename);
|
||||||
if (*length != -1)
|
if (*length != -1)
|
||||||
return 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string_list_free(str_list);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user