ENGINES: Add GUIErrorMessageFormat to replace duplicated functions (#1455)
This commit is contained in:
parent
e94ccdbe6b
commit
f6015086e1
17 changed files with 31 additions and 98 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -170,11 +170,6 @@ public:
|
|||
return _targetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a message in a GUI dialog
|
||||
*/
|
||||
void GUIError(const char *msg, ...);
|
||||
|
||||
/**
|
||||
* Return the filename for a given save slot
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -195,11 +195,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
|
||||
*/
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -163,7 +163,6 @@ public:
|
|||
RMGfxEngine *getEngine() {
|
||||
return &_theEngine;
|
||||
}
|
||||
void GUIError(const Common::String &msg);
|
||||
|
||||
virtual bool canLoadGameStateCurrently();
|
||||
virtual bool canSaveGameStateCurrently();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -217,11 +217,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)
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue