ENGINES: extend toDetectedGames to deal with ADDetectedGameExtraInfo.

This commit is contained in:
ysj1173886760 2021-06-10 21:35:32 +08:00 committed by Eugene Sandulenko
parent 6e3551049c
commit 65f36c33ff
3 changed files with 23 additions and 17 deletions

View File

@ -121,10 +121,12 @@ static Common::String sanitizeName(const char *name, int maxLen) {
* or (if ADGF_DEMO has been set)
* GAMEID-demo-PLAFORM-LANG
*/
static Common::String generatePreferredTarget(const ADGameDescription *desc, int maxLen) {
static Common::String generatePreferredTarget(const ADGameDescription *desc, int maxLen, Common::String targetID) {
Common::String res;
if (desc->flags & ADGF_AUTOGENTARGET && desc->extra && *desc->extra) {
if (!targetID.empty()) {
res = targetID;
} else if (desc->flags & ADGF_AUTOGENTARGET && desc->extra && *desc->extra) {
res = sanitizeName(desc->extra, maxLen);
} else {
res = desc->gameId;
@ -153,7 +155,7 @@ static Common::String generatePreferredTarget(const ADGameDescription *desc, int
return res;
}
DetectedGame AdvancedMetaEngineDetection::toDetectedGame(const ADDetectedGame &adGame) const {
DetectedGame AdvancedMetaEngineDetection::toDetectedGame(const ADDetectedGame &adGame, ADDetectedGameExtraInfo *extraInfo) const {
const ADGameDescription *desc = adGame.desc;
const char *title;
@ -171,10 +173,20 @@ DetectedGame AdvancedMetaEngineDetection::toDetectedGame(const ADDetectedGame &a
extra = desc->extra;
}
if (extraInfo) {
if (!extraInfo->gameName.empty())
title = extraInfo->gameName.c_str();
}
DetectedGame game(getEngineId(), desc->gameId, title, desc->language, desc->platform, extra, ((desc->flags & (ADGF_UNSUPPORTED | ADGF_WARNING)) != 0));
game.hasUnknownFiles = adGame.hasUnknownFiles;
game.matchedFiles = adGame.matchedFiles;
game.preferredTarget = generatePreferredTarget(desc, _maxAutogenLength);
if (extraInfo && !extraInfo->targetID.empty()) {
game.preferredTarget = generatePreferredTarget(desc, _maxAutogenLength, extraInfo->targetID);
} else {
game.preferredTarget = generatePreferredTarget(desc, _maxAutogenLength, Common::String());
}
game.gameSupportLevel = kStableGame;
if (desc->flags & ADGF_UNSTABLE)
@ -259,20 +271,14 @@ DetectedGames AdvancedMetaEngineDetection::detectGames(const Common::FSList &fsl
ADDetectedGame fallbackDetectionResult = fallbackDetect(allFiles, fslist, &extraInfo);
if (fallbackDetectionResult.desc) {
DetectedGame fallbackDetectedGame = toDetectedGame(fallbackDetectionResult);
fallbackDetectedGame.preferredTarget += "-fallback";
DetectedGame fallbackDetectedGame = toDetectedGame(fallbackDetectionResult, extraInfo);
// if we have extraInfo here
if (extraInfo != nullptr) {
// if we have specified game name or targetID, then we replace the original one
// maybe we need to use generatePreferredTarget to generate it
if (!extraInfo->gameName.empty())
fallbackDetectedGame.description = extraInfo->gameName;
if (!extraInfo->targetID.empty())
fallbackDetectedGame.preferredTarget = extraInfo->targetID;
// then it's our duty to free it
delete extraInfo;
} else {
// don't add fallback when we are specifying the targetID
fallbackDetectedGame.preferredTarget += "-fallback";
}
detectedGames.push_back(fallbackDetectedGame);

View File

@ -440,7 +440,7 @@ protected:
bool getFileProperties(const FileMap &allFiles, const ADGameDescription &game, const Common::String fname, FileProperties &fileProps) const;
/** Convert an AD game description into the shared game description format. */
virtual DetectedGame toDetectedGame(const ADDetectedGame &adGame) const;
virtual DetectedGame toDetectedGame(const ADDetectedGame &adGame, ADDetectedGameExtraInfo *extraInfo = nullptr) const;
/** Check for pirated games in the given detected games */
bool cleanupPirated(ADDetectedGames &matched) const;

View File

@ -102,12 +102,12 @@ public:
return "Myst and Riven (C) Cyan Worlds\nMohawk OS (C) Ubisoft";
}
DetectedGame toDetectedGame(const ADDetectedGame &adGame) const override;
DetectedGame toDetectedGame(const ADDetectedGame &adGame, ADDetectedGameExtraInfo *extraInfo) const override;
void registerDefaultSettings(const Common::String &target) const override;
};
DetectedGame MohawkMetaEngineDetection::toDetectedGame(const ADDetectedGame &adGame) const {
DetectedGame MohawkMetaEngineDetection::toDetectedGame(const ADDetectedGame &adGame, ADDetectedGameExtraInfo *extraInfo) const {
DetectedGame game = AdvancedMetaEngineDetection::toDetectedGame(adGame);
// The AdvancedDetector model only allows specifying a single supported