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.
|
|
|
|
*
|
|
|
|
*/
|
2011-06-14 13:25:33 +00:00
|
|
|
|
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
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
#include "engines/metaengine.h"
|
2011-04-25 20:26:38 +00:00
|
|
|
#include "engines/engine.h"
|
2006-11-12 03:23:29 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
namespace Common {
|
|
|
|
class Error;
|
|
|
|
class FSList;
|
|
|
|
}
|
|
|
|
|
2011-06-14 15:13:02 +00:00
|
|
|
/**
|
|
|
|
* A record describing a file to be matched for detecting a specific game
|
|
|
|
* variant. A list of such records is used inside every ADGameDescription to
|
|
|
|
* enable detection.
|
|
|
|
*/
|
2006-10-02 22:21:57 +00:00
|
|
|
struct ADGameFileDescription {
|
2011-06-14 15:13:02 +00:00
|
|
|
const char *fileName; ///< Name of described file.
|
|
|
|
uint16 fileType; ///< Optional. Not used during detection, only by engines.
|
|
|
|
const char *md5; ///< MD5 of (the beginning of) the described file. Optional. Set to NULL to ignore.
|
|
|
|
int32 fileSize; ///< Size of the described file. Set to -1 to ignore.
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2011-06-14 15:13:02 +00:00
|
|
|
/**
|
|
|
|
* A shortcut to produce an empty ADGameFileDescription record. Used to mark
|
|
|
|
* the end of a list of these.
|
|
|
|
*/
|
2010-08-01 20:47:46 +00:00
|
|
|
#define AD_LISTEND {NULL, 0, NULL, 0}
|
|
|
|
|
2011-06-14 15:13:02 +00:00
|
|
|
/**
|
|
|
|
* A shortcut to produce a list of ADGameFileDescription records with only one
|
|
|
|
* record that contains just a filename with an MD5, and no file size.
|
|
|
|
*/
|
2010-08-01 20:47:46 +00:00
|
|
|
#define AD_ENTRY1(f, x) {{ f, 0, x, -1}, AD_LISTEND}
|
2011-06-14 15:13:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A shortcut to produce a list of ADGameFileDescription records with only one
|
|
|
|
* record that contains just a filename with an MD5, plus a file size.
|
|
|
|
*/
|
2010-08-01 20:47:46 +00:00
|
|
|
#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,
|
2011-04-25 20:26:38 +00:00
|
|
|
ADGF_UNSTABLE = (1 << 21), // flag to designate not yet officially-supported games that are not fit for public testing
|
|
|
|
ADGF_TESTING = (1 << 22), // flag to designate not yet officially-supported games that are fit for public testing
|
2011-06-14 15:13:02 +00:00
|
|
|
ADGF_PIRATED = (1 << 23), ///< flag to designate well known pirated versions with cracks
|
|
|
|
ADGF_ADDENGLISH = (1 << 24), ///< always add English as language option
|
|
|
|
ADGF_MACRESFORK = (1 << 25), ///< the md5 for this entry will be calculated from the resource fork
|
|
|
|
ADGF_USEEXTRAASTITLE = (1 << 26), ///< Extra field value will be used as main game title, not gameid
|
|
|
|
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];
|
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
|
|
|
/**
|
2011-04-27 09:31:52 +00:00
|
|
|
* A bitmask of extra flags. The top 16 bits are reserved for generic flags
|
|
|
|
* defined in the ADGameFlags. This leaves 16 bits to be used by client
|
2007-02-13 01:28:18 +00:00
|
|
|
* code.
|
|
|
|
*/
|
|
|
|
uint32 flags;
|
2009-06-06 17:56:41 +00:00
|
|
|
|
|
|
|
uint32 guioptions;
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2011-06-10 20:13:51 +00:00
|
|
|
/**
|
|
|
|
* A list of pointers to ADGameDescription structs (or subclasses thereof).
|
|
|
|
*/
|
2011-06-14 13:25:33 +00:00
|
|
|
typedef Common::Array<const ADGameDescription *> ADGameDescList;
|
2011-06-10 20:13:51 +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-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
|
|
|
*/
|
2011-06-14 16:21:44 +00:00
|
|
|
const ADGameDescription *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 {
|
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.
|
2011-06-14 16:15:47 +00:00
|
|
|
* In addition, this is useful if two variants of a game sharing the same
|
|
|
|
* gameid are contained in a single directory.
|
2010-01-03 21:07:40 +00:00
|
|
|
*/
|
2011-06-14 16:15:47 +00:00
|
|
|
kADFlagUseExtraAsHint = (1 << 0)
|
2007-01-28 07:31:26 +00:00
|
|
|
};
|
|
|
|
|
2011-06-11 15:52:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A MetaEngine implementation based around the advanced detector code.
|
|
|
|
*/
|
|
|
|
class AdvancedMetaEngine : public MetaEngine {
|
|
|
|
protected:
|
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).
|
|
|
|
*/
|
2011-06-11 15:52:32 +00:00
|
|
|
const byte *_gameDescriptors;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The size of a single entry of the above descs array. Always
|
|
|
|
* must be >= sizeof(ADGameDescription).
|
|
|
|
*/
|
2011-06-14 15:13:02 +00:00
|
|
|
const uint _descItemSize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all gameids (and their corresponding descriptions) supported
|
|
|
|
* by this engine.
|
|
|
|
*/
|
|
|
|
const PlainGameDescriptor *_gameids;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2011-08-20 22:41:32 +00:00
|
|
|
* Typically this will be set to something between 5 and 50 kilobytes,
|
2011-06-14 15:13:02 +00:00
|
|
|
* but arbitrary non-zero values are possible. The default is 5000.
|
2007-02-13 22:25:25 +00:00
|
|
|
*/
|
2011-06-11 15:52:32 +00:00
|
|
|
uint _md5Bytes;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of single gameid (optional).
|
|
|
|
*
|
|
|
|
* @todo Properly explain this -- what does it do?
|
|
|
|
*/
|
2011-06-11 15:52:32 +00:00
|
|
|
const char *_singleid;
|
2007-01-24 22:24:52 +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.
|
|
|
|
*/
|
2011-06-11 15:52:32 +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.
|
|
|
|
*/
|
2011-06-11 15:52:32 +00:00
|
|
|
uint32 _guioptions;
|
2010-06-14 14:50:23 +00:00
|
|
|
|
|
|
|
/**
|
2011-06-11 15:52:32 +00:00
|
|
|
* Maximum depth of directories to look up.
|
2010-06-14 14:50:23 +00:00
|
|
|
* If set to 0, the depth is 1 level
|
|
|
|
*/
|
2011-06-11 15:52:32 +00:00
|
|
|
uint32 _maxScanDepth;
|
2010-06-15 10:59:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Case-insensitive list of directory globs which could be used for
|
2011-06-11 15:52:32 +00:00
|
|
|
* going deeper into the directory structure.
|
2010-06-15 10:59:23 +00:00
|
|
|
* @see String::matchString() method for format description.
|
|
|
|
*
|
|
|
|
* @note Last item must be 0
|
|
|
|
*/
|
2011-06-11 15:52:32 +00:00
|
|
|
const char * const *_directoryGlobs;
|
2006-12-19 22:43:15 +00:00
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
public:
|
2011-06-11 15:52:32 +00:00
|
|
|
AdvancedMetaEngine(const void *descs, uint descItemSize, const PlainGameDescriptor *gameids);
|
2008-02-02 02:35:13 +00:00
|
|
|
|
2011-06-10 20:13:51 +00:00
|
|
|
/**
|
|
|
|
* Returns list of targets supported by the engine.
|
|
|
|
* Distinguishes engines with single ID
|
|
|
|
*/
|
2008-02-03 18:37:41 +00:00
|
|
|
virtual GameList getSupportedGames() const;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
2008-02-03 18:37:41 +00:00
|
|
|
virtual GameDescriptor findGame(const char *gameid) const;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
2009-01-29 22:13:01 +00:00
|
|
|
virtual GameList detectGames(const Common::FSList &fslist) const;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
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
|
|
|
|
2011-06-10 20:13:51 +00:00
|
|
|
protected:
|
|
|
|
// To be implemented 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
|
|
|
|
2011-06-14 16:02:09 +00:00
|
|
|
typedef Common::HashMap<Common::String, Common::FSNode, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> FileMap;
|
|
|
|
|
2008-03-14 13:59:31 +00:00
|
|
|
/**
|
|
|
|
* An (optional) generic fallback detect function which is invoked
|
2011-06-14 16:11:14 +00:00
|
|
|
* if the regular MD5 based detection failed to detect anything.
|
2008-03-14 13:59:31 +00:00
|
|
|
*/
|
2011-06-14 16:02:09 +00:00
|
|
|
virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
|
2008-03-15 15:25:49 +00:00
|
|
|
return 0;
|
2008-03-14 13:59:31 +00:00
|
|
|
}
|
2011-06-10 13:56:56 +00:00
|
|
|
|
|
|
|
protected:
|
2011-06-10 20:13:51 +00:00
|
|
|
/**
|
|
|
|
* Detect games in specified directory.
|
|
|
|
* Parameters language and platform are used to pass on values
|
2011-06-14 15:13:02 +00:00
|
|
|
* specified by the user. This is used to restrict search scope.
|
2011-06-10 20:13:51 +00:00
|
|
|
*
|
2011-06-14 16:02:09 +00:00
|
|
|
* @param allFiles list of all present files, as computed by composeFileHashMap
|
2011-06-14 15:13:02 +00:00
|
|
|
* @param language restrict results to specified language
|
|
|
|
* @param platform restrict results to specified platform
|
|
|
|
* @param extra restrict results to specified extra string (only if kADFlagUseExtraAsHint is set)
|
|
|
|
* @return list of ADGameDescription pointers corresponding to matched games
|
2011-06-10 20:13:51 +00:00
|
|
|
*/
|
2011-06-14 16:02:09 +00:00
|
|
|
ADGameDescList detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
|
|
|
/**
|
2011-06-14 16:11:14 +00:00
|
|
|
* Iterates over all ADFileBasedFallback records inside fileBasedFallback.
|
2011-06-14 15:32:13 +00:00
|
|
|
* This then returns the record (or rather, the ADGameDescription
|
|
|
|
* contained in it) for which all files described by it are present, and
|
|
|
|
* among those the one with the maximal number of matching files.
|
|
|
|
* In case of a tie, the entry coming first in the list is chosen.
|
|
|
|
*
|
|
|
|
* @param allFiles a map describing all present files
|
|
|
|
* @param fileBasedFallback a list of ADFileBasedFallback records, zero-terminated
|
2011-06-10 20:13:51 +00:00
|
|
|
*/
|
2011-06-14 16:11:14 +00:00
|
|
|
const ADGameDescription *detectGameFilebased(const FileMap &allFiles, const ADFileBasedFallback *fileBasedFallback) const;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
2011-06-14 13:25:33 +00:00
|
|
|
// TODO
|
2011-06-10 20:13:51 +00:00
|
|
|
void updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose a hashmap of all files in fslist.
|
|
|
|
* Includes nifty stuff like removing trailing dots and ignoring case.
|
|
|
|
*/
|
2011-06-14 16:02:09 +00:00
|
|
|
void composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth) const;
|
2008-02-02 00:54:52 +00:00
|
|
|
};
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
#endif
|