AdvancedDetector: revamped the file based fallback code

svn-id: r25599
This commit is contained in:
Max Horn 2007-02-14 23:46:39 +00:00
parent 247110b19b
commit ec27c53491
3 changed files with 96 additions and 89 deletions

View File

@ -341,11 +341,6 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
continue;
}
if (g->filesDescriptions[0].fileName == 0) {
debug(5, "Skipping dummy entry: %s", g->gameid);
continue;
}
// Try to open all files for this game
for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) {
tstr = fileDesc->fileName;
@ -423,18 +418,17 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
// to be present in order to generate a match; the row is terminated
// by a zero byte.
// The whole list is terminated by another zero byte (i.e. a zero gameid).
const char **ptr = params.fileBasedFallback;
const ADFileBasedFallback *ptr = params.fileBasedFallback;
const char* const* filenames = 0;
// First we create list of files required for detection.
if (allFiles.empty()) {
File testFile;
for (; *ptr; ptr++) {
// skip the gameid
ptr++;
for (; *ptr; ptr++) {
tstr = String(*ptr);
for (; ptr->desc; ptr++) {
filenames = ptr->filenames;
for (; *filenames; filenames++) {
tstr = String(*filenames);
tstr.toLowercase();
if (!allFiles.contains(tstr)) {
@ -449,26 +443,27 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
}
int maxNumMatchedFiles = 0;
const char *matchedGameid = 0;
const ADGameDescription *matchedDesc = 0;
ptr = params.fileBasedFallback;
for (; *ptr; ptr++) {
const char *entryGameid = *ptr++;
fileMissing = false;
for (; ptr->desc; ptr++) {
const ADGameDescription *agdesc = (const ADGameDescription *)ptr->desc;
int numMatchedFiles = 0;
fileMissing = false;
for (; *ptr; ptr++) {
filenames = ptr->filenames;
for (; *filenames; filenames++) {
if (fileMissing) {
continue;
}
tstr = String(*ptr);
tstr = String(*filenames);
tstr.toLowercase();
tstr2 = tstr + ".";
debug(3, "++ %s", *ptr);
debug(3, "++ %s", *filenames);
if (!allFiles.contains(tstr) && !allFiles.contains(tstr2)) {
fileMissing = true;
continue;
@ -478,29 +473,22 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p
}
if (!fileMissing)
debug(4, "Matched: %s", entryGameid);
debug(4, "Matched: %s", agdesc->gameid);
if (!fileMissing && numMatchedFiles > maxNumMatchedFiles) {
matchedGameid = entryGameid;
matchedDesc = agdesc;
maxNumMatchedFiles = numMatchedFiles;
debug(4, "and overriden");
}
}
if (matchedGameid) { // We got a match
for (descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize) {
g = (const ADGameDescription *)descPtr;
if (g->filesDescriptions[0].fileName == 0) {
if (!scumm_stricmp(g->gameid, matchedGameid)) {
// FIXME: This warning, if ever seen by somebody, is
// extremly cryptic!
warning("But it looks like unknown variant of %s", matchedGameid);
if (matchedDesc) { // We got a match
// FIXME: This warning, if ever seen by somebody, is
// extremly cryptic!
warning("But it looks like unknown variant of %s", matchedDesc->gameid);
matched.push_back(g);
}
}
}
matched.push_back(matchedDesc);
}
}

View File

@ -79,6 +79,21 @@ struct ADObsoleteGameID {
Common::Platform platform;
};
struct ADFileBasedFallback {
/**
* Pointer to an ADGameDescription or subclass thereof.
*/
const void *desc;
/**
* A zero-terminated list of filenames.
*
* @todo Properly explain this
*/
const char *filenames[10];
};
enum ADFlags {
/**
* Generate/augment preferred target with information on the language (if
@ -142,10 +157,11 @@ struct ADParams {
* List of files for file-based fallback detection (optional).
* This is used if the regular MD5 based detection failed to
* detect anything.
* As usual this list is terminated by an all-zero entry.
*
* @todo Properly explain this
*/
const char **fileBasedFallback;
const ADFileBasedFallback *fileBasedFallback;
/**
* A callback pointing to an (optional) generic fallback detect

View File

@ -64,18 +64,6 @@ static const ADObsoleteGameID obsoleteGameIDsTable[] = {
namespace Gob {
static const GOBGameDescription gameDescriptions[] = {
{ // Dummy entry for fallback detection
{
"gob1",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB1,
"intro"
},
{ // Supplied by Florian Zeitz on scummvm-devel
{
"gob1",
@ -112,18 +100,6 @@ static const GOBGameDescription gameDescriptions[] = {
GF_GOB1,
"intro"
},
{ // Dummy entry for fallback detection
{
"gob1cd",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB1 | GF_CD,
"intro"
},
{ // CD 1.000 version.
{
"gob1cd",
@ -328,18 +304,6 @@ static const GOBGameDescription gameDescriptions[] = {
GF_GOB1,
"intro"
},
{ // Dummy entry for fallback detection
{
"gob2",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB2,
"intro"
},
{
{
"gob2",
@ -440,18 +404,6 @@ static const GOBGameDescription gameDescriptions[] = {
GF_GOB2,
"intro"
},
{ // Dummy entry for fallback detection
{
"gob2cd",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB2 | GF_CD,
"intro"
},
{
{
"gob2cd",
@ -887,13 +839,64 @@ static const GOBGameDescription gameDescriptions[] = {
{ AD_TABLE_END_MARKER, 0, NULL }
};
static const char *fileBased[] = {
"gob1", "intro.stk", "disk1.stk", "disk2.stk", "disk3.stk", "disk4.stk", 0,
"gob1cd", "intro.stk", "gob.lic", 0,
"gob2", "intro.stk", 0,
"gob2", "intro.stk", "disk2.stk", "disk3.stk", 0,
"gob2cd", "intro.stk", "gobnew.lic", 0,
0
static const GOBGameDescription fallbackDescs[] = {
{
{
"gob1",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB1,
"intro"
},
{
{
"gob1cd",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB1 | GF_CD,
"intro"
},
{
{
"gob2",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB2,
"intro"
},
{
{
"gob2cd",
"unknown",
AD_ENTRY1(0, 0),
UNK_LANG,
kPlatformPC,
Common::ADGF_NO_FLAGS
},
GF_GOB2 | GF_CD,
"intro"
},
};
static const ADFileBasedFallback fileBased[] = {
{ &fallbackDescs[0], { "intro.stk", "disk1.stk", "disk2.stk", "disk3.stk", "disk4.stk", 0 } },
{ &fallbackDescs[1], { "intro.stk", "gob.lic", 0 } },
{ &fallbackDescs[2], { "intro.stk", 0 } },
{ &fallbackDescs[2], { "intro.stk", "disk2.stk", "disk3.stk", 0 } },
{ &fallbackDescs[3], { "intro.stk", "gobnew.lic", 0 } },
{ 0, { 0 } }
};
}