From 96fd5c41210be38fc2db9281917ac510645f8f9d Mon Sep 17 00:00:00 2001 From: qwertymodo Date: Thu, 17 Aug 2017 10:37:28 -0700 Subject: [PATCH] Allow unzFindExtension to optionally match the exact filename --- memmap.cpp | 8 ++++---- msu1.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/memmap.cpp b/memmap.cpp index 259c416c..230ea285 100644 --- a/memmap.cpp +++ b/memmap.cpp @@ -967,7 +967,7 @@ static bool8 ReadUPSPatch (Stream *, long, int32 &); static long ReadInt (Stream *, unsigned); static bool8 ReadIPSPatch (Stream *, long, int32 &); #ifdef UNZIP_SUPPORT -static int unzFindExtension (unzFile &, const char *, bool restart = TRUE, bool print = TRUE); +static int unzFindExtension (unzFile &, const char *, bool restart = TRUE, bool print = TRUE, bool allowExact = FALSE); #endif // deinterleave @@ -4188,10 +4188,10 @@ static bool8 ReadIPSPatch (Stream *r, long offset, int32 &rom_size) } #ifdef UNZIP_SUPPORT -static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool print) +static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool print, bool allowExact) { unz_file_info info; - int port, l = strlen(ext); + int port, l = strlen(ext), e = allowExact ? 0 : 1; if (restart) port = unzGoToFirstFile(file); @@ -4206,7 +4206,7 @@ static int unzFindExtension (unzFile &file, const char *ext, bool restart, bool unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0); len = strlen(name); - if (len >= l + 1 && name[len - l - 1] == '.' && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK) + if (len >= l + e && name[len - l - 1] == '.' && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK) { if (print) printf("Using patch %s", name); diff --git a/msu1.cpp b/msu1.cpp index 1f042110..51e15dd3 100644 --- a/msu1.cpp +++ b/msu1.cpp @@ -206,10 +206,10 @@ size_t partial_samples; int16 *bufPos, *bufBegin, *bufEnd; #ifdef UNZIP_SUPPORT -static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE, bool print = TRUE) +static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE, bool print = TRUE, bool allowExact = FALSE) { unz_file_info info; - int port, l = strlen(ext); + int port, l = strlen(ext), e = allowExact ? 0 : 1; if (restart) port = unzGoToFirstFile(file); @@ -224,7 +224,7 @@ static int unzFindExtension(unzFile &file, const char *ext, bool restart = TRUE, unzGetCurrentFileInfo(file, &info, name, 128, NULL, 0, NULL, 0); len = strlen(name); - if (len >= l && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK) + if (len >= l + e && strcasecmp(name + len - l, ext) == 0 && unzOpenCurrentFile(file) == UNZ_OK) { if (print) printf("Using msu file %s", name); @@ -267,7 +267,7 @@ STREAM S9xMSU1OpenFile(char *msu_ext) if (unzFile) { - int port = unzFindExtension(unzFile, msu_ext); + int port = unzFindExtension(unzFile, msu_ext, true, true, true); if (port == UNZ_OK) { printf(" in %s.\n", zip_filename);