AD: Restrict length of autogenerated targets

This commit is contained in:
Eugene Sandulenko 2020-10-21 19:13:12 +02:00
parent b9d1c7d95c
commit 1c830bc068
2 changed files with 15 additions and 6 deletions

View File

@ -74,12 +74,14 @@ private:
const AdvancedMetaEngineDetection::FileMap &_fileMap;
};
static Common::String sanitizeName(const char *name) {
static Common::String sanitizeName(const char *name, int maxLen) {
Common::String res;
while (*name) {
if (Common::isAlnum(*name))
while (*name && maxLen > 0) {
if (Common::isAlnum(*name)) {
res += tolower(*name);
maxLen--;
}
name++;
}
@ -92,11 +94,11 @@ static Common::String sanitizeName(const char *name) {
* or (if ADGF_DEMO has been set)
* GAMEID-demo-PLAFORM-LANG
*/
static Common::String generatePreferredTarget(const ADGameDescription *desc) {
static Common::String generatePreferredTarget(const ADGameDescription *desc, int maxLen) {
Common::String res;
if (desc->flags & ADGF_AUTOGENTARGET && desc->extra && *desc->extra) {
res = sanitizeName(desc->extra);
res = sanitizeName(desc->extra, maxLen);
} else {
res = desc->gameId;
}
@ -145,7 +147,7 @@ DetectedGame AdvancedMetaEngineDetection::toDetectedGame(const ADDetectedGame &a
DetectedGame game(getEngineId(), desc->gameId, title, desc->language, desc->platform, extra);
game.hasUnknownFiles = adGame.hasUnknownFiles;
game.matchedFiles = adGame.matchedFiles;
game.preferredTarget = generatePreferredTarget(desc);
game.preferredTarget = generatePreferredTarget(desc, _maxAutogenLength);
game.gameSupportLevel = kStableGame;
if (desc->flags & ADGF_UNSTABLE)
@ -672,6 +674,7 @@ AdvancedMetaEngineDetection::AdvancedMetaEngineDetection(const void *descs, uint
_maxScanDepth = 1;
_directoryGlobs = NULL;
_matchFullPaths = false;
_maxAutogenLength = 15;
}
void AdvancedMetaEngineDetection::initSubSystems(const ADGameDescription *gameDesc) const {

View File

@ -246,6 +246,12 @@ protected:
*/
bool _matchFullPaths;
/**
* If we use ADGF_AUTOGENTARGET, then this specifies the max length
* of the autogenerated name. The default is 15
*/
int _maxAutogenLength;
public:
AdvancedMetaEngineDetection(const void *descs, uint descItemSize, const PlainGameDescriptor *gameIds, const ADExtraGuiOptionsMap *extraGuiOptions = 0);