diff --git a/Makefile.common b/Makefile.common index d11d06c4ce..e8567377ab 100644 --- a/Makefile.common +++ b/Makefile.common @@ -557,12 +557,14 @@ ifeq ($(WANT_MINIZ),1) deps/rzlib/ioapi.o \ deps/rzlib/unzip.o else +ifeq ($(HAVE_ZLIB),1) ZLIB_OBJS = deps/rzlib/unzip.o deps/rzlib/ioapi.o OBJ += $(ZLIB_OBJS) RETROLAUNCH_OBJ += $(ZLIB_OBJS) JOYCONFIG_OBJ += $(ZLIB_OBJS) HAVE_ZLIB_DEFLATE = 1 endif +endif ifeq ($(HAVE_ZLIB_DEFLATE),1) DEFINES += -DHAVE_ZLIB_DEFLATE diff --git a/file_path.c b/file_path.c index 4ff3f5911a..b9f505075b 100644 --- a/file_path.c +++ b/file_path.c @@ -417,6 +417,22 @@ void fill_pathname_base(char *out, const char *in_path, size_t size) else ptr = in_path; + /* In case of compression, we also have to consider paths like + * /path/to/archive.7z#mygame.img + * and + * /path/to/archive.7z#folder/mygame.img + * basename would be mygame.img in both cases + */ + +#ifdef HAVE_COMPRESSION + const char *ptr_bak = ptr; + ptr = strchr(ptr_bak,'#'); + if (ptr) + ptr++; + else + ptr = ptr_bak; +#endif + rarch_assert(strlcpy(out, ptr, size) < size); } @@ -450,7 +466,16 @@ void path_basedir(char *path) if (strlen(path) < 2) return; - char *last = find_last_slash(path); + char *last; + +#ifdef HAVE_COMPRESSION + /* We want to find the directory with the zipfile in basedir. */ + last = strchr(path,'#'); + if (last) + *last = '\0'; +#endif + + last = find_last_slash(path); if (last) last[1] = '\0'; @@ -470,6 +495,15 @@ const char *path_basename(const char *path) { const char *last = find_last_slash(path); + /* We cut either at the last hash or the last slash; whichever comes last */ +#ifdef HAVE_COMPRESSION + const char *last_hash = strchr(path,'#'); + if (last_hash > last) + { + return last_hash + 1; + } +#endif + if (last) return last + 1; return path; diff --git a/retroarch.c b/retroarch.c index 117b7fc3c3..b62a348471 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1023,6 +1023,29 @@ static void set_basename(const char *path) strlcpy(g_extern.fullpath, path, sizeof(g_extern.fullpath)); strlcpy(g_extern.basename, path, sizeof(g_extern.basename)); + /* Removing extension is a bit tricky for compressed files. + * Basename means: + * /file/to/path/game.extension should be: + * /file/to/path/game + * + * Two things to consider here are: /file/to/path/ is expected + * to be a directory and "game" is a single file. This is used for + * states and srm default paths + * + * For compressed files we have: + * + * /file/to/path/comp.7z#game.extension and + * /file/to/path/comp.7z#folder/game.extension + * + * The choice I take here is: + * /file/to/path/game as basename. We might end up in a writable dir then + * and the name of srm and states are meaningful. + * + */ +#ifdef HAVE_COMPRESSION + path_basedir(g_extern.basename); + fill_pathname_dir(g_extern.basename,path,"",sizeof(g_extern.basename)); +#endif if ((dst = strrchr(g_extern.basename, '.'))) *dst = '\0';