[Scummvm-git-logs] scummvm master -> f6015086e18360659552ec4f7ca898f20fad1d16

bluegr bluegr at gmail.com
Wed Dec 19 07:31:29 CET 2018


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f6015086e1 ENGINES: Add GUIErrorMessageFormat to replace duplicated functions (#1455)


Commit: f6015086e18360659552ec4f7ca898f20fad1d16
    https://github.com/scummvm/scummvm/commit/f6015086e18360659552ec4f7ca898f20fad1d16
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2018-12-19T08:31:26+02:00

Commit Message:
ENGINES: Add GUIErrorMessageFormat to replace duplicated functions (#1455)

Changed paths:
    engines/engine.cpp
    engines/engine.h
    engines/glk/glk.cpp
    engines/glk/glk.h
    engines/glk/glulxe/glulxe.cpp
    engines/lure/lure.cpp
    engines/lure/lure.h
    engines/mortevielle/mortevielle.cpp
    engines/supernova/supernova.cpp
    engines/titanic/support/files_manager.cpp
    engines/titanic/titanic.cpp
    engines/titanic/titanic.h
    engines/tony/tony.cpp
    engines/tony/tony.h
    engines/xeen/files.cpp
    engines/xeen/xeen.cpp
    engines/xeen/xeen.h


diff --git a/engines/engine.cpp b/engines/engine.cpp
index 0e7f64f..a06be61 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 d3415d5..d004c29 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 d3e715a..2525c0b 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 7460317..55066e2 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 e2e1a47..aaa63b6 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 13417b3..6512caa 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 d395d00..dd9fb18 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 92d1ca8..21e96e6 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 c47e476..51512af 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 9a07b68..63fde3a 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 0931d91..3318459 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 5efefe4..ce2188e 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 8a7b676..2d9e93c 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 fc47e1a..cb9f5fe 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 ecac2c5..284f91b 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 371f437..1952dc1 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 98b09e7..dfe2c79 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(); }





More information about the Scummvm-git-logs mailing list