aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-03 16:55:49 -0700
committerPaul Gilbert2018-12-08 19:05:59 -0800
commit60146c383d4b69920c6ba326611f9de66a513529 (patch)
treeb7a249b88cc53e4736a069605fc0c310e7077a19 /engines
parentf91cdb19bf2f96ffcb50de7d796bc32fcda38f34 (diff)
downloadscummvm-rg350-60146c383d4b69920c6ba326611f9de66a513529.tar.gz
scummvm-rg350-60146c383d4b69920c6ba326611f9de66a513529.tar.bz2
scummvm-rg350-60146c383d4b69920c6ba326611f9de66a513529.zip
GLK: Merge Files class into existing Streams class
Diffstat (limited to 'engines')
-rw-r--r--engines/gargoyle/files.cpp160
-rw-r--r--engines/gargoyle/files.h137
-rw-r--r--engines/gargoyle/gargoyle.cpp3
-rw-r--r--engines/gargoyle/gargoyle.h2
-rw-r--r--engines/gargoyle/glk.cpp12
-rw-r--r--engines/gargoyle/module.mk1
-rw-r--r--engines/gargoyle/streams.cpp136
-rw-r--r--engines/gargoyle/streams.h99
8 files changed, 241 insertions, 309 deletions
diff --git a/engines/gargoyle/files.cpp b/engines/gargoyle/files.cpp
deleted file mode 100644
index e14a315f09..0000000000
--- a/engines/gargoyle/files.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software{} you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation{} either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY{} without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program{} if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "gargoyle/files.h"
-#include "gargoyle/gargoyle.h"
-#include "gui/saveload.h"
-#include "common/file.h"
-#include "common/savefile.h"
-#include "common/translation.h"
-
-namespace Gargoyle {
-
-frefid_t Files::createByPrompt(glui32 usage, FileMode fmode, glui32 rock) {
- switch (usage & fileusage_TypeMask) {
- case fileusage_SavedGame: {
- if (fmode == filemode_Write) {
- // Select a savegame slot
- GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
-
- int slot = dialog->runModalWithCurrentTarget();
- if (slot >= 0) {
- Common::String desc = dialog->getResultString();
- return createRef(slot, desc, usage, rock);
- }
- } else if (fmode == filemode_Read) {
- // Load a savegame slot
- GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
-
- int slot = dialog->runModalWithCurrentTarget();
- if (slot >= 0) {
- return createRef(slot, "", usage, rock);
- }
- } else {
- error("Unsupport file mode");
- }
- break;
- }
-
- case fileusage_Transcript:
- return createRef("transcript.txt", fmode, rock);
-
- default:
- error("Unsupport file mode");
- break;
- }
-
- return nullptr;
-}
-
-frefid_t Files::createRef(int slot, const Common::String &desc, glui32 usage, glui32 rock) {
- frefid_t fref = new FileReference();
- fref->_slotNumber = slot;
- fref->_description = desc;
- fref->_textMode = ((usage & fileusage_TextMode) != 0);
- fref->_fileType = (FileUsage)(usage & fileusage_TypeMask);
-
- _fileReferences.push_back(FileRefArray::value_type(fref));
- return fref;
-}
-
-frefid_t Files::createRef(const Common::String &filename, glui32 usage, glui32 rock) {
- frefid_t fref = new FileReference();
- fref->_filename = filename;
- fref->_textMode = ((usage & fileusage_TextMode) != 0);
- fref->_fileType = (FileUsage)(usage & fileusage_TypeMask);
-
- _fileReferences.push_back(FileRefArray::value_type(fref));
- return fref;
-}
-
-frefid_t Files::createTemp(glui32 usage, glui32 rock) {
- return createRef(Common::String::format("%s.tmp", g_vm->getTargetName().c_str()),
- usage, rock);
-}
-
-frefid_t Files::createFromRef(frefid_t fref, glui32 usage, glui32 rock) {
- return createRef(fref->_filename, usage, rock);
-}
-
-void Files::deleteRef(frefid_t fref) {
- for (uint idx = 0; idx < _fileReferences.size(); ++idx) {
- if (_fileReferences[idx].get() == fref) {
- _fileReferences.remove_at(idx);
- return;
- }
- }
-}
-
-frefid_t Files::iterate(frefid_t fref, glui32 *rock) {
- // Find reference following the specified one
- int index = -1;
- for (uint idx = 0; idx < _fileReferences.size(); ++idx) {
- if (fref == nullptr || _fileReferences[idx].get() == fref) {
- if (idx < (_fileReferences.size() - 1))
- index = idx + 1;
- break;
- }
- }
-
- if (index != -1) {
- if (rock)
- *rock = _fileReferences[index].get()->_rock;
- return _fileReferences[index].get();
- }
-
- if (rock)
- *rock = 0;
- return nullptr;
-}
-
-/*--------------------------------------------------------------------------*/
-
-const Common::String FileReference::getSaveName() const {
- assert(_slotNumber != -1);
- return Common::String::format("%s.%.3d", g_vm->getTargetName().c_str(), _slotNumber);
-}
-
-bool FileReference::exists() const {
- Common::String filename;
-
- if (_slotNumber == -1) {
- if (Common::File::exists(_filename))
- return true;
- filename = _filename;
- } else {
- filename = getSaveName();
- }
-
- // Check for a savegame (or other file in the save folder) with that name
- Common::InSaveFile *inSave = g_system->getSavefileManager()->openForLoading(filename);
- bool result = inSave != nullptr;
- delete inSave;
- return result;
-}
-
-void FileReference::deleteFile() {
- Common::String filename = (_slotNumber == -1) ? _filename : getSaveName();
- g_system->getSavefileManager()->removeSavefile(filename);
-}
-
-} // End of namespace Gargoyle
diff --git a/engines/gargoyle/files.h b/engines/gargoyle/files.h
deleted file mode 100644
index 7e7ebfb726..0000000000
--- a/engines/gargoyle/files.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef GARGOYLE_FILES_H
-#define GARGOYLE_FILES_H
-
-#include "gargoyle/glk_types.h"
-#include "common/array.h"
-#include "common/ptr.h"
-#include "common/str.h"
-
-namespace Gargoyle {
-
-enum FileUsage {
- fileusage_Data = 0x00,
- fileusage_SavedGame = 0x01,
- fileusage_Transcript = 0x02,
- fileusage_InputRecord = 0x03,
- fileusage_TypeMask = 0x0f,
-
- fileusage_TextMode = 0x100,
- fileusage_BinaryMode = 0x000,
-};
-
-enum FileMode {
- filemode_Write = 0x01,
- filemode_Read = 0x02,
- filemode_ReadWrite = 0x03,
- filemode_WriteAppend = 0x05,
-};
-
-enum SeekMode {
- seekmode_Start = 0,
- seekmode_Current = 1,
- seekmode_End = 2,
-};
-
-
-/**
- * File details
- */
-struct FileReference {
- glui32 _rock;
- int _slotNumber;
- Common::String _description;
- Common::String _filename;
- FileUsage _fileType;
- bool _textMode;
- gidispatch_rock_t _dispRock;
-
- /**
- * Constructor
- */
- FileReference() : _rock(0), _slotNumber(-1), _fileType(fileusage_Data), _textMode(false) {}
-
- /**
- * Get savegame filename
- */
- const Common::String getSaveName() const;
-
- /**
- * Returns true if the given file exists
- */
- bool exists() const;
-
- /**
- * Delete the given file
- */
- void deleteFile();
-};
-
-typedef FileReference *frefid_t;
-typedef Common::Array< Common::SharedPtr<FileReference> > FileRefArray;
-
-class Files {
-private:
- FileRefArray _fileReferences;
-public:
- /**
- * Prompt for a savegame to load or save, and populate a file reference from the result
- */
- frefid_t createByPrompt(glui32 usage, FileMode fmode, glui32 rock);
-
- /**
- * Create a new file reference
- */
- frefid_t createRef(int slot, const Common::String &desc, glui32 usage, glui32 rock);
-
- /**
- * Create a new file reference
- */
- frefid_t createRef(const Common::String &filename, glui32 usage, glui32 rock);
-
- /**
- * Create a new temporary file reference
- */
- frefid_t createTemp(glui32 usage, glui32 rock);
-
- /**
- * Create a new file reference from an old one
- */
- frefid_t createFromRef(frefid_t fref, glui32 usage, glui32 rock);
-
- /**
- * Delete a file reference
- */
- void deleteRef(frefid_t fref);
-
- /**
- * Iterates to the next file reference following the specified one,
- * or the first if null is passed
- */
- frefid_t iterate(frefid_t fref, glui32 *rock);
-};
-
-} // End of namespace Gargoyle
-
-#endif
diff --git a/engines/gargoyle/gargoyle.cpp b/engines/gargoyle/gargoyle.cpp
index 503cf1cd1b..3135fcb5fe 100644
--- a/engines/gargoyle/gargoyle.cpp
+++ b/engines/gargoyle/gargoyle.cpp
@@ -32,7 +32,6 @@
#include "gargoyle/clipboard.h"
#include "gargoyle/conf.h"
#include "gargoyle/events.h"
-#include "gargoyle/files.h"
#include "gargoyle/picture.h"
#include "gargoyle/screen.h"
#include "gargoyle/streams.h"
@@ -55,7 +54,6 @@ GargoyleEngine::~GargoyleEngine() {
delete _clipboard;
delete _conf;
delete _events;
- delete _files;
delete _picList;
delete _screen;
delete _streams;
@@ -76,7 +74,6 @@ void GargoyleEngine::initialize() {
_clipboard = new Clipboard();
_events = new Events();
- _files = new Files();
_picList = new PicList();
_streams = new Streams();
_windows = new Windows(_screen);
diff --git a/engines/gargoyle/gargoyle.h b/engines/gargoyle/gargoyle.h
index 651499e4e8..88859b4d68 100644
--- a/engines/gargoyle/gargoyle.h
+++ b/engines/gargoyle/gargoyle.h
@@ -36,7 +36,6 @@ namespace Gargoyle {
class Clipboard;
class Conf;
class Events;
-class Files;
class PicList;
class Screen;
class Streams;
@@ -98,7 +97,6 @@ public:
Clipboard *_clipboard;
Conf *_conf;
Events *_events;
- Files *_files;
PicList *_picList;
Screen *_screen;
Streams *_streams;
diff --git a/engines/gargoyle/glk.cpp b/engines/gargoyle/glk.cpp
index a50c7a6211..f386f2280c 100644
--- a/engines/gargoyle/glk.cpp
+++ b/engines/gargoyle/glk.cpp
@@ -626,7 +626,7 @@ bool Glk::glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *resu
}
frefid_t Glk::glk_fileref_create_temp(glui32 usage, glui32 rock) {
- return _files->createTemp(usage, rock);
+ return _streams->createTemp(usage, rock);
}
frefid_t Glk::glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock) {
@@ -637,11 +637,11 @@ frefid_t Glk::glk_fileref_create_by_name(glui32 usage, const char *name, glui32
tempName.setChar(idx, '-');
}
- return _files->createRef(tempName, usage, rock);
+ return _streams->createRef(tempName, usage, rock);
}
frefid_t Glk::glk_fileref_create_by_prompt(glui32 usage, FileMode fmode, glui32 rock) {
- return _files->createByPrompt(usage, fmode, rock);
+ return _streams->createByPrompt(usage, fmode, rock);
}
frefid_t Glk::glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock) {
@@ -649,16 +649,16 @@ frefid_t Glk::glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui3
warning("fileref_create_from_fileref: invalid ref");
return nullptr;
} else {
- return _files->createFromRef(fref, usage, rock);
+ return _streams->createFromRef(fref, usage, rock);
}
}
void Glk::glk_fileref_destroy(frefid_t fref) {
- _files->deleteRef(fref);
+ _streams->deleteRef(fref);
}
frefid_t Glk::glk_fileref_iterate(frefid_t fref, glui32 *rockptr) {
- return _files->iterate(fref, rockptr);
+ return _streams->iterate(fref, rockptr);
}
glui32 Glk::glk_fileref_get_rock(frefid_t fref) {
diff --git a/engines/gargoyle/module.mk b/engines/gargoyle/module.mk
index 306ac8b7a5..f4422b0b31 100644
--- a/engines/gargoyle/module.mk
+++ b/engines/gargoyle/module.mk
@@ -5,7 +5,6 @@ MODULE_OBJS := \
conf.o \
detection.o \
events.o \
- files.o \
fonts.o \
gargoyle.o \
glk.o \
diff --git a/engines/gargoyle/streams.cpp b/engines/gargoyle/streams.cpp
index cdc2e7d17a..93335b9c0e 100644
--- a/engines/gargoyle/streams.cpp
+++ b/engines/gargoyle/streams.cpp
@@ -25,6 +25,10 @@
#include "gargoyle/events.h"
#include "gargoyle/gargoyle.h"
#include "gargoyle/windows.h"
+#include "gui/saveload.h"
+#include "common/file.h"
+#include "common/savefile.h"
+#include "common/translation.h"
namespace Gargoyle {
@@ -975,4 +979,136 @@ Stream *Streams::getFirst(uint32 *rock) {
return _streamList;
}
+
+frefid_t Streams::createByPrompt(glui32 usage, FileMode fmode, glui32 rock) {
+ switch (usage & fileusage_TypeMask) {
+ case fileusage_SavedGame: {
+ if (fmode == filemode_Write) {
+ // Select a savegame slot
+ GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"), true);
+
+ int slot = dialog->runModalWithCurrentTarget();
+ if (slot >= 0) {
+ Common::String desc = dialog->getResultString();
+ return createRef(slot, desc, usage, rock);
+ }
+ }
+ else if (fmode == filemode_Read) {
+ // Load a savegame slot
+ GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"), false);
+
+ int slot = dialog->runModalWithCurrentTarget();
+ if (slot >= 0) {
+ return createRef(slot, "", usage, rock);
+ }
+ }
+ else {
+ error("Unsupport file mode");
+ }
+ break;
+ }
+
+ case fileusage_Transcript:
+ return createRef("transcript.txt", fmode, rock);
+
+ default:
+ error("Unsupport file mode");
+ break;
+ }
+
+ return nullptr;
+}
+
+frefid_t Streams::createRef(int slot, const Common::String &desc, glui32 usage, glui32 rock) {
+ frefid_t fref = new FileReference();
+ fref->_slotNumber = slot;
+ fref->_description = desc;
+ fref->_textMode = ((usage & fileusage_TextMode) != 0);
+ fref->_fileType = (FileUsage)(usage & fileusage_TypeMask);
+
+ _fileReferences.push_back(FileRefArray::value_type(fref));
+ return fref;
+}
+
+frefid_t Streams::createRef(const Common::String &filename, glui32 usage, glui32 rock) {
+ frefid_t fref = new FileReference();
+ fref->_filename = filename;
+ fref->_textMode = ((usage & fileusage_TextMode) != 0);
+ fref->_fileType = (FileUsage)(usage & fileusage_TypeMask);
+
+ _fileReferences.push_back(FileRefArray::value_type(fref));
+ return fref;
+}
+
+frefid_t Streams::createTemp(glui32 usage, glui32 rock) {
+ return createRef(Common::String::format("%s.tmp", g_vm->getTargetName().c_str()),
+ usage, rock);
+}
+
+frefid_t Streams::createFromRef(frefid_t fref, glui32 usage, glui32 rock) {
+ return createRef(fref->_filename, usage, rock);
+}
+
+void Streams::deleteRef(frefid_t fref) {
+ for (uint idx = 0; idx < _fileReferences.size(); ++idx) {
+ if (_fileReferences[idx].get() == fref) {
+ _fileReferences.remove_at(idx);
+ return;
+ }
+ }
+}
+
+frefid_t Streams::iterate(frefid_t fref, glui32 *rock) {
+ // Find reference following the specified one
+ int index = -1;
+ for (uint idx = 0; idx < _fileReferences.size(); ++idx) {
+ if (fref == nullptr || _fileReferences[idx].get() == fref) {
+ if (idx < (_fileReferences.size() - 1))
+ index = idx + 1;
+ break;
+ }
+ }
+
+ if (index != -1) {
+ if (rock)
+ *rock = _fileReferences[index].get()->_rock;
+ return _fileReferences[index].get();
+ }
+
+ if (rock)
+ *rock = 0;
+ return nullptr;
+}
+
+/*--------------------------------------------------------------------------*/
+
+const Common::String FileReference::getSaveName() const {
+ assert(_slotNumber != -1);
+ return Common::String::format("%s.%.3d", g_vm->getTargetName().c_str(), _slotNumber);
+}
+
+bool FileReference::exists() const {
+ Common::String filename;
+
+ if (_slotNumber == -1) {
+ if (Common::File::exists(_filename))
+ return true;
+ filename = _filename;
+ }
+ else {
+ filename = getSaveName();
+ }
+
+ // Check for a savegame (or other file in the save folder) with that name
+ Common::InSaveFile *inSave = g_system->getSavefileManager()->openForLoading(filename);
+ bool result = inSave != nullptr;
+ delete inSave;
+ return result;
+}
+
+void FileReference::deleteFile() {
+ Common::String filename = (_slotNumber == -1) ? _filename : getSaveName();
+ g_system->getSavefileManager()->removeSavefile(filename);
+}
+
} // End of namespace Gargoyle
diff --git a/engines/gargoyle/streams.h b/engines/gargoyle/streams.h
index 08d97cb402..264190cc76 100644
--- a/engines/gargoyle/streams.h
+++ b/engines/gargoyle/streams.h
@@ -33,12 +33,74 @@ namespace Gargoyle {
class Window;
class Streams;
+enum FileUsage {
+ fileusage_Data = 0x00,
+ fileusage_SavedGame = 0x01,
+ fileusage_Transcript = 0x02,
+ fileusage_InputRecord = 0x03,
+ fileusage_TypeMask = 0x0f,
+
+ fileusage_TextMode = 0x100,
+ fileusage_BinaryMode = 0x000,
+};
+
+enum FileMode {
+ filemode_Write = 0x01,
+ filemode_Read = 0x02,
+ filemode_ReadWrite = 0x03,
+ filemode_WriteAppend = 0x05,
+};
+
+enum SeekMode {
+ seekmode_Start = 0,
+ seekmode_Current = 1,
+ seekmode_End = 2,
+};
+
struct StreamResult {
uint32 _readCount;
uint32 _writeCount;
};
typedef StreamResult stream_result_t;
+
+/**
+ * File details
+ */
+struct FileReference {
+ glui32 _rock;
+ int _slotNumber;
+ Common::String _description;
+ Common::String _filename;
+ FileUsage _fileType;
+ bool _textMode;
+ gidispatch_rock_t _dispRock;
+
+ /**
+ * Constructor
+ */
+ FileReference() : _rock(0), _slotNumber(-1), _fileType(fileusage_Data), _textMode(false) {}
+
+ /**
+ * Get savegame filename
+ */
+ const Common::String getSaveName() const;
+
+ /**
+ * Returns true if the given file exists
+ */
+ bool exists() const;
+
+ /**
+ * Delete the given file
+ */
+ void deleteFile();
+};
+
+typedef FileReference *frefid_t;
+typedef Common::Array< Common::SharedPtr<FileReference> > FileRefArray;
+
+
/**
* Base class for streams
*/
@@ -342,6 +404,7 @@ class Streams {
private:
Stream *_streamList;
Stream *_currentStream;
+ FileRefArray _fileReferences;
private:
/**
* Adds a created stream to the list
@@ -397,6 +460,42 @@ public:
* Gets the current output stream
*/
Stream *getCurrent() const { return _currentStream; }
+
+ /**
+ * Prompt for a savegame to load or save, and populate a file reference from the result
+ */
+ frefid_t createByPrompt(glui32 usage, FileMode fmode, glui32 rock);
+
+ /**
+ * Create a new file reference
+ */
+ frefid_t createRef(int slot, const Common::String &desc, glui32 usage, glui32 rock);
+
+ /**
+ * Create a new file reference
+ */
+ frefid_t createRef(const Common::String &filename, glui32 usage, glui32 rock);
+
+ /**
+ * Create a new temporary file reference
+ */
+ frefid_t createTemp(glui32 usage, glui32 rock);
+
+ /**
+ * Create a new file reference from an old one
+ */
+ frefid_t createFromRef(frefid_t fref, glui32 usage, glui32 rock);
+
+ /**
+ * Delete a file reference
+ */
+ void deleteRef(frefid_t fref);
+
+ /**
+ * Iterates to the next file reference following the specified one,
+ * or the first if null is passed
+ */
+ frefid_t iterate(frefid_t fref, glui32 *rock);
};
} // End of namespace Gargoyle