diff options
-rw-r--r-- | engines/glk/alan2/alan2.cpp | 50 | ||||
-rw-r--r-- | engines/glk/alan2/alan2.h | 7 | ||||
-rw-r--r-- | engines/glk/alan2/main.cpp | 17 |
3 files changed, 25 insertions, 49 deletions
diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp index 7d5040ca67..f9077c9f7a 100644 --- a/engines/glk/alan2/alan2.cpp +++ b/engines/glk/alan2/alan2.cpp @@ -46,15 +46,18 @@ Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, g void Alan2::runGame() { Common::String gameFileName = _gameFile.getName(); - if (!is_gamefile_valid()) + if (!initialize()) return; - initialize(); - Glk::Alan2::run(); } -void Alan2::initialize() { +bool Alan2::initialize() { + // Set up adventure name + _advName = getFilename(); + if (_advName.size() > 4 && _advName[_advName.size() - 4] == '.') + _advName = Common::String(_advName.c_str(), _advName.size() - 4); + // first, open a window for error output glkMainWin = g_vm->glk_window_open(0, 0, 0, wintype_TextBuffer, 0); if (glkMainWin == nullptr) @@ -70,10 +73,25 @@ void Alan2::initialize() { strncpy(codfnm, getFilename().c_str(), 255); codfnm[255] = '\0'; + if (_gameFile.size() < 8) { + GUIErrorMessage(_("This is too short to be a valid Alan2 file.")); + return false; + } + + if (_gameFile.readUint32BE() != MKTAG(2, 8, 1, 0)) { + GUIErrorMessage(_("This is not a valid Alan2 file.")); + return false; + } + // Open up the text file txtfil = new Common::File(); - if (!txtfil->open(Common::String::format("%s.dat", advnam))) - ::error("Could not open adventure text data file"); + if (!txtfil->open(Common::String::format("%s.dat", _advName.c_str()))) { + GUIErrorMessage("Could not open adventure text data file"); + delete txtfil; + return false; + } + + return true; } Common::Error Alan2::readSaveData(Common::SeekableReadStream *rs) { @@ -149,25 +167,5 @@ void Alan2::synchronizeSave(Common::Serializer &s) { syncVal(s, &scores[i]); } -bool Alan2::is_gamefile_valid() { - // Set up adventure name - _advName = getFilename(); - while (_advName.contains('.')) - _advName.deleteLastChar(); - advnam = _advName.c_str(); - - if (_gameFile.size() < 8) { - GUIErrorMessage(_("This is too short to be a valid Alan2 file.")); - return false; - } - - if (_gameFile.readUint32BE() != MKTAG(2, 8, 1, 0)) { - GUIErrorMessage(_("This is not a valid Alan2 file.")); - return false; - } - - return Common::File::exists(Common::String::format("%s.dat", advnam)); -} - } // End of namespace Alan2 } // End of namespace Glk diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h index 9d007d0bde..413800cd90 100644 --- a/engines/glk/alan2/alan2.h +++ b/engines/glk/alan2/alan2.h @@ -42,14 +42,9 @@ public: Common::String _advName; private: /** - * Validates the game file, and if it's invalid, displays an error dialog - */ - bool is_gamefile_valid(); - - /** * Initialization */ - void initialize(); + bool initialize(); /** * Synchronize data to or from a save file diff --git a/engines/glk/alan2/main.cpp b/engines/glk/alan2/main.cpp index 1371ace2e1..58c483a852 100644 --- a/engines/glk/alan2/main.cpp +++ b/engines/glk/alan2/main.cpp @@ -1376,23 +1376,6 @@ static void movactor(CONTEXT) { */ static void openFiles() { - { - char *s = strrchr(codfnm, '\\'); - if (!s) s = strrchr(codfnm, '/'); - g_vm->garglk_set_story_name(s ? s + 1 : codfnm); - } - - // Open Text file - strcpy(txtfnm, advnam); - strcat(txtfnm, ".dat"); - - Common::File *f = new Common::File(); - if (!f->open(txtfnm)) { - delete f; - Common::String s = Common::String::format("Can't open adventure text data file '%s'.", txtfnm); - ::error("%s", s.c_str()); - } - // If logging open log file if (logflg) { sprintf(logfnm, "%s.log", advnam); |