aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/alan2/alan2.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2019-06-23 15:27:57 -0700
committerPaul Gilbert2019-06-23 16:19:42 -0700
commite7fbd9268c9bd4a21a9f4741d4636c722368847c (patch)
treeb86649beaebfc3d0b6facf9c4ce7fb707df095c4 /engines/glk/alan2/alan2.cpp
parent16f8c024d1dfba31e9f764818936384a429ac663 (diff)
downloadscummvm-rg350-e7fbd9268c9bd4a21a9f4741d4636c722368847c.tar.gz
scummvm-rg350-e7fbd9268c9bd4a21a9f4741d4636c722368847c.tar.bz2
scummvm-rg350-e7fbd9268c9bd4a21a9f4741d4636c722368847c.zip
GLK: ALAN2: Cleanup of data text file opening
Diffstat (limited to 'engines/glk/alan2/alan2.cpp')
-rw-r--r--engines/glk/alan2/alan2.cpp50
1 files changed, 24 insertions, 26 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