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$
|
|
|
|
*
|
|
|
|
*/
|
2009-01-29 22:13:01 +00:00
|
|
|
#ifndef ENGINES_ADVANCED_DETECTOR_H
|
|
|
|
#define ENGINES_ADVANCED_DETECTOR_H
|
2006-10-02 22:21:57 +00:00
|
|
|
|
|
|
|
#include "common/fs.h"
|
2008-02-02 00:54:52 +00:00
|
|
|
#include "common/error.h"
|
2006-10-02 22:21:57 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2010-08-01 20:47:46 +00:00
|
|
|
#define AD_LISTEND {NULL, 0, NULL, 0}
|
|
|
|
|
|
|
|
#define AD_ENTRY1(f, x) {{ f, 0, x, -1}, AD_LISTEND}
|
|
|
|
#define AD_ENTRY1s(f, x, s) {{ f, 0, x, s}, AD_LISTEND}
|
2007-02-13 22:25:25 +00:00
|
|
|
|
2007-02-13 01:28:18 +00:00
|
|
|
enum ADGameFlags {
|
2007-02-13 13:42:28 +00:00
|
|
|
ADGF_NO_FLAGS = 0,
|
2010-08-25 11:51:06 +00:00
|
|
|
ADGF_PIRATED = (1 << 23), // flag to designate well known pirated versions with cracks
|
2010-08-01 21:17:00 +00:00
|
|
|
ADGF_ADDENGLISH = (1 << 24), // always add English as language option
|
2010-05-10 18:23:54 +00:00
|
|
|
ADGF_MACRESFORK = (1 << 25), // the md5 for this entry will be calculated from the resource fork
|
2010-01-03 21:07:40 +00:00
|
|
|
ADGF_USEEXTRAASTITLE = (1 << 26), // Extra field value will be used as main game title, not gameid
|
2010-05-10 18:23:54 +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
|
2010-01-03 21:07:40 +00:00
|
|
|
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];
|
2009-01-29 22:13:01 +00:00
|
|
|
Common::Language language;
|
|
|
|
Common::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;
|
2009-06-06 17:56:41 +00:00
|
|
|
|
|
|
|
uint32 guioptions;
|
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 \
|
2009-06-06 17:56:41 +00:00
|
|
|
{ NULL, NULL, { { NULL, 0, NULL, 0 } }, Common::UNK_LANG, Common::kPlatformUnknown, ADGF_NO_FLAGS, Common::GUIO_NONE }
|
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),
|
2010-01-03 21:07:40 +00:00
|
|
|
/**
|
|
|
|
* Warn user about new variant if his version was detected with fallback
|
|
|
|
*/
|
2007-12-31 14:45:38 +00:00
|
|
|
kADFlagPrintWarningOnFileBasedFallback = (1 << 1),
|
2010-01-03 21:07:40 +00:00
|
|
|
/**
|
|
|
|
* Store value of extra field in config file, and use it as a hint
|
|
|
|
* on subsequent runs. Could be used when there is no way to autodetect
|
|
|
|
* game (when more than one game sits in same directory), and user picks
|
|
|
|
* up a variant manually.
|
|
|
|
*/
|
2007-12-31 14:45:38 +00:00
|
|
|
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.
|
|
|
|
*/
|
2009-01-29 22:13:01 +00:00
|
|
|
const 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;
|
2009-06-06 17:56:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A bitmask of game GUI options which will be added to each
|
|
|
|
* entry in addition to per-game options. Refer to GameGUIOption
|
|
|
|
* enum for the list.
|
|
|
|
*/
|
|
|
|
uint32 guioptions;
|
2010-06-14 14:50:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum depth of directories to look up
|
|
|
|
* If set to 0, the depth is 1 level
|
|
|
|
*/
|
|
|
|
uint32 depth;
|
2010-06-15 10:59:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Case-insensitive list of directory globs which could be used for
|
|
|
|
* going deeper int directory structure.
|
|
|
|
* @see String::matchString() method for format description.
|
|
|
|
*
|
|
|
|
* @note Last item must be 0
|
|
|
|
*/
|
2010-08-24 13:10:48 +00:00
|
|
|
const char * const *directoryGlobs;
|
2007-02-13 22:25:25 +00:00
|
|
|
};
|
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,
|
2009-01-29 22:13:01 +00:00
|
|
|
const ADObsoleteGameID *obsoleteList = 0
|
2007-06-15 17:36:41 +00:00
|
|
|
);
|
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 {
|
2009-01-29 22:13:01 +00:00
|
|
|
const ADParams ¶ms;
|
2008-02-02 00:54:52 +00:00
|
|
|
public:
|
2009-01-29 22:13:01 +00:00
|
|
|
AdvancedMetaEngine(const 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;
|
2009-01-29 22:13:01 +00:00
|
|
|
virtual GameList detectGames(const Common::FSList &fslist) const;
|
2008-11-05 17:24:56 +00:00
|
|
|
virtual Common::Error createInstance(OSystem *syst, Engine **engine) const;
|
2008-02-03 18:37:41 +00:00
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
// To be provided by subclasses
|
2009-01-29 22:13:01 +00:00
|
|
|
virtual bool createInstance(OSystem *syst, Engine **engine, const 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.
|
|
|
|
*/
|
2009-01-29 22:13:01 +00:00
|
|
|
virtual const ADGameDescription *fallbackDetect(const Common::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
|
|
|
};
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
#endif
|