From 5d31775d6c38cd950a380099da975601cc701b09 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Mon, 27 Apr 2020 10:16:53 -0400 Subject: [PATCH] Convert to std::array and std::string. (mythgame) --- mythplugins/mythgame/mythgame/gamehandler.cpp | 2 +- .../mythgame/mythgame/gamesettings.cpp | 8 +++----- .../mythgame/mythgame/rom_metadata.cpp | 20 +++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/mythplugins/mythgame/mythgame/gamehandler.cpp b/mythplugins/mythgame/mythgame/gamehandler.cpp index fa8e6eef16c..d1f70a4a107 100644 --- a/mythplugins/mythgame/mythgame/gamehandler.cpp +++ b/mythplugins/mythgame/mythgame/gamehandler.cpp @@ -871,7 +871,7 @@ void GameHandler::Launchgame(RomInfo *romdata, const QString& systemname) QString basename = romdata->Romname().left(romdata->Romname().length() - (romdata->getExtension().length() + 2)); QString extension = romdata->getExtension(); QString rom; - QString diskid[] = { "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6" }; + std::array diskid { "%d0", "%d1", "%d2", "%d3", "%d4", "%d5", "%d6" }; for (int disk = 1; disk <= romdata->DiskCount(); disk++) { diff --git a/mythplugins/mythgame/mythgame/gamesettings.cpp b/mythplugins/mythgame/mythgame/gamesettings.cpp index 33e54335aa4..1aaa61e22d9 100644 --- a/mythplugins/mythgame/mythgame/gamesettings.cpp +++ b/mythplugins/mythgame/mythgame/gamesettings.cpp @@ -11,10 +11,8 @@ struct GameTypes { QString m_extensions; }; -#define MAX_GAME_TYPES 12 - -const GameTypes GameTypeList[MAX_GAME_TYPES] = -{ +const std::array GameTypeList +{{ { QT_TRANSLATE_NOOP("(GameTypes)", "OTHER"), "OTHER", "" }, { QT_TRANSLATE_NOOP("(GameTypes)", "AMIGA"), "AMIGA", "adf,ipf" }, { QT_TRANSLATE_NOOP("(GameTypes)", "ATARI"), "ATARI", "bin,a26" }, @@ -27,7 +25,7 @@ const GameTypes GameTypeList[MAX_GAME_TYPES] = { QT_TRANSLATE_NOOP("(GameTypes)", "PCE/TG16"),"PCE", "pce" }, { QT_TRANSLATE_NOOP("(GameTypes)", "SEGA/MASTER SYSTEM"), "SEGA", "sms" }, { QT_TRANSLATE_NOOP("(GameTypes)", "SNES"), "SNES", "zip,smc,sfc,fig,swc" } -}; +}}; QString GetGameTypeName(const QString &GameType) { diff --git a/mythplugins/mythgame/mythgame/rom_metadata.cpp b/mythplugins/mythgame/mythgame/rom_metadata.cpp index e79138bd4ee..e9e28e15bbe 100644 --- a/mythplugins/mythgame/mythgame/rom_metadata.cpp +++ b/mythplugins/mythgame/mythgame/rom_metadata.cpp @@ -51,7 +51,7 @@ static QString crcStr(uLong crc) QString crcinfo(const QString& romname, const QString& GameType, QString *key, RomDBMap *romDB) { // Get CRC of file - char block[32768] = ""; + std::array block {}; uLong crc = crc32(0, Z_NULL, 0); QString crcRes; unz_file_info file_info {}; @@ -70,24 +70,24 @@ QString crcinfo(const QString& romname, const QString& GameType, QString *key, R { if (unzOpenCurrentFile(zf) == UNZ_OK) { - char filename_inzip[256]; - unzGetCurrentFileInfo(zf,&file_info,filename_inzip,sizeof(filename_inzip),nullptr,0,nullptr,0); + std::string filename_inzip(256,'\0'); + unzGetCurrentFileInfo(zf,&file_info,filename_inzip.data(),filename_inzip.size(),nullptr,0,nullptr,0); int offset = calcOffset(GameType, file_info.uncompressed_size); if (offset > 0) - unzReadCurrentFile(zf, block, offset); + unzReadCurrentFile(zf, block.data(), offset); // Get CRC of rom data int count = 0; - while ((count = unzReadCurrentFile(zf, block, blocksize)) > 0) + while ((count = unzReadCurrentFile(zf, block.data(), blocksize)) > 0) { - crc = crc32(crc, (Bytef *)block, (uInt)count); + crc = crc32(crc, (Bytef *)block.data(), (uInt)count); } crcRes = crcStr(crc); *key = QString("%1:%2") .arg(crcRes) - .arg(filename_inzip); + .arg(filename_inzip.data()); if (romDB->contains(*key)) { @@ -109,13 +109,13 @@ QString crcinfo(const QString& romname, const QString& GameType, QString *key, R int offset = calcOffset(GameType, f.size()); if (offset > 0) - f.read(block, offset); + f.read(block.data(), offset); // Get CRC of rom data qint64 count = 0; - while ((count = f.read(block, blocksize)) > 0) + while ((count = f.read(block.data(), blocksize)) > 0) { - crc = crc32(crc, (Bytef *)block, (uInt)count); + crc = crc32(crc, (Bytef *)block.data(), (uInt)count); } crcRes = crcStr(crc);