mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-15 23:06:40 +00:00
Added function to check whether path contains a compressed file
This commit is contained in:
parent
5ad5a1b6a9
commit
502475f6c7
46
file_path.c
46
file_path.c
@ -86,13 +86,13 @@ long read_compressed_file(const char * archive_path, const char *relative_path,
|
|||||||
{
|
{
|
||||||
const char* file_ext = path_get_extension(archive_path);
|
const char* file_ext = path_get_extension(archive_path);
|
||||||
#ifdef HAVE_7ZIP
|
#ifdef HAVE_7ZIP
|
||||||
if (strcmp(file_ext,"7z") == 0)
|
if (strcasecmp(file_ext,"7z") == 0)
|
||||||
{
|
{
|
||||||
return read_7zip_file(archive_path,relative_path,buf);
|
return read_7zip_file(archive_path,relative_path,buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
if (strcmp(file_ext,"zip") == 0)
|
if (strcasecmp(file_ext,"zip") == 0)
|
||||||
{
|
{
|
||||||
return read_zip_file(archive_path,relative_path,buf);
|
return read_zip_file(archive_path,relative_path,buf);
|
||||||
}
|
}
|
||||||
@ -395,13 +395,13 @@ struct string_list *compressed_file_list_new(const char *path,
|
|||||||
#ifdef HAVE_COMPRESSION
|
#ifdef HAVE_COMPRESSION
|
||||||
const char* file_ext = path_get_extension(path);
|
const char* file_ext = path_get_extension(path);
|
||||||
#ifdef HAVE_7ZIP
|
#ifdef HAVE_7ZIP
|
||||||
if (strcmp(file_ext,"7z") == 0)
|
if (strcasecmp(file_ext,"7z") == 0)
|
||||||
{
|
{
|
||||||
return compressed_7zip_file_list_new(path,ext);
|
return compressed_7zip_file_list_new(path,ext);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_ZLIB
|
#ifdef HAVE_ZLIB
|
||||||
if (strcmp(file_ext,"zip") == 0)
|
if (strcasecmp(file_ext,"zip") == 0)
|
||||||
{
|
{
|
||||||
return compressed_zip_file_list_new(path,ext);
|
return compressed_zip_file_list_new(path,ext);
|
||||||
}
|
}
|
||||||
@ -622,6 +622,15 @@ static const char *path_default_slash(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool path_contains_compressed_file(const char *path)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Currently we only check for hash symbol inside the pathname.
|
||||||
|
* If path is ever expanded to a general URI, we should check for that here.
|
||||||
|
*/
|
||||||
|
return (strchr(path,'#') != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
bool path_is_compressed_file(const char* path)
|
bool path_is_compressed_file(const char* path)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_COMPRESSION
|
#ifdef HAVE_COMPRESSION
|
||||||
@ -957,6 +966,35 @@ void fill_pathname_expand_special(char *out_path,
|
|||||||
rarch_assert(strlcpy(out_path, in_path, size) < size);
|
rarch_assert(strlcpy(out_path, in_path, size) < size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fill_short_pathname_representation(char* out_rep,
|
||||||
|
const char *in_path, size_t size)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
char path_short[PATH_MAX];
|
||||||
|
fill_pathname(path_short, path_basename(in_path), "",
|
||||||
|
sizeof(path_short));
|
||||||
|
|
||||||
|
char* last_hash = strchr(path_short,'#');
|
||||||
|
/* We handle paths like:
|
||||||
|
* /path/to/file.7z#mygame.img
|
||||||
|
* short_name: mygame.img:
|
||||||
|
*/
|
||||||
|
if(last_hash != NULL)
|
||||||
|
{
|
||||||
|
/* We check whether something is actually after the hash to avoid
|
||||||
|
* going over the buffer.
|
||||||
|
*/
|
||||||
|
rarch_assert(strlen(last_hash) > 1);
|
||||||
|
strlcpy(out_rep,last_hash + 1, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strlcpy(out_rep,path_short, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void fill_pathname_abbreviate_special(char *out_path,
|
void fill_pathname_abbreviate_special(char *out_path,
|
||||||
const char *in_path, size_t size)
|
const char *in_path, size_t size)
|
||||||
{
|
{
|
||||||
|
16
file_path.h
16
file_path.h
@ -88,6 +88,11 @@ void string_list_set(struct string_list *list, unsigned index,
|
|||||||
|
|
||||||
/* path_is_compressed_file also means: The compressed file is supported */
|
/* path_is_compressed_file also means: The compressed file is supported */
|
||||||
bool path_is_compressed_file(const char *path);
|
bool path_is_compressed_file(const char *path);
|
||||||
|
|
||||||
|
/* Somewhere in the path there might be a compressed file
|
||||||
|
* E.g.: /path/to/file.7z#mygame.img
|
||||||
|
*/
|
||||||
|
bool path_contains_compressed_file(const char *path);
|
||||||
bool path_is_directory(const char *path);
|
bool path_is_directory(const char *path);
|
||||||
bool path_file_exists(const char *path);
|
bool path_file_exists(const char *path);
|
||||||
|
|
||||||
@ -188,6 +193,17 @@ void fill_pathname_resolve_relative(char *out_path, const char *in_refpath,
|
|||||||
void fill_pathname_join(char *out_path, const char *dir,
|
void fill_pathname_join(char *out_path, const char *dir,
|
||||||
const char *path, size_t size);
|
const char *path, size_t size);
|
||||||
|
|
||||||
|
/* Generates a short representation of path. It should only
|
||||||
|
* be used for displaying the result; the output representation is not
|
||||||
|
* binding in any meaningful way (for a normal path, this is the same as basename)
|
||||||
|
* In case of more complex URLs, this should cut everything except for
|
||||||
|
* the main image file.
|
||||||
|
* E.g.: "/path/to/game.img" -> game.img
|
||||||
|
* "/path/to/myarchive.7z#folder/to/game.img" -> game.img
|
||||||
|
*/
|
||||||
|
void fill_short_pathname_representation(char* out_rep,
|
||||||
|
const char *in_path, size_t size);
|
||||||
|
|
||||||
void fill_pathname_expand_special(char *out_path,
|
void fill_pathname_expand_special(char *out_path,
|
||||||
const char *in_path, size_t size);
|
const char *in_path, size_t size);
|
||||||
void fill_pathname_abbreviate_special(char *out_path,
|
void fill_pathname_abbreviate_special(char *out_path,
|
||||||
|
Loading…
Reference in New Issue
Block a user