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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2006-10-02 22:21:57 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2006-10-02 22:21:57 +00:00
|
|
|
* 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
|
|
|
|
2012-06-27 02:07:32 +00:00
|
|
|
#include "common/hash-str.h"
|
|
|
|
|
2012-02-22 14:33:29 +00:00
|
|
|
#include "common/gui_options.h" // FIXME: Temporary hack?
|
|
|
|
|
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 {
|
2018-04-28 22:16:42 +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 {
|
2018-04-28 22:16:42 +00:00
|
|
|
ADGF_NO_FLAGS = 0,
|
|
|
|
ADGF_AUTOGENTARGET = (1 << 20), ///< automatically generate gameid from extra
|
|
|
|
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
|
|
|
|
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
|
2011-06-14 15:13:02 +00:00
|
|
|
ADGF_USEEXTRAASTITLE = (1 << 26), ///< Extra field value will be used as main game title, not gameid
|
2018-04-28 22:16:42 +00:00
|
|
|
ADGF_DROPLANGUAGE = (1 << 27), ///< don't add language to gameid
|
|
|
|
ADGF_DROPPLATFORM = (1 << 28), ///< don't add platform 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 {
|
2016-03-08 17:53:55 +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
|
|
|
|
2016-03-08 17:53:55 +00:00
|
|
|
const char *guiOptions;
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2011-06-10 20:13:51 +00:00
|
|
|
/**
|
2017-12-02 16:14:22 +00:00
|
|
|
* A game installation matching an AD game description
|
2011-06-10 20:13:51 +00:00
|
|
|
*/
|
2017-12-02 16:14:22 +00:00
|
|
|
struct ADDetectedGame {
|
|
|
|
bool hasUnknownFiles;
|
|
|
|
FilePropertiesMap matchedFiles;
|
|
|
|
const ADGameDescription *desc;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
2017-12-02 16:14:22 +00:00
|
|
|
ADDetectedGame() : desc(nullptr), hasUnknownFiles(false) {}
|
|
|
|
explicit ADDetectedGame(const ADGameDescription *d) : desc(d), hasUnknownFiles(false) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** A list of games detected by the AD */
|
|
|
|
typedef Common::Array<ADDetectedGame> ADDetectedGames;
|
2017-10-08 04:18: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 \
|
2011-11-16 21:38:58 +00:00
|
|
|
{ NULL, NULL, { { NULL, 0, NULL, 0 } }, Common::UNK_LANG, Common::kPlatformUnknown, ADGF_NO_FLAGS, GUIO0() }
|
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
|
|
|
|
2012-02-29 15:48:25 +00:00
|
|
|
/**
|
|
|
|
* Map entry for mapping GUIO_GAMEOPTIONS* to their ExtraGuiOption
|
|
|
|
* description.
|
|
|
|
*/
|
|
|
|
struct ADExtraGuiOptionsMap {
|
|
|
|
/**
|
|
|
|
* GUIO_GAMEOPTION* string.
|
|
|
|
*/
|
|
|
|
const char *guioFlag;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The associated option.
|
|
|
|
*/
|
|
|
|
ExtraGuiOption option;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define AD_EXTRA_GUI_OPTIONS_TERMINATOR { 0, { 0, 0, 0, 0 } }
|
|
|
|
|
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.
|
|
|
|
*/
|
2016-03-08 17:30:58 +00:00
|
|
|
const PlainGameDescriptor *_gameIds;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
2012-02-29 15:48:25 +00:00
|
|
|
/**
|
|
|
|
* A map containing all the extra game GUI options the engine supports.
|
2012-09-26 02:17:31 +00:00
|
|
|
*/
|
2012-02-29 15:48:25 +00:00
|
|
|
const ADExtraGuiOptionsMap * const _extraGuiOptions;
|
|
|
|
|
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).
|
|
|
|
*
|
2012-02-29 12:13:28 +00:00
|
|
|
* Used to override gameid.
|
|
|
|
* This is a recommended setting to prevent global gameid pollution.
|
2012-09-26 02:17:31 +00:00
|
|
|
* With this option set, the gameid effectively turns into engineid.
|
2012-02-28 09:13:40 +00:00
|
|
|
*
|
2012-02-29 12:13:28 +00:00
|
|
|
* FIXME: This field actually removes a feature (gameid) in order to
|
|
|
|
* address a more generic problem. We should find a better way to
|
|
|
|
* disambiguate gameids.
|
2007-02-13 22:25:25 +00:00
|
|
|
*/
|
2016-03-08 17:30:58 +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
|
|
|
|
|
|
|
/**
|
2011-10-23 14:14:41 +00:00
|
|
|
* A list of game GUI options which will be added to each
|
2009-06-06 17:56:41 +00:00
|
|
|
* entry in addition to per-game options. Refer to GameGUIOption
|
|
|
|
* enum for the list.
|
|
|
|
*/
|
2016-03-08 17:30:58 +00:00
|
|
|
Common::String _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
|
|
|
|
2017-05-21 20:31:37 +00:00
|
|
|
/**
|
|
|
|
* If true, filenames will be matched against the entire path, relative to
|
|
|
|
* the root detection directory (e.g. "foo/bar.000" for a file at
|
|
|
|
* "<root>/foo/bar.000"). Otherwise, filenames only match the basename
|
|
|
|
* (e.g. "bar.000" for the same file).
|
|
|
|
*
|
|
|
|
* @note _maxScanDepth and _directoryGlobs must still be configured to allow
|
|
|
|
* the detector to find files inside subdirectories.
|
|
|
|
*/
|
|
|
|
bool _matchFullPaths;
|
|
|
|
|
2008-02-02 00:54:52 +00:00
|
|
|
public:
|
2016-03-08 17:30:58 +00:00
|
|
|
AdvancedMetaEngine(const void *descs, uint descItemSize, const PlainGameDescriptor *gameIds, const ADExtraGuiOptionsMap *extraGuiOptions = 0);
|
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
|
|
|
|
2016-03-08 17:30:58 +00:00
|
|
|
virtual GameDescriptor findGame(const char *gameId) const;
|
2011-06-10 20:13:51 +00:00
|
|
|
|
2017-12-02 16:14:22 +00:00
|
|
|
DetectedGames detectGames(const Common::FSList &fslist) const override;
|
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
|
|
|
|
2012-02-29 15:48:25 +00:00
|
|
|
virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const;
|
|
|
|
|
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
|
|
|
*/
|
2017-12-02 16:14:22 +00:00
|
|
|
virtual ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
|
|
|
|
return ADDetectedGame();
|
2008-03-14 13:59:31 +00:00
|
|
|
}
|
2011-06-10 13:56:56 +00:00
|
|
|
|
2013-05-16 21:18:09 +00:00
|
|
|
private:
|
|
|
|
void initSubSystems(const ADGameDescription *gameDesc) const;
|
|
|
|
|
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
|
|
|
*/
|
2017-12-02 16:14:22 +00:00
|
|
|
virtual ADDetectedGames 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
|
2012-06-27 02:42:36 +00:00
|
|
|
* @param fslist a list of nodes for all present files
|
2011-06-14 15:32:13 +00:00
|
|
|
* @param fileBasedFallback a list of ADFileBasedFallback records, zero-terminated
|
2012-06-27 02:42:36 +00:00
|
|
|
* @param filesProps if not 0, return a map of properties for all detected files here
|
2011-06-10 20:13:51 +00:00
|
|
|
*/
|
2017-12-02 16:14:22 +00:00
|
|
|
ADDetectedGame detectGameFilebased(const FileMap &allFiles, const Common::FSList &fslist, const ADFileBasedFallback *fileBasedFallback) const;
|
2012-06-27 02:48:57 +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.
|
|
|
|
*/
|
2017-05-21 20:31:37 +00:00
|
|
|
void composeFileHashMap(FileMap &allFiles, const Common::FSList &fslist, int depth, const Common::String &parentName = Common::String()) const;
|
2012-06-27 02:25:38 +00:00
|
|
|
|
|
|
|
/** Get the properties (size and MD5) of this file. */
|
2017-12-02 16:14:22 +00:00
|
|
|
bool getFileProperties(const Common::FSNode &parent, const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const;
|
|
|
|
|
|
|
|
/** Convert an AD game description into the shared game description format */
|
|
|
|
DetectedGame toDetectedGame(const ADDetectedGame &adGame) const;
|
2008-02-02 00:54:52 +00:00
|
|
|
};
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
#endif
|