GLK: Migrate engine to Path

This commit is contained in:
Le Philousophe authored and Eugene Sandulenko committed 2023-12-24 13:19:25 +01:00
1 parent a8e11a0611
commit ff87ff4e24
24 files changed
+112 -123

No files matched your search

+1 -1
View File
@@ -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))
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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 {
+30 -32
View File
@@ -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<Common::Path> &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<Common::Path> &filenames, const Common::String &gameId) {
if (gameId == "beyondzork")
filenames.push_back("beyondzork.blb");
else if (gameId == "journey")
+6 -6
View File
@@ -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<ChunkEntry> _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<Common::Path> &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<Common::Path> &filenames,
InterpreterType interpType, const Common::String &gameId);
};
+2 -2
View File
@@ -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() {
+7 -9
View File
@@ -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
+1 -1
View File
@@ -76,7 +76,7 @@ class Pics : public Common::Archive {
struct ImageFile {
private:
Common::Array<uint16> _imageOffsets;
Common::String _filename;
Common::Path _filename;
private:
bool doImageOp(ImageContext *ctx) const;
+5 -5
View File
@@ -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 {
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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<Common::Path> blorbFilenames;
Blorb::getBlorbFilenames(filename, blorbFilenames, getInterpreterType(), getGameID());
for (uint idx = 0; idx < blorbFilenames.size(); ++idx) {
+3 -6
View File
@@ -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
+3 -3
View File
@@ -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());
}
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -141,7 +141,7 @@ template<class META, class ENG>bool 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();
+10 -10
View File
@@ -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;
+1 -1
View File
@@ -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);
+4 -4
View File
@@ -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)) {
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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);
}
+5 -6
View File
@@ -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<byte>();
@@ -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) {
+17 -22
View File
@@ -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
+5 -3
View File
@@ -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<Common::Path, Common::String, Common::Path::IgnoreCase_Hash, Common::Path::IgnoreCase_EqualTo> 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<Common::Path, Common::Path, Common::Path::IgnoreCase_Hash, Common::Path::IgnoreCase_EqualTo> FileMap;
FileMap _filenames;
private:
/**
* Constructor