Gracefully handle the case when a zip file contains no known Model 3 ROM set.

This commit is contained in:
Bart Trzynadlowski 2015-06-13 02:57:41 +00:00
parent 6bf4244207
commit 1035b0c6a8

View file

@ -223,7 +223,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
ErrorLog("Could not open '%s'.", zipFile); ErrorLog("Could not open '%s'.", zipFile);
return NULL; return NULL;
} }
// First pass: scan every file and determine the game // First pass: scan every file and determine the game
err = unzGoToFirstFile(zf); err = unzGoToFirstFile(zf);
if (UNZ_OK != err) if (UNZ_OK != err)
@ -236,14 +236,14 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
// Identify the file we're looking at // Identify the file we're looking at
err = unzGetCurrentFileInfo(zf, &fileInfo, NULL, 0, NULL, 0, NULL, 0); err = unzGetCurrentFileInfo(zf, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
if (err != UNZ_OK) if (err != UNZ_OK)
continue; continue;
if (OKAY != FindROMByCRC(&CurGame, &romIdx, GameList, Game, fileInfo.crc)) if (OKAY != FindROMByCRC(&CurGame, &romIdx, GameList, Game, fileInfo.crc))
continue; continue;
// If the ROM appears in multiple games, do not use it to identify the game! // If the ROM appears in multiple games, do not use it to identify the game!
if (!ROMIsUnique(GameList, fileInfo.crc)) if (!ROMIsUnique(GameList, fileInfo.crc))
continue; continue;
// We have a unique ROM used by a single game; identify that game // We have a unique ROM used by a single game; identify that game
if (Game == NULL) // this is the first game we've identified within the ZIP if (Game == NULL) // this is the first game we've identified within the ZIP
{ {
@ -264,6 +264,13 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
} }
} }
if (Game == NULL)
{
ErrorLog("No Model 3 games found in '%s'.", zipFile);
unzClose(zf);
return NULL;
}
if (CurGame->parent) if (CurGame->parent)
{ {
// Create parent zip file name // Create parent zip file name
@ -288,6 +295,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
if (NULL == zfp) if (NULL == zfp)
{ {
ErrorLog("Parent ROM set '%s' is missing.", zipFileParent.c_str()); ErrorLog("Parent ROM set '%s' is missing.", zipFileParent.c_str());
unzClose(zf);
return NULL; return NULL;
} }
} }
@ -297,6 +305,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
if (UNZ_OK != err) if (UNZ_OK != err)
{ {
ErrorLog("Unable to read the contents of '%s' (code %X)", zipFile, err); ErrorLog("Unable to read the contents of '%s' (code %X)", zipFile, err);
unzClose(zf);
return NULL; return NULL;
} }
memset(romsFound, 0, sizeof(romsFound)); // here, romsFound[] indicates which ROMs were found in the ZIP file for the game memset(romsFound, 0, sizeof(romsFound)); // here, romsFound[] indicates which ROMs were found in the ZIP file for the game
@ -320,6 +329,7 @@ const struct GameInfo * LoadROMSetFromZIPFile(const struct ROMMap *Map, const st
if (UNZ_OK != err) if (UNZ_OK != err)
{ {
ErrorLog("Unable to read the contents of '%s' (code %X)", zipFileParent.c_str(), err); ErrorLog("Unable to read the contents of '%s' (code %X)", zipFileParent.c_str(), err);
unzClose(zf);
return NULL; return NULL;
} }
for (; err != UNZ_END_OF_LIST_OF_FILE; err = unzGoToNextFile(zfp)) for (; err != UNZ_END_OF_LIST_OF_FILE; err = unzGoToNextFile(zfp))