2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-10-02 22:21:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef COMMON_ADVANCED_DETECTOR_H
|
|
|
|
#define COMMON_ADVANCED_DETECTOR_H
|
|
|
|
|
|
|
|
#include "common/fs.h"
|
2008-02-02 00:54:52 +00:00
|
|
|
#include "common/error.h"
|
2006-10-02 22:21:57 +00:00
|
|
|
|
2006-11-12 03:23:29 +00:00
|
|
|
#include "base/game.h" // For PlainGameDescriptor and GameList
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
#include "engines/metaengine.h"
|
2006-11-12 03:23:29 +00:00
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
struct ADGameFileDescription {
|
|
|
|
const char *fileName;
|
2007-01-28 23:24:16 +00:00
|
|
|
uint16 fileType; // Optional. Not used during detection, only by engines.
|
|
|
|
const char *md5; // Optional. May be NULL.
|
|
|
|
int32 fileSize; // Optional. Set to -1 to ignore.
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
#define AD_ENTRY1(f, x) {{ f, 0, x, -1}, {NULL, 0, NULL, 0}}
|
|
|
|
#define AD_ENTRY1s(f, x, s) {{ f, 0, x, s}, {NULL, 0, NULL, 0}}
|
|
|
|
|
2007-02-13 01:28:18 +00:00
|
|
|
enum ADGameFlags {
|
2007-02-13 13:42:28 +00:00
|
|
|
ADGF_NO_FLAGS = 0,
|
2008-06-02 18:19:58 +00:00
|
|
|
ADGF_KEEPMATCH = (1 << 27), // this entry is kept even when there are matched
|
|
|
|
// entries with more files
|
2008-04-10 21:41:57 +00:00
|
|
|
ADGF_DROPLANGUAGE = (1 << 28), // don't add language to gameid
|
|
|
|
ADGF_CD = (1 << 29), // add "-cd" to gameid
|
|
|
|
ADGF_DEMO = (1 << 30) // add "-demo" to gameid
|
2007-02-13 01:28:18 +00:00
|
|
|
};
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
struct ADGameDescription {
|
2006-12-19 23:37:03 +00:00
|
|
|
const char *gameid;
|
2006-10-02 22:21:57 +00:00
|
|
|
const char *extra;
|
2007-01-28 23:24:16 +00:00
|
|
|
ADGameFileDescription filesDescriptions[14];
|
2006-10-02 22:21:57 +00:00
|
|
|
Language language;
|
|
|
|
Platform platform;
|
2007-11-21 21:51:21 +00:00
|
|
|
|
2007-02-13 01:28:18 +00:00
|
|
|
/**
|
|
|
|
* A bitmask of extra flags. The top 8 bits are reserved for generic flags
|
|
|
|
* defined in the ADGameFlags. This leaves 24 flags to be used by client
|
|
|
|
* code.
|
|
|
|
*/
|
|
|
|
uint32 flags;
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
|
|
|
* End marker for a table of ADGameDescription structs. Use this to
|
|
|
|
* terminate a list to be passed to the AdvancedDetector API.
|
|
|
|
*/
|
2007-02-13 01:28:18 +00:00
|
|
|
#define AD_TABLE_END_MARKER \
|
2007-02-13 13:42:28 +00:00
|
|
|
{ NULL, NULL, { { NULL, 0, NULL, 0 } }, Common::UNK_LANG, Common::kPlatformUnknown, Common::ADGF_NO_FLAGS }
|
2007-02-13 01:28:18 +00:00
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
|
2006-11-10 22:43:10 +00:00
|
|
|
struct ADObsoleteGameID {
|
|
|
|
const char *from;
|
|
|
|
const char *to;
|
|
|
|
Common::Platform platform;
|
|
|
|
};
|
|
|
|
|
2007-02-14 23:46:39 +00:00
|
|
|
struct ADFileBasedFallback {
|
|
|
|
/**
|
2007-03-08 21:33:55 +00:00
|
|
|
* Pointer to an ADGameDescription or subclass thereof which will get
|
|
|
|
* returned if there's a detection match.
|
2007-02-14 23:46:39 +00:00
|
|
|
*/
|
|
|
|
const void *desc;
|
2007-11-21 21:51:21 +00:00
|
|
|
|
2007-02-14 23:46:39 +00:00
|
|
|
/**
|
2007-03-08 21:33:55 +00:00
|
|
|
* A zero-terminated list of filenames used for matching. All files in
|
|
|
|
* the list must be present to get a detection match.
|
2007-02-14 23:46:39 +00:00
|
|
|
*/
|
|
|
|
const char *filenames[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-28 07:31:26 +00:00
|
|
|
enum ADFlags {
|
2007-02-13 13:17:46 +00:00
|
|
|
/**
|
|
|
|
* Generate/augment preferred target with information on the language (if
|
|
|
|
* not equal to english) and platform (if not equal to PC).
|
|
|
|
*/
|
2008-04-05 22:29:08 +00:00
|
|
|
kADFlagDontAugmentPreferredTarget = (1 << 0),
|
2007-12-31 14:45:38 +00:00
|
|
|
kADFlagPrintWarningOnFileBasedFallback = (1 << 1),
|
|
|
|
kADFlagUseExtraAsHint = (1 << 2)
|
2007-01-28 07:31:26 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
|
|
|
* A structure containing all parameters for the AdvancedDetector.
|
|
|
|
* Typically, an engine will have a single instance of this which is
|
2008-02-03 18:37:41 +00:00
|
|
|
* used by its AdvancedMetaEngine subclass as a parameter to the
|
|
|
|
* primary AdvancedMetaEngine constructor.
|
2007-02-13 22:25:25 +00:00
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
struct ADParams {
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
|
|
|
* Pointer to an array of objects which are either ADGameDescription
|
|
|
|
* or superset structures (i.e. start with an ADGameDescription member.
|
|
|
|
* The list is terminated by an entry with a gameid equal to 0
|
|
|
|
* (see AD_TABLE_END_MARKER).
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
const byte *descs;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The size of a single entry of the above descs array. Always
|
|
|
|
* must be >= sizeof(ADGameDescription).
|
|
|
|
*/
|
|
|
|
uint descItemSize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of bytes to compute MD5 sum for. The AdvancedDetector
|
|
|
|
* is primarily based on computing and matching MD5 checksums of files.
|
|
|
|
* Since doing that for large files can be slow, it can be restricted
|
|
|
|
* to a subset of all files.
|
|
|
|
* Typically this will be set to something between 5 and 50 kilobyte,
|
|
|
|
* but arbitrary non-zero values are possible.
|
|
|
|
*/
|
|
|
|
uint md5Bytes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all gameids (and their corresponding descriptions) supported
|
|
|
|
* by this engine.
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
const PlainGameDescriptor *list;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
2007-02-13 23:37:44 +00:00
|
|
|
* Structure for autoupgrading obsolete targets (optional).
|
2007-02-13 22:25:25 +00:00
|
|
|
*
|
|
|
|
* @todo Properly explain this.
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADObsoleteGameID *obsoleteList;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of single gameid (optional).
|
|
|
|
*
|
|
|
|
* @todo Properly explain this -- what does it do?
|
|
|
|
*/
|
2007-01-28 07:31:26 +00:00
|
|
|
const char *singleid;
|
2007-01-24 22:24:52 +00:00
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
2007-02-13 23:37:44 +00:00
|
|
|
* List of files for file-based fallback detection (optional).
|
2007-11-21 21:51:21 +00:00
|
|
|
* This is used if the regular MD5 based detection failed to
|
2007-02-13 23:37:44 +00:00
|
|
|
* detect anything.
|
2007-02-14 23:46:39 +00:00
|
|
|
* As usual this list is terminated by an all-zero entry.
|
2007-02-13 23:37:44 +00:00
|
|
|
*
|
2007-02-13 22:25:25 +00:00
|
|
|
* @todo Properly explain this
|
|
|
|
*/
|
2007-02-14 23:46:39 +00:00
|
|
|
const ADFileBasedFallback *fileBasedFallback;
|
2007-11-21 21:51:21 +00:00
|
|
|
|
2007-02-13 23:37:44 +00:00
|
|
|
/**
|
|
|
|
* A bitmask of flags which can be used to configure the behavior
|
|
|
|
* of the AdvancedDetector. Refer to ADFlags for a list of flags
|
|
|
|
* that can be ORed together and passed here.
|
|
|
|
*/
|
2007-02-13 22:25:25 +00:00
|
|
|
uint32 flags;
|
|
|
|
};
|
2006-12-19 22:43:15 +00:00
|
|
|
|
|
|
|
|
2007-01-25 21:16:57 +00:00
|
|
|
namespace AdvancedDetector {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scan through the game descriptors specified in params and search for
|
2008-02-03 18:37:41 +00:00
|
|
|
* 'gameid' in there. If a match is found, returns a GameDescriptor
|
2007-01-25 21:16:57 +00:00
|
|
|
* with gameid and description set.
|
|
|
|
*/
|
2007-06-15 17:36:41 +00:00
|
|
|
GameDescriptor findGameID(
|
|
|
|
const char *gameid,
|
|
|
|
const PlainGameDescriptor *list,
|
|
|
|
const Common::ADObsoleteGameID *obsoleteList = 0
|
|
|
|
);
|
2006-11-12 03:23:29 +00:00
|
|
|
|
2007-01-25 21:16:57 +00:00
|
|
|
} // End of namespace AdvancedDetector
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
/**
|
|
|
|
* A MetaEngine implementation based around the advanced detector code.
|
|
|
|
*/
|
|
|
|
class AdvancedMetaEngine : public MetaEngine {
|
|
|
|
const Common::ADParams ¶ms;
|
|
|
|
public:
|
|
|
|
AdvancedMetaEngine(const Common::ADParams &dp) : params(dp) {}
|
2008-02-02 02:35:13 +00:00
|
|
|
|
2008-02-03 18:37:41 +00:00
|
|
|
virtual GameList getSupportedGames() const;
|
|
|
|
virtual GameDescriptor findGame(const char *gameid) const;
|
|
|
|
virtual GameList detectGames(const FSList &fslist) const;
|
|
|
|
virtual PluginError createInstance(OSystem *syst, Engine **engine) const;
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
// To be provided by subclasses
|
2008-03-14 17:31:04 +00:00
|
|
|
virtual bool createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const = 0;
|
2008-03-14 13:59:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An (optional) generic fallback detect function which is invoked
|
|
|
|
* if both the regular MD5 based detection as well as the file
|
|
|
|
* based fallback failed to detect anything.
|
|
|
|
*
|
|
|
|
* @note The fslist parameter may be 0 -- in that case, it is assumed
|
|
|
|
* that the callback searchs the current directory.
|
|
|
|
*/
|
2008-05-26 18:03:55 +00:00
|
|
|
virtual const Common::ADGameDescription *fallbackDetect(const FSList *fslist) const {
|
2008-03-15 15:25:49 +00:00
|
|
|
return 0;
|
2008-03-14 13:59:31 +00:00
|
|
|
}
|
2008-02-02 00:54:52 +00:00
|
|
|
};
|
|
|
|
|
2008-02-02 11:52:04 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
#endif
|