GLK: Only check the format of a Blorb file if it has a valid file extension

This commit is contained in:
Cameron Cawley 2019-03-31 19:46:16 +01:00 committed by Paul Gilbert
parent 7b4c6d6a35
commit 280a4f2d91
6 changed files with 26 additions and 8 deletions

View File

@ -213,4 +213,9 @@ bool Blorb::isBlorb(const Common::String &filename, uint32 type) {
return isBlorb(f, type);
}
bool Blorb::hasBlorbExt(const Common::String &filename) {
return filename.hasSuffixIgnoreCase(".blorb") || filename.hasSuffixIgnoreCase(".zblorb")
|| filename.hasSuffixIgnoreCase(".gblorb") || filename.hasSuffixIgnoreCase(".blb");
}
} // End of namespace Glk

View File

@ -141,6 +141,11 @@ public:
* Returns true if a given filename specifies a Blorb file
*/
static bool isBlorb(const Common::String &filename, uint32 type = 0);
/**
* Returns true if a given filename has a Blorb file extension
*/
static bool hasBlorbExt(const Common::String &filename);
};
} // End of namespace Glk

View File

@ -65,9 +65,11 @@ bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
if (file->isDirectory())
continue;
Common::String filename = file->getName();
bool hasExt = false, isBlorb = false;
bool hasExt = Blorb::hasBlorbExt(filename), isBlorb = false;
for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
hasExt = filename.hasSuffixIgnoreCase(*ext);
if (!hasExt)
continue;
// Open up the file and calculate the md5, and get the serial
Common::File gameFile;
@ -81,7 +83,7 @@ bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
isBlorb = Blorb::isBlorb(gameFile, ID_ZCOD);
if (!isBlorb) {
if (!hasExt) {
if (Blorb::hasBlorbExt(filename)) {
gameFile.close();
continue;
}

View File

@ -55,9 +55,11 @@ bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &
if (file->isDirectory())
continue;
Common::String filename = file->getName();
bool hasExt = false, isBlorb = false;
bool hasExt = Blorb::hasBlorbExt(filename), isBlorb = false;
for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
hasExt = filename.hasSuffixIgnoreCase(*ext);
if (!hasExt)
continue;
// Open up the file and calculate the md5
Common::File gameFile;
@ -69,7 +71,7 @@ bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &
isBlorb = Blorb::isBlorb(gameFile, ID_GLUL);
gameFile.close();
if (!hasExt && !isBlorb)
if (!isBlorb && Blorb::hasBlorbExt(filename))
continue;
// Check for known games

View File

@ -54,9 +54,11 @@ bool ScottMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
continue;
Common::String filename = file->getName();
bool hasExt = false, isBlorb = false;
bool hasExt = Blorb::hasBlorbExt(filename), isBlorb = false;
for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
hasExt = filename.hasSuffixIgnoreCase(*ext);
if (!hasExt)
continue;
Common::File gameFile;
if (!gameFile.open(*file))
@ -67,7 +69,7 @@ bool ScottMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g
isBlorb = Blorb::isBlorb(gameFile, ID_SAAI);
gameFile.close();
if (!hasExt && !isBlorb)
if (!isBlorb && Blorb::hasBlorbExt(filename))
continue;
// Scan through the Scott game list for a match

View File

@ -68,9 +68,11 @@ bool TADSMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &ga
continue;
Common::String filename = file->getName();
bool hasExt = false, isBlorb = false;
bool hasExt = Blorb::hasBlorbExt(filename), isBlorb = false;
for (const char *const *ext = &EXTENSIONS[0]; *ext && !hasExt; ++ext)
hasExt = filename.hasSuffixIgnoreCase(*ext);
if (!hasExt)
continue;
// Open up the file and calculate the md5
Common::File gameFile;
@ -82,7 +84,7 @@ bool TADSMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &ga
isBlorb = Blorb::isBlorb(gameFile, ID_TAD2) || Blorb::isBlorb(gameFile, ID_TAD3);
gameFile.close();
if (!hasExt && !isBlorb)
if (!isBlorb && Blorb::hasBlorbExt(filename))
continue;
// Check for known games