diff options
author | Cameron Cawley | 2018-12-19 06:31:26 +0000 |
---|---|---|
committer | Filippos Karapetis | 2018-12-19 08:31:26 +0200 |
commit | f6015086e18360659552ec4f7ca898f20fad1d16 (patch) | |
tree | 3f132ccbeb663e74d6b408c2ce2d608d3e2b27d8 | |
parent | e94ccdbe6b0d650e04872ee3cc68fe13272f81a4 (diff) | |
download | scummvm-rg350-f6015086e18360659552ec4f7ca898f20fad1d16.tar.gz scummvm-rg350-f6015086e18360659552ec4f7ca898f20fad1d16.tar.bz2 scummvm-rg350-f6015086e18360659552ec4f7ca898f20fad1d16.zip |
ENGINES: Add GUIErrorMessageFormat to replace duplicated functions (#1455)
-rw-r--r-- | engines/engine.cpp | 11 | ||||
-rw-r--r-- | engines/engine.h | 1 | ||||
-rw-r--r-- | engines/glk/glk.cpp | 12 | ||||
-rw-r--r-- | engines/glk/glk.h | 5 | ||||
-rw-r--r-- | engines/glk/glulxe/glulxe.cpp | 8 | ||||
-rw-r--r-- | engines/lure/lure.cpp | 18 | ||||
-rw-r--r-- | engines/lure/lure.h | 1 | ||||
-rw-r--r-- | engines/mortevielle/mortevielle.cpp | 9 | ||||
-rw-r--r-- | engines/supernova/supernova.cpp | 12 | ||||
-rw-r--r-- | engines/titanic/support/files_manager.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/titanic.cpp | 12 | ||||
-rw-r--r-- | engines/titanic/titanic.h | 5 | ||||
-rw-r--r-- | engines/tony/tony.cpp | 7 | ||||
-rw-r--r-- | engines/tony/tony.h | 1 | ||||
-rw-r--r-- | engines/xeen/files.cpp | 4 | ||||
-rw-r--r-- | engines/xeen/xeen.cpp | 12 | ||||
-rw-r--r-- | engines/xeen/xeen.h | 5 |
17 files changed, 31 insertions, 98 deletions
diff --git a/engines/engine.cpp b/engines/engine.cpp index 0e7f64f8a4..a06be61be2 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -399,6 +399,17 @@ void GUIErrorMessage(const Common::String &msg) { } } +void GUIErrorMessageFormat(const char *fmt, ...) { + Common::String msg; + + va_list va; + va_start(va, fmt); + msg = Common::String::vformat(fmt, va); + va_end(va); + + GUIErrorMessage(msg); +} + void Engine::checkCD() { #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) // It is a known bug under Windows that games that play CD audio cause diff --git a/engines/engine.h b/engines/engine.h index d3415d584c..d004c29f84 100644 --- a/engines/engine.h +++ b/engines/engine.h @@ -51,6 +51,7 @@ class Dialog; * Initializes graphics and shows error message. */ void GUIErrorMessage(const Common::String &msg); +void GUIErrorMessageFormat(const char *fmt, ...) GCC_PRINTF(1, 2); class Engine { diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp index d3e715a7fe..2525c0b1fa 100644 --- a/engines/glk/glk.cpp +++ b/engines/glk/glk.cpp @@ -145,18 +145,6 @@ Common::Error GlkEngine::run() { return Common::kNoError; } -void GlkEngine::GUIError(const char *msg, ...) { - char buffer[STRINGBUFLEN]; - va_list va; - - // Generate the full error message - va_start(va, msg); - vsnprintf(buffer, STRINGBUFLEN, msg, va); - va_end(va); - - GUIErrorMessage(buffer); -} - Common::Error GlkEngine::loadGame() { frefid_t ref = _streams->createByPrompt(fileusage_BinaryMode | fileusage_SavedGame, filemode_Read, 0); diff --git a/engines/glk/glk.h b/engines/glk/glk.h index 7460317fc0..55066e2cde 100644 --- a/engines/glk/glk.h +++ b/engines/glk/glk.h @@ -171,11 +171,6 @@ public: } /** - * Display a message in a GUI dialog - */ - void GUIError(const char *msg, ...); - - /** * Return the filename for a given save slot */ Common::String getSaveName(uint slot) const { diff --git a/engines/glk/glulxe/glulxe.cpp b/engines/glk/glulxe/glulxe.cpp index e2e1a477e5..aaa63b6141 100644 --- a/engines/glk/glulxe/glulxe.cpp +++ b/engines/glk/glulxe/glulxe.cpp @@ -52,23 +52,23 @@ Common::Error Glulxe::saveGameData(strid_t file, const Common::String &desc) { bool Glulxe::is_gamefile_valid() { if (_gameFile->size() < 8) { - GUIError(_("This is too short to be a valid Glulx file.")); + GUIErrorMessage(_("This is too short to be a valid Glulx file.")); return false; } if (_gameFile->readUint32BE() != MKTAG('G', 'l', 'u', 'l')) { - GUIError(_("This is not a valid Glulx file.")); + GUIErrorMessage(_("This is not a valid Glulx file.")); return false; } // We support version 2.0 through 3.1.* uint version = _gameFile->readUint32BE(); if (version < 0x20000) { - GUIError(_("This Glulx file is too old a version to execute.")); + GUIErrorMessage(_("This Glulx file is too old a version to execute.")); return false; } if (version >= 0x30200) { - GUIError(_("This Glulx file is too new a version to execute.")); + GUIErrorMessage(_("This Glulx file is too new a version to execute.")); return false; } diff --git a/engines/lure/lure.cpp b/engines/lure/lure.cpp index 13417b3251..6512caa049 100644 --- a/engines/lure/lure.cpp +++ b/engines/lure/lure.cpp @@ -61,7 +61,7 @@ Common::Error LureEngine::init() { Common::File f; VersionStructure version; if (!f.open(SUPPORT_FILENAME)) { - GUIError(_("Unable to locate the '%s' engine data file."), SUPPORT_FILENAME); + GUIErrorMessageFormat(_("Unable to locate the '%s' engine data file."), SUPPORT_FILENAME); return Common::kUnknownError; } @@ -70,10 +70,10 @@ Common::Error LureEngine::init() { f.close(); if (READ_LE_UINT16(&version.id) != 0xffff) { - GUIError(_("The '%s' engine data file is corrupt."), SUPPORT_FILENAME); + GUIErrorMessageFormat(_("The '%s' engine data file is corrupt."), SUPPORT_FILENAME); return Common::kUnknownError; } else if ((version.vMajor != LURE_DAT_MAJOR) || (version.vMinor != LURE_DAT_MINOR)) { - GUIError(_("Incorrect version of the '%s' engine data file found. Expected %d.%d but got %d.%d."), + GUIErrorMessageFormat(_("Incorrect version of the '%s' engine data file found. Expected %d.%d but got %d.%d."), SUPPORT_FILENAME, LURE_DAT_MAJOR, LURE_DAT_MINOR, version.vMajor, version.vMinor); return Common::kUnknownError; @@ -248,18 +248,6 @@ bool LureEngine::loadGame(uint8 slotNumber) { return true; } -void LureEngine::GUIError(const char *msg, ...) { - char buffer[STRINGBUFLEN]; - va_list va; - - // Generate the full error message - va_start(va, msg); - vsnprintf(buffer, STRINGBUFLEN, msg, va); - va_end(va); - - GUIErrorMessage(buffer); -} - GUI::Debugger *LureEngine::getDebugger() { return !Game::isCreated() ? NULL : &Game::getReference().debugger(); } diff --git a/engines/lure/lure.h b/engines/lure/lure.h index d395d00c03..dd9fb18f5b 100644 --- a/engines/lure/lure.h +++ b/engines/lure/lure.h @@ -111,7 +111,6 @@ public: bool saveGame(uint8 slotNumber, Common::String &caption); Common::String *detectSave(int slotNumber); uint8 saveVersion() { return _saveVersion; } - void GUIError(const char *msg, ...) GCC_PRINTF(2, 3); uint32 getFeatures() const; LureLanguage getLureLanguage() const; diff --git a/engines/mortevielle/mortevielle.cpp b/engines/mortevielle/mortevielle.cpp index 92d1ca8839..21e96e6766 100644 --- a/engines/mortevielle/mortevielle.cpp +++ b/engines/mortevielle/mortevielle.cpp @@ -303,8 +303,7 @@ Common::ErrorCode MortevielleEngine::loadMortDat() { // Open the mort.dat file if (!f.open(MORT_DAT)) { - Common::String msg = Common::String::format(_("Unable to locate the '%s' engine data file."), MORT_DAT); - GUIErrorMessage(msg); + GUIErrorMessageFormat(_("Unable to locate the '%s' engine data file."), MORT_DAT); return Common::kReadingFailed; } @@ -312,8 +311,7 @@ Common::ErrorCode MortevielleEngine::loadMortDat() { char fileId[4]; f.read(fileId, 4); if (strncmp(fileId, "MORT", 4) != 0) { - Common::String msg = Common::String::format(_("The '%s' engine data file is corrupt."), MORT_DAT); - GUIErrorMessage(msg); + GUIErrorMessageFormat(_("The '%s' engine data file is corrupt."), MORT_DAT); return Common::kReadingFailed; } @@ -322,10 +320,9 @@ Common::ErrorCode MortevielleEngine::loadMortDat() { int minVer = f.readByte(); if (majVer < MORT_DAT_REQUIRED_VERSION) { - Common::String msg = Common::String::format( + GUIErrorMessageFormat( _("Incorrect version of the '%s' engine data file found. Expected %d.%d but got %d.%d."), MORT_DAT, MORT_DAT_REQUIRED_VERSION, 0, majVer, minVer); - GUIErrorMessage(msg); return Common::kReadingFailed; } diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index c47e476de7..51512af7e6 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -172,8 +172,7 @@ Common::Error SupernovaEngine::loadGameStrings() { // strings anyway (actually the engine will even refuse to start). Common::File f; if (!f.open(SUPERNOVA_DAT)) { - Common::String msg = Common::String::format(_("Unable to locate the '%s' engine data file."), SUPERNOVA_DAT); - GUIErrorMessage(msg); + GUIErrorMessageFormat(_("Unable to locate the '%s' engine data file."), SUPERNOVA_DAT); return Common::kReadingFailed; } @@ -182,17 +181,15 @@ Common::Error SupernovaEngine::loadGameStrings() { id[4] = lang[4] = '\0'; f.read(id, 3); if (strncmp(id, "MSN", 3) != 0) { - Common::String msg = Common::String::format(_("The '%s' engine data file is corrupt."), SUPERNOVA_DAT); - GUIErrorMessage(msg); + GUIErrorMessageFormat(_("The '%s' engine data file is corrupt."), SUPERNOVA_DAT); return Common::kReadingFailed; } int version = f.readByte(); if (version != SUPERNOVA_DAT_VERSION) { - Common::String msg = Common::String::format( + GUIErrorMessageFormat( _("Incorrect version of the '%s' engine data file found. Expected %d but got %d."), SUPERNOVA_DAT, SUPERNOVA_DAT_VERSION, version); - GUIErrorMessage(msg); return Common::kReadingFailed; } @@ -217,8 +214,7 @@ Common::Error SupernovaEngine::loadGameStrings() { } Common::Language l = Common::parseLanguage(cur_lang); - Common::String msg = Common::String::format(_("Unable to locate the text for %s language in '%s' engine data file."), Common::getLanguageDescription(l), SUPERNOVA_DAT); - GUIErrorMessage(msg); + GUIErrorMessageFormat(_("Unable to locate the text for %s language in '%s' engine data file."), Common::getLanguageDescription(l), SUPERNOVA_DAT); return Common::kReadingFailed; } diff --git a/engines/titanic/support/files_manager.cpp b/engines/titanic/support/files_manager.cpp index 9a07b68e35..63fde3aaba 100644 --- a/engines/titanic/support/files_manager.cpp +++ b/engines/titanic/support/files_manager.cpp @@ -39,19 +39,19 @@ CFilesManager::~CFilesManager() { bool CFilesManager::loadResourceIndex() { if (!_datFile.open("titanic.dat")) { - g_vm->GUIError("Could not find titanic.dat data file"); + GUIErrorMessage("Could not find titanic.dat data file"); return false; } uint headerId = _datFile.readUint32BE(); _version = _datFile.readUint16LE(); if (headerId != MKTAG('S', 'V', 'T', 'N')) { - g_vm->GUIError("titanic.dat has invalid contents"); + GUIErrorMessage("titanic.dat has invalid contents"); return false; } if (_version != 5) { - g_vm->GUIError("titanic.dat is out of date"); + GUIErrorMessage("titanic.dat is out of date"); return false; } diff --git a/engines/titanic/titanic.cpp b/engines/titanic/titanic.cpp index 0931d91806..33184599fe 100644 --- a/engines/titanic/titanic.cpp +++ b/engines/titanic/titanic.cpp @@ -276,18 +276,6 @@ void TitanicEngine::syncSoundSettings() { } } -void TitanicEngine::GUIError(const char *msg, ...) { - char buffer[STRINGBUFLEN]; - va_list va; - - // Generate the full error message - va_start(va, msg); - vsnprintf(buffer, STRINGBUFLEN, msg, va); - va_end(va); - - GUIErrorMessage(buffer); -} - void TitanicEngine::showScummVMSaveDialog() { if (!canSaveGameStateCurrently()) diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h index 5efefe41bd..ce2188ed1e 100644 --- a/engines/titanic/titanic.h +++ b/engines/titanic/titanic.h @@ -196,11 +196,6 @@ public: CString getSavegameName(int slot); /** - * Displays an error message in a GUI dialog - */ - void GUIError(const char *msg, ...) GCC_PRINTF(2, 3); - - /** * Shows the ScummVM GMM save dialog */ void showScummVMSaveDialog(); diff --git a/engines/tony/tony.cpp b/engines/tony/tony.cpp index 8a7b676918..2d9e93c1da 100644 --- a/engines/tony/tony.cpp +++ b/engines/tony/tony.cpp @@ -281,13 +281,6 @@ void TonyEngine::initCustomFunctionMap() { INIT_CUSTOM_FUNCTION(_funcList, _funcListStrings); } -/** - * Display an error message - */ -void TonyEngine::GUIError(const Common::String &msg) { - GUIErrorMessage(msg); -} - void TonyEngine::playMusic(int nChannel, const Common::String &fname, int nFX, bool bLoop, int nSync) { if (nChannel < 4) { if (GLOBALS._flipflop) diff --git a/engines/tony/tony.h b/engines/tony/tony.h index fc47e1a1bf..cb9f5fe322 100644 --- a/engines/tony/tony.h +++ b/engines/tony/tony.h @@ -163,7 +163,6 @@ public: RMGfxEngine *getEngine() { return &_theEngine; } - void GUIError(const Common::String &msg); virtual bool canLoadGameStateCurrently(); virtual bool canSaveGameStateCurrently(); diff --git a/engines/xeen/files.cpp b/engines/xeen/files.cpp index ecac2c5b2b..284f91be2b 100644 --- a/engines/xeen/files.cpp +++ b/engines/xeen/files.cpp @@ -255,14 +255,14 @@ bool FileManager::setup() { // Ensure the custom CC archive is present File f; if (!f.exists("xeen.ccs")) { - g_vm->GUIError("Could not find xeen.ccs data file"); + GUIErrorMessage("Could not find xeen.ccs data file"); return false; } // Verify the version of the CC is correct CCArchive *dataCc = new CCArchive("xeen.ccs", "data", true); if (!f.open("VERSION", *dataCc) || f.readUint32LE() != 1) { - g_vm->GUIError("xeen.ccs is out of date"); + GUIErrorMessage("xeen.ccs is out of date"); return false; } SearchMan.add("data", dataCc); diff --git a/engines/xeen/xeen.cpp b/engines/xeen/xeen.cpp index 371f437172..1952dc16c0 100644 --- a/engines/xeen/xeen.cpp +++ b/engines/xeen/xeen.cpp @@ -310,18 +310,6 @@ void XeenEngine::syncSoundSettings() { _sound->updateSoundSettings(); } -void XeenEngine::GUIError(const char *msg, ...) { - char buffer[STRINGBUFLEN]; - va_list va; - - // Generate the full error message - va_start(va, msg); - vsnprintf(buffer, STRINGBUFLEN, msg, va); - va_end(va); - - GUIErrorMessage(buffer); -} - void XeenEngine::saveSettings() { if (_gameWon[0]) ConfMan.setBool("game_won", true); diff --git a/engines/xeen/xeen.h b/engines/xeen/xeen.h index 98b09e7f23..dfe2c79eec 100644 --- a/engines/xeen/xeen.h +++ b/engines/xeen/xeen.h @@ -218,11 +218,6 @@ public: int getRandomNumber(int minNumber, int maxNumber); /** - * Displays an error message in a GUI dialog - */ - void GUIError(const char *msg, ...) GCC_PRINTF(2, 3); - - /** * Returns true if the game should be exited (either quitting, exiting to the main menu, or loading a savegame) */ bool shouldExit() const { return _gameMode != GMODE_NONE || isLoadPending() || shouldQuit(); } |