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-04-15 21:20:16 +00:00
*
2021-12-26 18:47:58 +01: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 3 of the License , or
* ( at your option ) any later version .
2014-02-18 02:34:20 +01:00
*
2006-04-15 21:20:16 +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 02:34:20 +01:00
*
2006-04-15 21:20:16 +00:00
* You should have received a copy of the GNU General Public License
2021-12-26 18:47:58 +01:00
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
2006-04-15 21:20:16 +00:00
*
*/
2008-09-17 17:31:29 +00:00
# ifndef ENGINES_GAME_H
# define ENGINES_GAME_H
2006-04-15 21:20:16 +00:00
2006-11-12 03:23:29 +00:00
# include "common/array.h"
2007-01-20 21:27:57 +00:00
# include "common/hash-str.h"
2011-04-24 11:34:27 +03:00
# include "common/str.h"
2020-07-21 04:24:04 +05:30
# include "common/ustr.h"
2019-04-27 02:34:48 +01:00
# include "common/str-array.h"
2012-02-22 21:03:17 +01:00
# include "common/language.h"
# include "common/platform.h"
2008-02-04 10:15:21 +00:00
2020-11-21 02:20:41 +01:00
/**
* @ defgroup engines_game Games
* @ ingroup engines
*
* @ brief API for managing games by engines .
*
* @ {
*/
2007-06-15 17:13:13 +00:00
/**
* A simple structure used to map gameids ( like " monkey " , " sword1 " , . . . ) to
* nice human readable and descriptive game titles ( like " The Secret of Monkey Island " ) .
* This is a plain struct to make it possible to declare NULL - terminated C arrays
* consisting of PlainGameDescriptors .
*/
2006-04-15 21:20:16 +00:00
struct PlainGameDescriptor {
2016-03-08 18:59:23 +01:00
const char * gameId ;
2007-06-15 17:13:13 +00:00
const char * description ;
2018-05-06 12:57:08 +02:00
2018-05-10 09:26:26 +02:00
static PlainGameDescriptor empty ( ) ;
static PlainGameDescriptor of ( const char * gameId , const char * description ) ;
2006-04-15 21:20:16 +00:00
} ;
2007-06-15 17:13:13 +00:00
/**
* Given a list of PlainGameDescriptors , returns the first PlainGameDescriptor
* matching the given gameid . If not match is found return 0.
2011-06-11 17:57:16 +02:00
* The end of the list must be marked by an entry with gameid 0.
2007-06-15 17:13:13 +00:00
*/
const PlainGameDescriptor * findPlainGameDescriptor ( const char * gameid , const PlainGameDescriptor * list ) ;
2018-05-06 13:09:52 +02:00
class PlainGameList : public Common : : Array < PlainGameDescriptor > {
public :
PlainGameList ( ) { }
PlainGameList ( const PlainGameList & list ) : Common : : Array < PlainGameDescriptor > ( list ) { }
PlainGameList ( const PlainGameDescriptor * g ) {
while ( g - > gameId ) {
push_back ( * g ) ;
g + + ;
}
}
} ;
2016-09-25 08:45:42 +02:00
/**
* The description of a game supported by an engine
*/
2020-01-01 08:19:48 +01:00
struct QualifiedGameDescriptor {
Common : : String engineId ;
Common : : String gameId ;
Common : : String description ;
2016-09-25 08:45:42 +02:00
2020-01-01 08:19:48 +01:00
QualifiedGameDescriptor ( ) { }
2016-09-25 08:45:42 +02:00
QualifiedGameDescriptor ( const char * engine , const PlainGameDescriptor & pgd ) ;
} ;
typedef Common : : Array < QualifiedGameDescriptor > QualifiedGameList ;
2011-04-25 15:26:38 -05:00
/**
* Ths is an enum to describe how done a game is . This also indicates what level of support is expected .
*/
enum GameSupportLevel {
2021-04-16 13:28:43 +02:00
kStableGame = 0 , // the game is fully supported
kTestingGame , // the game is not supposed to end up in releases yet but is ready for public testing
kUnstableGame , // the game is not even ready for public testing yet
2021-04-16 14:14:40 +02:00
kUnsupportedGame , // we don't want to support the game
kWarningGame // we want to ask user to proceed and provide them with an explanation
2011-04-25 15:26:38 -05:00
} ;
2021-11-06 14:18:33 +02:00
/**
* This enum is used to indicate the method of MD5 calculation used for a particular file .
* The result is used for the more fine tuned reporting of unknown MD5s
*/
enum MD5Properties {
2023-08-07 02:48:46 +03:00
kMD5Head = 0 < < 1 , // the MD5 is calculated from the head, default
kMD5Tail = 1 < < 1 , // the MD5 is calculated from the tail
2022-12-19 23:01:20 +01:00
kMD5MacResFork = 1 < < 2 , // the MD5 is calculated from the Mac Resource fork (no fall back) (head or tail)
kMD5MacDataFork = 1 < < 3 , // the MD5 is calculated from the Mac Data fork (head or tail)
kMD5MacResOrDataFork = kMD5MacResFork | kMD5MacDataFork , // the MD5 is calculated from the Mac Resource fork falling back to data fork (head or tail). Deprecated.
kMD5MacMask = kMD5MacResFork | kMD5MacDataFork , // Mask for mac type
2023-08-07 02:48:46 +03:00
kMD5Archive = 1 < < 4 , // the desired file is inside an archive
2021-11-06 14:18:33 +02:00
} ;
2006-11-12 03:23:29 +00:00
2023-08-29 19:20:18 +03:00
Common : : String md5PropToCachePrefix ( MD5Properties val ) ;
2022-12-19 22:29:08 +01:00
2017-12-02 17:14:22 +01:00
/**
* A record describing the properties of a file . Used on the existing
* files while detecting a game .
*/
struct FileProperties {
2021-07-03 21:38:40 -07:00
int64 size ;
2017-12-02 17:14:22 +01:00
Common : : String md5 ;
2021-11-06 14:18:33 +02:00
MD5Properties md5prop ;
2017-12-02 17:14:22 +01:00
2021-11-06 14:18:33 +02:00
FileProperties ( ) : size ( - 1 ) , md5prop ( kMD5Head ) { }
2017-12-02 17:14:22 +01:00
} ;
/**
* A map of all relevant existing files while detecting .
*/
typedef Common : : HashMap < Common : : String , FileProperties , Common : : IgnoreCase_Hash , Common : : IgnoreCase_EqualTo > FilePropertiesMap ;
2018-05-06 15:51:03 +02:00
/**
* Details about a given game .
*
* While PlainGameDescriptor refers to a game supported by an engine , this refers to a game copy
* that has been detected by an engine ' s detector .
* It contains all the necessary data to add the game to the configuration manager and / or to launch it .
*/
2017-12-02 17:14:22 +01:00
struct DetectedGame {
2018-05-06 15:51:03 +02:00
DetectedGame ( ) ;
2016-09-15 18:39:45 +02:00
DetectedGame ( const Common : : String & engine , const PlainGameDescriptor & pgd ) ;
DetectedGame ( const Common : : String & engine , const Common : : String & id ,
2023-08-07 02:48:46 +03:00
const Common : : String & description ,
Common : : Language language = Common : : UNK_LANG ,
Common : : Platform platform = Common : : kPlatformUnknown ,
const Common : : String & extra = Common : : String ( ) ,
bool unsupported = false ) ;
2018-05-06 15:51:03 +02:00
void setGUIOptions ( const Common : : String & options ) ;
void appendGUIOptions ( const Common : : String & str ) ;
2020-03-26 10:55:08 +01:00
const Common : : String & getGUIOptions ( ) const { return _guiOptions ; }
2018-05-06 15:51:03 +02:00
2016-09-15 18:39:45 +02:00
Common : : String engineId ;
2017-12-02 17:14:22 +01:00
/**
* A game was detected , but some files were not recognized
*
* This can happen when the md5 or size of the detected files did not match the engine ' s detection tables .
* When this is true , the list of matched files below contains detail about the unknown files .
*
* @ see matchedFiles
*/
bool hasUnknownFiles ;
/**
* An optional list of the files that were used to match the game with the engine ' s detection tables
*/
FilePropertiesMap matchedFiles ;
/**
* This detection entry contains enough data to add the game to the configuration manager and launch it
*
* @ see matchedGame
*/
bool canBeAdded ;
2018-05-06 15:51:03 +02:00
Common : : String gameId ;
Common : : String preferredTarget ;
Common : : String description ;
Common : : Language language ;
Common : : Platform platform ;
Common : : String path ;
2019-05-03 20:48:06 +02:00
Common : : String shortPath ;
2018-05-06 15:51:03 +02:00
Common : : String extra ;
/**
* What level of support is expected of this game
*/
GameSupportLevel gameSupportLevel ;
2018-10-17 22:44:45 -07:00
/**
* A list of extra keys to write to the configuration file
*/
Common : : StringMap _extraConfigEntries ;
/**
* Allows adding of extra entries to be saved as part of the detection entry
* in the configuration file .
* @ remarks Any entry added using this should not be relied on being present
* in the configuration file , since starting games directly from the
* command line bypasses the game detection code
*/
void addExtraEntry ( const Common : : String & key , const Common : : String & value ) {
_extraConfigEntries [ key ] = value ;
}
2018-05-06 15:51:03 +02:00
private :
2017-12-02 17:14:22 +01:00
/**
2018-05-06 15:51:03 +02:00
* Update the description string by appending ( EXTRA / PLATFORM / LANG ) to it .
* Values that are missing are omitted , so e . g . ( EXTRA / LANG ) would be
* added if no platform has been specified but a language and an extra string .
2017-12-02 17:14:22 +01:00
*/
2020-11-08 20:05:35 +01:00
Common : : String updateDesc ( bool skipExtraField ) const ;
2017-12-02 17:14:22 +01:00
2018-05-06 15:51:03 +02:00
Common : : String _guiOptions ;
2017-12-02 17:14:22 +01:00
} ;
2018-05-06 15:51:03 +02:00
/** List of games. */
2017-12-02 17:14:22 +01:00
typedef Common : : Array < DetectedGame > DetectedGames ;
/**
* Contains a list of games found by the engines ' detectors .
*
* Each detected game can either :
* - be fully recognized ( e . g . an exact match was found in the detection tables of an engine )
* - be an unknown variant ( e . g . a game using files with the same name was found in the detection tables )
* - be recognized with unknown files ( e . g . the game was exactly not found in the detection tables ,
* but the detector was able to gather enough data to allow launching the game )
*
* Practically , this means a detected game can be in both the recognized game list and in the unknown game
* report handled by this class .
*/
class DetectionResults {
public :
explicit DetectionResults ( const DetectedGames & detectedGames ) ;
/**
* List all the games that were recognized by the engines
*
* Recognized games can be added to the configuration manager and then launched .
*/
2019-04-27 02:34:48 +01:00
DetectedGames listRecognizedGames ( ) const ;
2017-12-02 17:14:22 +01:00
2019-05-03 20:48:06 +02:00
/**
* List all the games that were detected
*
* That includes entries that don ' t have enough information to be added to the
* configuration manager .
*/
DetectedGames listDetectedGames ( ) const ;
2017-12-02 17:14:22 +01:00
/**
* Were unknown game variants found by the engines ?
*
* When unknown game variants are found , an unknown game report can be generated .
*/
bool foundUnknownGames ( ) const ;
/**
2019-05-03 20:48:06 +02:00
* Generate a report that we found an unknown game variant .
2017-12-02 17:14:22 +01:00
*
2019-05-03 20:48:06 +02:00
* @ see : : generateUnknownGameReport
2017-12-02 17:14:22 +01:00
*/
2020-07-21 04:24:04 +05:30
Common : : U32String generateUnknownGameReport ( bool translate , uint32 wordwrapAt = 0 ) const ;
2017-12-02 17:14:22 +01:00
private :
DetectedGames _detectedGames ;
} ;
2019-05-03 20:48:06 +02:00
/**
* Generate a report that we found an unknown game variant , together with the file
* names , sizes and MD5 sums .
*
* @ param translate translate the report to the currently active GUI language
* @ param fullPath include the full path where the files are located , otherwise only the name
* of last component of the path is included
* @ param wordwrapAt word wrap the text part of the report after a number of characters
*/
2020-07-21 04:24:04 +05:30
Common : : U32String generateUnknownGameReport ( const DetectedGames & detectedGames , bool translate , bool fullPath , uint32 wordwrapAt = 0 ) ;
Common : : U32String generateUnknownGameReport ( const DetectedGame & detectedGame , bool translate , bool fullPath , uint32 wordwrapAt = 0 ) ;
2020-11-21 02:20:41 +01:00
/** @} */
2006-04-15 21:20:16 +00:00
# endif