From 502475f6c736224cfe2775c3e4ebafc88050e7a8 Mon Sep 17 00:00:00 2001 From: Timo Strunk Date: Fri, 12 Sep 2014 17:05:05 +0200 Subject: [PATCH] Added function to check whether path contains a compressed file --- file_path.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- file_path.h | 16 ++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/file_path.c b/file_path.c index d1629fa455..a88cdb5ca8 100644 --- a/file_path.c +++ b/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); #ifdef HAVE_7ZIP - if (strcmp(file_ext,"7z") == 0) + if (strcasecmp(file_ext,"7z") == 0) { return read_7zip_file(archive_path,relative_path,buf); } #endif #ifdef HAVE_ZLIB - if (strcmp(file_ext,"zip") == 0) + if (strcasecmp(file_ext,"zip") == 0) { 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 const char* file_ext = path_get_extension(path); #ifdef HAVE_7ZIP - if (strcmp(file_ext,"7z") == 0) + if (strcasecmp(file_ext,"7z") == 0) { return compressed_7zip_file_list_new(path,ext); } #endif #ifdef HAVE_ZLIB - if (strcmp(file_ext,"zip") == 0) + if (strcasecmp(file_ext,"zip") == 0) { return compressed_zip_file_list_new(path,ext); } @@ -622,6 +622,15 @@ static const char *path_default_slash(void) #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) { #ifdef HAVE_COMPRESSION @@ -957,6 +966,35 @@ void fill_pathname_expand_special(char *out_path, 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, const char *in_path, size_t size) { diff --git a/file_path.h b/file_path.h index 3c57dd9ee4..3efd78c5e8 100644 --- a/file_path.h +++ b/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 */ 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_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, 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, const char *in_path, size_t size); void fill_pathname_abbreviate_special(char *out_path,