From ff87ff4e241539643f0931c4a424bc39130daba2 Mon Sep 17 00:00:00 2001 From: Le Philousophe Date: Sun, 17 Sep 2023 18:23:42 +0200 Subject: [PATCH] GLK: Migrate engine to Path --- engines/glk/adrift/sxutils.cpp | 2 +- engines/glk/alan2/alan2.cpp | 2 +- engines/glk/alan3/alan3.cpp | 2 +- engines/glk/archetype/misc.cpp | 2 +- engines/glk/blorb.cpp | 62 +++++++++++++-------------- engines/glk/blorb.h | 12 +++--- engines/glk/comprehend/file_buf.cpp | 4 +- engines/glk/comprehend/pics.cpp | 16 +++---- engines/glk/comprehend/pics.h | 2 +- engines/glk/debugger.cpp | 10 ++--- engines/glk/detection.cpp | 2 +- engines/glk/glk.cpp | 4 +- engines/glk/hugo/resource_archive.cpp | 9 ++-- engines/glk/jacl/types.h | 6 +-- engines/glk/magnetic/glk.cpp | 2 +- engines/glk/metaengine.cpp | 4 +- engines/glk/picture.cpp | 20 ++++----- engines/glk/quest/geas_glk.cpp | 2 +- engines/glk/sound.cpp | 8 ++-- engines/glk/streams.cpp | 4 +- engines/glk/zcode/glk_interface.cpp | 2 +- engines/glk/zcode/pics.cpp | 11 +++-- engines/glk/zcode/sound_folder.cpp | 39 ++++++++--------- engines/glk/zcode/sound_folder.h | 8 ++-- 24 files changed, 112 insertions(+), 123 deletions(-) diff --git a/engines/glk/adrift/sxutils.cpp b/engines/glk/adrift/sxutils.cpp index f7fd0795477..00334e58569 100644 --- a/engines/glk/adrift/sxutils.cpp +++ b/engines/glk/adrift/sxutils.cpp @@ -144,7 +144,7 @@ void sx_free(void *pointer) { Common::SeekableReadStream *sx_fopen(const sc_char *name, const sc_char *extension, const sc_char *mode) { assert(name && extension && mode); - Common::String filename = Common::String::format("%s.%s", name, extension); + Common::Path filename(Common::String::format("%s.%s", name, extension)); Common::File *f = new Common::File(); if (f->open(filename)) diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp index 177884a571e..a08775b89e7 100644 --- a/engines/glk/alan2/alan2.cpp +++ b/engines/glk/alan2/alan2.cpp @@ -84,7 +84,7 @@ bool Alan2::initialize() { // Open up the text file txtfil = new Common::File(); - if (!txtfil->open(Common::String::format("%s.dat", _advName.c_str()))) { + if (!txtfil->open(Common::Path(Common::String::format("%s.dat", _advName.c_str())))) { GUIErrorMessage("Could not open adventure text data file"); delete txtfil; return false; diff --git a/engines/glk/alan3/alan3.cpp b/engines/glk/alan3/alan3.cpp index a873f359a5b..5d78bf5abdb 100644 --- a/engines/glk/alan3/alan3.cpp +++ b/engines/glk/alan3/alan3.cpp @@ -92,7 +92,7 @@ bool Alan3::initialize() { // In Alan 3, the text data comes from the adventure file itself Common::File *txt = new Common::File(); - if (!txt->open(getFilename())) { + if (!txt->open(Common::Path(getFilename()))) { GUIErrorMessage("Could not open adventure file for text data"); delete txt; return false; diff --git a/engines/glk/archetype/misc.cpp b/engines/glk/archetype/misc.cpp index 750ae52c010..ff08f77e477 100644 --- a/engines/glk/archetype/misc.cpp +++ b/engines/glk/archetype/misc.cpp @@ -51,7 +51,7 @@ void misc_init() { bool progfile::open(const String &name) { filename = name; - if (!_file.open(name)) { + if (!_file.open(Common::Path(name))) { return false; } else { diff --git a/engines/glk/blorb.cpp b/engines/glk/blorb.cpp index 6dad4516ccb..c81ccaecfe3 100644 --- a/engines/glk/blorb.cpp +++ b/engines/glk/blorb.cpp @@ -26,7 +26,7 @@ namespace Glk { /*--------------------------------------------------------------------------*/ -Blorb::Blorb(const Common::String &filename, InterpreterType interpType) : +Blorb::Blorb(const Common::Path &filename, InterpreterType interpType) : Common::Archive(), _filename(filename), _interpType(interpType) { if (load() != Common::kNoError) error("Could not parse blorb file"); @@ -39,9 +39,8 @@ Blorb::Blorb(const Common::FSNode &fileNode, InterpreterType interpType) : } bool Blorb::hasFile(const Common::Path &path) const { - Common::String name = path.toString(); for (uint idx = 0; idx < _chunks.size(); ++idx) { - if (_chunks[idx]._filename.equalsIgnoreCase(name)) + if (_chunks[idx]._filename.equalsIgnoreCase(path)) return true; } @@ -57,19 +56,17 @@ int Blorb::listMembers(Common::ArchiveMemberList &list) const { } const Common::ArchiveMemberPtr Blorb::getMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!hasFile(name)) + if (!hasFile(path)) return Common::ArchiveMemberPtr(); - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, *this)); + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this)); } Common::SeekableReadStream *Blorb::createReadStreamForMember(const Common::Path &path) const { - Common::String name = path.toString(); for (uint idx = 0; idx < _chunks.size(); ++idx) { const ChunkEntry &ce = _chunks[idx]; - if (ce._filename.equalsIgnoreCase(name)) { + if (ce._filename.equalsIgnoreCase(path)) { Common::File f; if ((!_filename.empty() && !f.open(_filename)) || (_filename.empty() && !f.open(_fileNode))) @@ -116,32 +113,33 @@ Common::ErrorCode Blorb::load() { for (uint idx = 0; idx < _chunks.size(); ++idx) { ChunkEntry &ce = _chunks[idx]; + Common::String filename; if (ce._type == ID_Pict) { - ce._filename = Common::String::format("pic%u", ce._number); + filename = Common::String::format("pic%u", ce._number); if (ce._id == ID_JPEG) - ce._filename += ".jpg"; + filename += ".jpg"; else if (ce._id == ID_PNG) - ce._filename += ".png"; + filename += ".png"; else if (ce._id == ID_Rect) - ce._filename += ".rect"; + filename += ".rect"; } else if (ce._type == ID_Snd) { - ce._filename = Common::String::format("sound%u", ce._number); + filename = Common::String::format("sound%u", ce._number); if (ce._id == ID_MIDI) - ce._filename += ".midi"; + filename += ".midi"; else if (ce._id == ID_MP3) - ce._filename += ".mp3"; + filename += ".mp3"; else if (ce._id == ID_WAVE) - ce._filename += ".wav"; + filename += ".wav"; else if (ce._id == ID_AIFF || ce._id == ID_FORM) - ce._filename += ".aiff"; + filename += ".aiff"; else if (ce._id == ID_OGG) - ce._filename += ".ogg"; + filename += ".ogg"; else if (ce._id == ID_MOD) - ce._filename += ".mod"; + filename += ".mod"; } else if (ce._type == ID_Data) { - ce._filename = Common::String::format("data%u", ce._number); + filename = Common::String::format("data%u", ce._number); } else if (ce._type == ID_Exec) { if ( @@ -154,15 +152,15 @@ Common::ErrorCode Blorb::load() { (_interpType == INTERPRETER_ZCODE && ce._id == ID_ZCOD) ) { // Game executable - ce._filename = "game"; + filename = "game"; } else { char buffer[5]; WRITE_BE_UINT32(buffer, ce._id); buffer[4] = '\0'; - Common::String type(buffer); - ce._filename = type; + filename = Common::String(buffer); } } + ce._filename = Common::Path(filename); } // Check through any optional remaining chunks for an adaptive palette list @@ -251,7 +249,7 @@ bool Blorb::isBlorb(Common::SeekableReadStream &stream, uint32 type) { return false; } -bool Blorb::isBlorb(const Common::String &filename, uint32 type) { +bool Blorb::isBlorb(const Common::Path &filename, uint32 type) { Common::File f; if (!filename.empty() && !f.open(filename)) return false; @@ -265,10 +263,10 @@ bool Blorb::hasBlorbExt(const Common::String &filename) { || filename.hasSuffixIgnoreCase(".zlb") || filename.hasSuffixIgnoreCase(".a3r"); } -void Blorb::getBlorbFilenames(const Common::String &srcFilename, Common::StringArray &filenames, +void Blorb::getBlorbFilenames(const Common::Path &srcFilename, Common::Array &filenames, InterpreterType interpType, const Common::String &gameId) { // Strip off the source filename extension - Common::String filename = srcFilename; + Common::String filename = srcFilename.baseName(); if (!filename.contains('.')) { filename += '.'; } else { @@ -278,18 +276,18 @@ void Blorb::getBlorbFilenames(const Common::String &srcFilename, Common::StringA // Add in the different possible filenames filenames.clear(); - filenames.push_back(filename + "blorb"); - filenames.push_back(filename + "blb"); + filenames.push_back(srcFilename.getParent().appendComponent(filename + "blorb")); + filenames.push_back(srcFilename.getParent().appendComponent(filename + "blb")); switch (interpType) { case INTERPRETER_ALAN3: - filenames.push_back(filename + "a3r"); + filenames.push_back(srcFilename.getParent().appendComponent(filename + "a3r")); break; case INTERPRETER_GLULX: - filenames.push_back(filename + "gblorb"); + filenames.push_back(srcFilename.getParent().appendComponent(filename + "gblorb")); break; case INTERPRETER_ZCODE: - filenames.push_back(filename + "zblorb"); + filenames.push_back(srcFilename.getParent().appendComponent(filename + "zblorb")); getInfocomBlorbFilenames(filenames, gameId); break; default: @@ -297,7 +295,7 @@ void Blorb::getBlorbFilenames(const Common::String &srcFilename, Common::StringA } } -void Blorb::getInfocomBlorbFilenames(Common::StringArray &filenames, const Common::String &gameId) { +void Blorb::getInfocomBlorbFilenames(Common::Array &filenames, const Common::String &gameId) { if (gameId == "beyondzork") filenames.push_back("beyondzork.blb"); else if (gameId == "journey") diff --git a/engines/glk/blorb.h b/engines/glk/blorb.h index 1105fb96fc2..9c90edb530b 100644 --- a/engines/glk/blorb.h +++ b/engines/glk/blorb.h @@ -38,7 +38,7 @@ struct ChunkEntry { uint _id; size_t _offset; size_t _size; - Common::String _filename; + Common::Path _filename; }; enum { @@ -81,7 +81,7 @@ enum { */ class Blorb : public Common::Archive { private: - Common::String _filename; + Common::Path _filename; Common::FSNode _fileNode; InterpreterType _interpType; Common::Array _chunks; ///< list of chunk descriptors @@ -94,12 +94,12 @@ private: /** * Add possible Blorb filenames for Infocom games */ - static void getInfocomBlorbFilenames(Common::StringArray &filenames, const Common::String &gameId); + static void getInfocomBlorbFilenames(Common::Array &filenames, const Common::String &gameId); public: /** * Constructor */ - Blorb(const Common::String &filename, InterpreterType interpType); + Blorb(const Common::Path &filename, InterpreterType interpType); /** * Constructor @@ -146,7 +146,7 @@ public: /** * Returns true if a given filename specifies a Blorb file */ - static bool isBlorb(const Common::String &filename, uint32 type = 0); + static bool isBlorb(const Common::Path &filename, uint32 type = 0); /** * Returns true if a given filename has a Blorb file extension @@ -156,7 +156,7 @@ public: /** * Return a list of possible filenames for blorb files */ - static void getBlorbFilenames(const Common::String &srcFilename, Common::StringArray &filenames, + static void getBlorbFilenames(const Common::Path &srcFilename, Common::Array &filenames, InterpreterType interpType, const Common::String &gameId); }; diff --git a/engines/glk/comprehend/file_buf.cpp b/engines/glk/comprehend/file_buf.cpp index 88135ac6c16..84a45cad132 100644 --- a/engines/glk/comprehend/file_buf.cpp +++ b/engines/glk/comprehend/file_buf.cpp @@ -29,7 +29,7 @@ namespace Comprehend { FileBuffer::FileBuffer(const Common::String &filename) : _pos(0) { // Open the file Common::File f; - if (!f.open(filename)) + if (!f.open(Common::Path(filename))) error("Could not open - %s", filename.c_str()); _data.resize(f.size()); @@ -45,7 +45,7 @@ FileBuffer::FileBuffer(Common::ReadStream *stream, size_t size) : _pos(0) { bool FileBuffer::exists(const Common::String &filename) { - return Common::File::exists(filename); + return Common::File::exists(Common::Path(filename)); } void FileBuffer::close() { diff --git a/engines/glk/comprehend/pics.cpp b/engines/glk/comprehend/pics.cpp index e0a5a74966d..903886f50d3 100644 --- a/engines/glk/comprehend/pics.cpp +++ b/engines/glk/comprehend/pics.cpp @@ -100,13 +100,12 @@ void Pics::ImageContext::lineFixes() { /*-------------------------------------------------------*/ -Pics::ImageFile::ImageFile(const Common::String &filename, bool isSingleImage) { +Pics::ImageFile::ImageFile(const Common::String &filename, bool isSingleImage) : _filename(filename) { Common::File f; uint16 version; int i; - _filename = filename; - if (!f.open(filename)) + if (!f.open(_filename)) error("Could not open file - %s", filename.c_str()); if (isSingleImage) { @@ -363,7 +362,7 @@ int Pics::getPictureNumber(const Common::String &filename) const { } bool Pics::hasFile(const Common::Path &path) const { - Common::String name = path.toString(); + Common::String name = path.baseName(); int num = getPictureNumber(name); if (num == -1) return false; @@ -383,18 +382,17 @@ int Pics::listMembers(Common::ArchiveMemberList &list) const { } const Common::ArchiveMemberPtr Pics::getMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!hasFile(name)) + if (!hasFile(path)) return Common::ArchiveMemberPtr(); - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, *this)); + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this)); } Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::Path &path) const { - Common::String name = path.toString(); + Common::String name = path.baseName(); // Get the picture number int num = getPictureNumber(name); - if (num == -1 || !hasFile(name)) + if (num == -1 || !hasFile(path)) return nullptr; // Draw the image diff --git a/engines/glk/comprehend/pics.h b/engines/glk/comprehend/pics.h index c1a1aeef4d9..cc982db16aa 100644 --- a/engines/glk/comprehend/pics.h +++ b/engines/glk/comprehend/pics.h @@ -76,7 +76,7 @@ class Pics : public Common::Archive { struct ImageFile { private: Common::Array _imageOffsets; - Common::String _filename; + Common::Path _filename; private: bool doImageOp(ImageContext *ctx) const; diff --git a/engines/glk/debugger.cpp b/engines/glk/debugger.cpp index f7eae41c248..6d8a193a32f 100644 --- a/engines/glk/debugger.cpp +++ b/engines/glk/debugger.cpp @@ -55,9 +55,9 @@ bool Debugger::cmdDumpPic(int argc, const char **argv) { Common::File f; int picNum = strToInt(argv[1]); - Common::String filename = Common::String::format("pic%d.png", picNum); + Common::Path filename(Common::String::format("pic%d.png", picNum)); if (!f.exists(filename)) - filename = Common::String::format("pic%d.jpg", picNum); + filename = Common::Path(Common::String::format("pic%d.jpg", picNum)); if (f.open(filename)) { // png or jpeg file @@ -74,15 +74,15 @@ bool Debugger::cmdDumpPic(int argc, const char **argv) { } else { debugPrintf("Could not find specified picture\n"); } - } else if (f.exists(Common::String::format("pic%d.rect", picNum))) { + } else if (f.exists(Common::Path(Common::String::format("pic%d.rect", picNum)))) { debugPrintf("Picture is only a placeholder rectangle\n"); - } else if (f.open(Common::String::format("pic%d.raw", picNum))) { + } else if (f.open(Common::Path(Common::String::format("pic%d.raw", picNum)))) { // Raw picture #ifdef USE_PNG Common::DumpFile df; RawDecoder rd; - if (rd.loadStream(f) && df.open(Common::String::format("pic%d.png", picNum))) { + if (rd.loadStream(f) && df.open(Common::Path(Common::String::format("pic%d.png", picNum)))) { saveRawPicture(rd, df); debugPrintf("Dumped picture\n"); } else { diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp index 5ee75a09500..fe87cca019b 100644 --- a/engines/glk/detection.cpp +++ b/engines/glk/detection.cpp @@ -116,7 +116,7 @@ GlkDetectedGame::GlkDetectedGame(const char *id, const char *desc, const Common: FileProperties fp; fp.md5 = md5; fp.size = filesize; - matchedFiles[filename] = fp; + matchedFiles[Common::Path(filename)] = fp; } } // End of namespace Glk diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp index 1a2af57355a..8acb805a1b8 100644 --- a/engines/glk/glk.cpp +++ b/engines/glk/glk.cpp @@ -111,7 +111,7 @@ void GlkEngine::createConfiguration() { Common::Error GlkEngine::run() { // Open up the game file - Common::String filename = getFilename(); + Common::Path filename(getFilename()); if (!Common::File::exists(filename)) return Common::kNoGameDataFoundError; @@ -124,7 +124,7 @@ Common::Error GlkEngine::run() { return Common::kNoGameDataFoundError; } else { // Check for a secondary blorb file with the same filename - Common::StringArray blorbFilenames; + Common::Array blorbFilenames; Blorb::getBlorbFilenames(filename, blorbFilenames, getInterpreterType(), getGameID()); for (uint idx = 0; idx < blorbFilenames.size(); ++idx) { diff --git a/engines/glk/hugo/resource_archive.cpp b/engines/glk/hugo/resource_archive.cpp index a6546a452fb..d6f610bbc42 100644 --- a/engines/glk/hugo/resource_archive.cpp +++ b/engines/glk/hugo/resource_archive.cpp @@ -48,10 +48,9 @@ bool ResourceArchive::splitName(const Common::String &name, bool ResourceArchive::hasFile(const Common::Path &path) const { - Common::String name = path.toString(); Common::String filename, resName; - if (!splitName(name, filename, resName)) + if (!splitName(path.baseName(), filename, resName)) return false; size_t resLength = g_vm->FindResource(filename.c_str(), resName.c_str()); g_vm->hugo_fclose(g_vm->resource_file); @@ -60,19 +59,17 @@ bool ResourceArchive::hasFile(const Common::Path &path) const { } const Common::ArchiveMemberPtr ResourceArchive::getMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!hasFile(name)) + if (!hasFile(path)) return Common::ArchiveMemberPtr(); return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this)); } Common::SeekableReadStream *ResourceArchive::createReadStreamForMember(const Common::Path &path) const { - Common::String name = path.toString(); Common::String filename, resName; // Split up the file and resource entry; return if it's not one - if (!splitName(name, filename, resName)) + if (!splitName(path.baseName(), filename, resName)) return nullptr; // Try and get the entry details from the given file diff --git a/engines/glk/jacl/types.h b/engines/glk/jacl/types.h index 74f5e6046d6..5f81b5ba10b 100644 --- a/engines/glk/jacl/types.h +++ b/engines/glk/jacl/types.h @@ -196,7 +196,7 @@ class File : public Common::File { public: static File *openForReading(const Common::String &name) { File *f = new File(); - if (f->open(name)) + if (f->open(Common::Path(name))) return f; delete f; @@ -205,7 +205,7 @@ public: static Common::WriteStream *openForWriting(const Common::String &name) { Common::DumpFile *df = new Common::DumpFile(); - if (df->open(name)) + if (df->open(Common::Path(name))) return df; delete df; @@ -213,7 +213,7 @@ public: } public: File() : Common::File() {} - File(const Common::String &name) { + File(const Common::Path &name) { Common::File::open(name); assert(isOpen()); } diff --git a/engines/glk/magnetic/glk.cpp b/engines/glk/magnetic/glk.cpp index babd1cf15e4..075eb6be943 100644 --- a/engines/glk/magnetic/glk.cpp +++ b/engines/glk/magnetic/glk.cpp @@ -301,7 +301,7 @@ type32 Magnetic::gms_gameid_read_uint32(int offset, Common::SeekableReadStream * void Magnetic::gms_gameid_identify_game(const Common::String &text_file) { Common::File stream; - if (!stream.open(text_file)) + if (!stream.open(Common::Path(text_file))) error("Error opening game file"); type32 game_size, game_pc; diff --git a/engines/glk/metaengine.cpp b/engines/glk/metaengine.cpp index 13693dcbfe5..3831e8fe367 100644 --- a/engines/glk/metaengine.cpp +++ b/engines/glk/metaengine.cpp @@ -141,7 +141,7 @@ templatebool create(OSystem *syst, Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) const { // Get the list of files in the folder and return detection against them - Common::FSNode folder = Common::FSNode(ConfMan.get("path")); + Common::FSNode folder = Common::FSNode(ConfMan.getPath("path")); Common::FSList fslist; folder.getChildren(fslist, Common::FSNode::kListFilesOnly); @@ -192,7 +192,7 @@ Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) { // Get the MD5 Common::File f; - if (!f.open(Common::FSNode(ConfMan.get("path")).getChild(gameDesc._filename))) + if (!f.open(Common::FSNode(ConfMan.getPath("path")).getChild(gameDesc._filename))) return Common::kNoGameDataFoundError; Common::String fileName = f.getName(); diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp index 13d3e2cbca9..dbc54b7c915 100644 --- a/engines/glk/picture.cpp +++ b/engines/glk/picture.cpp @@ -128,9 +128,9 @@ Picture *Pictures::load(const Common::String &name) { return pic; Common::File f; - if ((name.hasSuffixIgnoreCase(".png") && f.open(name)) - || f.open(Common::String::format("pic%s.png", name.c_str())) - || f.open(Common::String::format("%s.png", name.c_str())) + if ((name.hasSuffixIgnoreCase(".png") && f.open(Common::Path(name))) + || f.open(Common::Path(Common::String::format("pic%s.png", name.c_str()))) + || f.open(Common::Path(Common::String::format("%s.png", name.c_str()))) ) { png.setKeepTransparencyPaletted(true); png.loadStream(f); @@ -140,23 +140,23 @@ Picture *Pictures::load(const Common::String &name) { hasTransColor = png.hasTransparentColor(); transColor = png.getTransparentColor(); } else if ( - ((name.hasSuffixIgnoreCase(".jpg") || name.hasSuffixIgnoreCase(".jpeg")) && f.open(name)) - || f.open(Common::String::format("pic%s.jpg", name.c_str())) - || f.open(Common::String::format("pic%s.jpeg", name.c_str())) - || f.open(Common::String::format("%s.jpg", name.c_str())) + ((name.hasSuffixIgnoreCase(".jpg") || name.hasSuffixIgnoreCase(".jpeg")) && f.open(Common::Path(name))) + || f.open(Common::Path(Common::String::format("pic%s.jpg", name.c_str()))) + || f.open(Common::Path(Common::String::format("pic%s.jpeg", name.c_str()))) + || f.open(Common::Path(Common::String::format("%s.jpg", name.c_str()))) ) { jpg.setOutputPixelFormat(g_system->getScreenFormat()); jpg.loadStream(f); img = jpg.getSurface(); - } else if ((name.hasSuffixIgnoreCase(".raw") && f.open(name)) || - f.open(Common::String::format("pic%s.raw", name.c_str()))) { + } else if ((name.hasSuffixIgnoreCase(".raw") && f.open(Common::Path(name))) || + f.open(Common::Path(Common::String::format("pic%s.raw", name.c_str())))) { raw.loadStream(f); img = raw.getSurface(); palette = raw.getPalette(); palCount = raw.getPaletteColorCount(); hasTransColor = raw.hasTransparentColor(); transColor = raw.getTransparentColor(); - } else if (f.open(Common::String::format("pic%s.rect", name.c_str()))) { + } else if (f.open(Common::Path(Common::String::format("pic%s.rect", name.c_str())))) { rectImg.w = f.readUint32BE(); rectImg.h = f.readUint32BE(); img = &rectImg; diff --git a/engines/glk/quest/geas_glk.cpp b/engines/glk/quest/geas_glk.cpp index 025c4554675..dfea4a9995d 100644 --- a/engines/glk/quest/geas_glk.cpp +++ b/engines/glk/quest/geas_glk.cpp @@ -111,7 +111,7 @@ void GeasGlkInterface::set_background(String s) { */ String GeasGlkInterface::get_file(const String &fname) const { Common::File f; - if (!f.open(fname)) { + if (!f.open(Common::Path(fname))) { glk_put_cstring("Couldn't open "); glk_put_cstring(fname.c_str()); g_vm->glk_put_char(0x0a); diff --git a/engines/glk/sound.cpp b/engines/glk/sound.cpp index a6bde487cf6..19dc474aff2 100644 --- a/engines/glk/sound.cpp +++ b/engines/glk/sound.cpp @@ -96,11 +96,11 @@ uint SoundChannel::play(uint soundNum, uint repeats, uint notify) { // Find a sound of the given name Audio::AudioStream *stream; Common::File f; - Common::String nameSnd = Common::String::format("sound%u.snd", soundNum); - Common::String nameWav = Common::String::format("sound%u.wav", soundNum); - Common::String nameAiff = Common::String::format("sound%u.aiff", soundNum); + Common::Path nameSnd(Common::String::format("sound%u.snd", soundNum)); + Common::Path nameWav(Common::String::format("sound%u.wav", soundNum)); + Common::Path nameAiff(Common::String::format("sound%u.aiff", soundNum)); #ifdef USE_MAD - Common::String nameMp3 = Common::String::format("sound%u.mp3", soundNum); + Common::Path nameMp3(Common::String::format("sound%u.mp3", soundNum)); #endif if (f.exists(nameSnd) && f.open(nameSnd)) { diff --git a/engines/glk/streams.cpp b/engines/glk/streams.cpp index ef39a97bce9..805bb9feaa6 100644 --- a/engines/glk/streams.cpp +++ b/engines/glk/streams.cpp @@ -1326,7 +1326,7 @@ FileStream::FileStream(Streams *streams, frefid_t fref, uint fmode, uint rock, b setStream(_outSave); } else if (fmode == filemode_Read) { - if (_file.open(fname)) { + if (_file.open(Common::Path(fname))) { setStream(&_file); } else { _inSave = g_system->getSavefileManager()->openForLoading(fname); @@ -1550,7 +1550,7 @@ bool FileReference::exists() const { Common::String filename; if (_slotNumber == -1) { - if (Common::File::exists(_filename)) + if (Common::File::exists(Common::Path(_filename))) return true; filename = _filename; } else { diff --git a/engines/glk/zcode/glk_interface.cpp b/engines/glk/zcode/glk_interface.cpp index 6e23f8dbcfb..b41a7f31ceb 100644 --- a/engines/glk/zcode/glk_interface.cpp +++ b/engines/glk/zcode/glk_interface.cpp @@ -229,7 +229,7 @@ void GlkInterface::initialize() { } void GlkInterface::addSound() { - Common::FSNode gameDir(ConfMan.get("path")); + Common::FSNode gameDir(ConfMan.getPath("path")); SoundSubfolder::check(gameDir); SoundZip::check(gameDir, _storyId); } diff --git a/engines/glk/zcode/pics.cpp b/engines/glk/zcode/pics.cpp index 438aa525e7c..66e0f5b24e6 100644 --- a/engines/glk/zcode/pics.cpp +++ b/engines/glk/zcode/pics.cpp @@ -37,7 +37,7 @@ enum { Pics::Pics() : Common::Archive(), _filename(getFilename()) { Common::File f; - if (!f.open(_filename)) + if (!f.open(Common::Path(_filename))) error("Error reading Pics file"); _palette = new Common::Array(); @@ -109,7 +109,7 @@ Common::String Pics::getFilename() { } bool Pics::exists() { - return Common::File::exists(getFilename()); + return Common::File::exists(Common::Path(getFilename())); } bool Pics::hasFile(const Common::Path &path) const { @@ -131,11 +131,10 @@ int Pics::listMembers(Common::ArchiveMemberList &list) const { } const Common::ArchiveMemberPtr Pics::getMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!hasFile(name)) + if (!hasFile(path)) return Common::ArchiveMemberPtr(); - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, *this)); + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this)); } Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::Path &path) const { @@ -147,7 +146,7 @@ Common::SeekableReadStream *Pics::createReadStreamForMember(const Common::Path & if (e._filename.equalsIgnoreCase(name)) { Common::File f; Common::SeekableReadStream *dest; - if (!f.open(_filename)) + if (!f.open(path)) error("Reading failed"); if (e._dataSize) { diff --git a/engines/glk/zcode/sound_folder.cpp b/engines/glk/zcode/sound_folder.cpp index 151cd0607d9..bfb84a23d62 100644 --- a/engines/glk/zcode/sound_folder.cpp +++ b/engines/glk/zcode/sound_folder.cpp @@ -39,7 +39,7 @@ SoundSubfolder::SoundSubfolder(const Common::FSNode &folder) : _folder(folder) { Common::String filename = files[idx].getName(); if (filename.hasSuffixIgnoreCase(".snd")) { int fileNum = atoi(filename.c_str() + filename.size() - 6); - Common::String newName = Common::String::format("sound%d.snd", fileNum); + Common::Path newName(Common::String::format("sound%d.snd", fileNum)); _filenames[newName] = filename; } @@ -48,13 +48,12 @@ SoundSubfolder::SoundSubfolder(const Common::FSNode &folder) : _folder(folder) { } bool SoundSubfolder::hasFile(const Common::Path &path) const { - Common::String name = path.toString(); - return _filenames.contains(name); + return _filenames.contains(path); } int SoundSubfolder::listMembers(Common::ArchiveMemberList &list) const { int total = 0; - for (Common::StringMap::iterator i = _filenames.begin(); i != _filenames.end(); ++i) { + for (FileMap::iterator i = _filenames.begin(); i != _filenames.end(); ++i) { list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember((*i)._key, *this))); ++total; } @@ -63,17 +62,15 @@ int SoundSubfolder::listMembers(Common::ArchiveMemberList &list) const { } const Common::ArchiveMemberPtr SoundSubfolder::getMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!hasFile(name)) + if (!hasFile(path)) return Common::ArchiveMemberPtr(); - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, *this)); + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this)); } Common::SeekableReadStream *SoundSubfolder::createReadStreamForMember(const Common::Path &path) const { - Common::String name = path.toString(); Common::File *f = new Common::File(); - if (_filenames.contains(name) && f->open(_folder.getChild(_filenames[name]))) + if (_filenames.contains(path) && f->open(_folder.getChild(_filenames[path]))) return f; delete f; @@ -100,10 +97,11 @@ SoundZip::SoundZip(Common::Archive *zip) : _zip(zip) { zip->listMembers(files); for (Common::ArchiveMemberList::iterator i = files.begin(); i != files.end(); ++i) { - Common::String filename = (*i)->getName(); - if (filename.hasSuffixIgnoreCase(".snd")) { - int fileNum = atoi(filename.c_str() + filename.size() - 6); - Common::String newName = Common::String::format("sound%d.snd", fileNum); + Common::Path filename = (*i)->getPathInArchive(); + Common::String basename(filename.baseName()); + if (basename.hasSuffixIgnoreCase(".snd")) { + int fileNum = atoi(basename.c_str() + basename.size() - 6); + Common::Path newName(Common::String::format("sound%d.snd", fileNum)); _filenames[newName] = filename; } @@ -115,14 +113,13 @@ SoundZip::~SoundZip() { } bool SoundZip::hasFile(const Common::Path &path) const { - Common::String name = path.toString(); - return _filenames.contains(name); + return _filenames.contains(path); } int SoundZip::listMembers(Common::ArchiveMemberList &list) const { int total = 0; - for (Common::StringMap::iterator i = _filenames.begin(); i != _filenames.end(); ++i) { + for (FileMap::iterator i = _filenames.begin(); i != _filenames.end(); ++i) { list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember((*i)._key, *this))); ++total; } @@ -131,20 +128,18 @@ int SoundZip::listMembers(Common::ArchiveMemberList &list) const { } const Common::ArchiveMemberPtr SoundZip::getMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!hasFile(name)) + if (!hasFile(path)) return Common::ArchiveMemberPtr(); - return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, *this)); + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(path, *this)); } Common::SeekableReadStream *SoundZip::createReadStreamForMember(const Common::Path &path) const { - Common::String name = path.toString(); - if (!_filenames.contains(name)) + if (!_filenames.contains(path)) return nullptr; - return _zip->createReadStreamForMember(_filenames[name]); + return _zip->createReadStreamForMember(_filenames[path]); } } // End of namespace ZCode diff --git a/engines/glk/zcode/sound_folder.h b/engines/glk/zcode/sound_folder.h index 97c0cc6c873..6b35be33a56 100644 --- a/engines/glk/zcode/sound_folder.h +++ b/engines/glk/zcode/sound_folder.h @@ -25,7 +25,7 @@ #include "glk/zcode/frotz_types.h" #include "common/archive.h" #include "common/fs.h" -#include "common/hash-str.h" +#include "common/hashmap.h" namespace Glk { namespace ZCode { @@ -38,7 +38,8 @@ namespace ZCode { class SoundSubfolder : public Common::Archive { private: Common::FSNode _folder; - Common::StringMap _filenames; + typedef Common::HashMap FileMap; + FileMap _filenames; private: /** * Constructor @@ -86,7 +87,8 @@ public: class SoundZip : public Common::Archive { private: Common::Archive *_zip; - Common::StringMap _filenames; + typedef Common::HashMap FileMap; + FileMap _filenames; private: /** * Constructor