GOB: Migrate engine to Path

This commit is contained in:
Le Philousophe 2023-09-17 18:23:42 +02:00 committed by Eugene Sandulenko
parent 49da9211ec
commit 8c49d1442e
10 changed files with 29 additions and 26 deletions

View File

@ -58,7 +58,7 @@ void Databases::setLanguage(Common::Language language) {
_language = lang;
}
bool Databases::open(const Common::String &id, const Common::String &file) {
bool Databases::open(const Common::String &id, const Common::Path &file) {
if (_databases.contains(id)) {
warning("Databases::open(): A database with the ID \"%s\" already exists", id.c_str());
return false;
@ -66,13 +66,13 @@ bool Databases::open(const Common::String &id, const Common::String &file) {
Common::File dbFile;
if (!dbFile.open(file)) {
warning("Databases::open(): No such file \"%s\"", file.c_str());
warning("Databases::open(): No such file \"%s\"", file.toString().c_str());
return false;
}
dBase db;
if (!db.load(dbFile)) {
warning("Databases::open(): Failed loading database file \"%s\"", file.c_str());
warning("Databases::open(): Failed loading database file \"%s\"", file.toString().c_str());
return false;
}
@ -81,7 +81,7 @@ bool Databases::open(const Common::String &id, const Common::String &file) {
assert(map != _databases.end());
if (!buildMap(db, map->_value)) {
warning("Databases::open(): Failed building a map for database \"%s\"", file.c_str());
warning("Databases::open(): Failed building a map for database \"%s\"", file.toString().c_str());
_databases.erase(map);
return false;
}

View File

@ -38,7 +38,7 @@ public:
void setLanguage(Common::Language language);
bool open(const Common::String &id, const Common::String &file);
bool open(const Common::String &id, const Common::Path &file);
bool close(const Common::String &id);
bool getString(const Common::String &id, Common::String group,

View File

@ -231,7 +231,7 @@ bool DataIO::openArchive(Common::String name, bool base) {
name += ".stk";
// Try to open
*archive = openArchive(name);
*archive = openArchive(Common::Path(name));
if (!*archive)
return false;
@ -245,14 +245,14 @@ static void replaceChar(char *str, char c1, char c2) {
*str = c2;
}
DataIO::Archive *DataIO::openArchive(const Common::String &name) {
DataIO::Archive *DataIO::openArchive(const Common::Path &name) {
Archive *archive = new Archive;
if (!archive->file.open(name)) {
delete archive;
return nullptr;
}
archive->name = name;
archive->name = name.toString('/');
uint16 fileCount = archive->file.readUint16LE();
for (uint16 i = 0; i < fileCount; i++) {
@ -316,7 +316,7 @@ bool DataIO::hasFile(const Common::String &name){
return true;
// Else, look if a plain file that matches exists
return Common::File::exists(name);
return Common::File::exists(Common::Path(name));
}
int32 DataIO::fileSize(const Common::String &name) {
@ -342,7 +342,7 @@ int32 DataIO::fileSize(const Common::String &name) {
// Else, try to find a matching plain file
Common::File f;
if (!f.open(name))
if (!f.open(Common::Path(name)))
return -1;
return f.size();
@ -359,7 +359,7 @@ Common::SeekableReadStream *DataIO::getFile(const Common::String &name) {
// Else, try to open a matching plain file
Common::File f;
if (!f.open(name))
if (!f.open(Common::Path(name)))
return nullptr;
return f.readStream(f.size());
@ -376,7 +376,7 @@ byte *DataIO::getFile(const Common::String &name, int32 &size) {
// Else, try to open a matching plain file
Common::File f;
if (!f.open(name))
if (!f.open(Common::Path(name)))
return nullptr;
size = f.size();

View File

@ -90,7 +90,7 @@ private:
Common::Array<Archive *> _archives;
Archive *openArchive(const Common::String &name);
Archive *openArchive(const Common::Path &name);
bool closeArchive(Archive &archive);
File *findFile(const Common::String &name);

View File

@ -100,7 +100,7 @@ ADDetectedGame GobMetaEngineDetection::fallbackDetect(const FileMap &allFiles, c
const Gob::GOBGameDescription *GobMetaEngineDetection::detectOnceUponATime(const Common::FSList &fslist) {
// Add the game path to the search manager
SearchMan.clear();
SearchMan.addDirectory(fslist.begin()->getParent().getPath(), fslist.begin()->getParent());
SearchMan.addDirectory(fslist.begin()->getParent());
// Open the archives
Gob::DataIO dataIO;

View File

@ -75,7 +75,9 @@ bool INIConfig::openConfig(const Common::String &file, Config &config) {
config.config = new Common::INIFile();
config.created = false;
if (!config.config->loadFromFile(file)) {
// GOB uses \ as a path separator but
// it almost always manipulates base names
if (!config.config->loadFromFile(Common::Path(file, '\\'))) {
delete config.config;
config.config = nullptr;
return false;

View File

@ -33,7 +33,7 @@ Init_v7::~Init_v7() {
}
void Init_v7::initGame() {
const Common::FSNode gameDataDir(ConfMan.get("path"));
const Common::FSNode gameDataDir(ConfMan.getPath("path"));
// Add the environment directory
SearchMan.addSubDirectoryMatching(gameDataDir, "envir");

View File

@ -724,7 +724,7 @@ void Inter_v7::o7_setActiveCD() {
Common::String str1 = _vm->_game->_script->evalString();
Common::ArchiveMemberDetailsList files;
SearchMan.listMatchingMembers(files, str0);
SearchMan.listMatchingMembers(files, Common::Path(str0));
Common::String savedCDpath = _currentCDPath;
for (Common::ArchiveMemberDetails file : files) {
@ -739,7 +739,7 @@ void Inter_v7::o7_setActiveCD() {
}
void Inter_v7::o7_findFile() {
Common::String file_pattern = getFile(_vm->_game->_script->evalString());
Common::Path file_pattern(getFile(_vm->_game->_script->evalString()));
Common::ArchiveMemberList files;
SearchMan.listMatchingMembers(files, file_pattern);
@ -758,7 +758,7 @@ void Inter_v7::o7_findFile() {
}
debugC(5, kDebugFileIO, "o7_findFile(%s): %d matches (%d including duplicates)",
file_pattern.c_str(),
file_pattern.toString().c_str(),
filesWithoutDuplicates.size(),
files.size());
@ -769,7 +769,7 @@ void Inter_v7::o7_findFile() {
Common::String file = files.front()->getName();
filesWithoutDuplicates.pop_front();
debugC(5, kDebugFileIO, "o7_findFile(%s): first match = %s",
file_pattern.c_str(),
file_pattern.toString().c_str(),
file.c_str());
storeString(file.c_str());
@ -961,7 +961,7 @@ void Inter_v7::o7_opendBase() {
dbFile += ".DBF";
_databases.setLanguage(_vm->_language);
if (!_databases.open(id, dbFile)) {
if (!_databases.open(id, Common::Path(dbFile))) {
WRITE_VAR(27, 0); // Failure
return;
}
@ -1250,7 +1250,7 @@ void Inter_v7::o7_checkData(OpFuncParams &params) {
if (indexAppli == -1) {
// New appli, find the first directory containing an application still not installed, and set it as "current CD" path.
Common::ArchiveMemberDetailsList files;
SearchMan.listMatchingMembers(files, file); // Search for CD.INF files
SearchMan.listMatchingMembers(files, Common::Path(file)); // Search for CD.INF files
for (Common::ArchiveMemberDetails &cdInfFile : files) {
Common::SeekableReadStream *stream = cdInfFile.arcMember->createReadStream();
while (stream->pos() + 4 <= stream->size()) {
@ -1266,7 +1266,7 @@ void Inter_v7::o7_checkData(OpFuncParams &params) {
} else if (indexAppli >= 0 && (size_t) indexAppli <= installedApplications.size()) {
// Already installed appli, find its directory and set it as "current CD" path
int32 applicationNumber = installedApplications[indexAppli - 1];
Common::String appliVmdName = Common::String::format("appli_%02d.vmd", applicationNumber);
Common::Path appliVmdName(Common::String::format("appli_%02d.vmd", applicationNumber));
Common::ArchiveMemberDetailsList matchingFiles;
SearchMan.listMatchingMembers(matchingFiles, appliVmdName);
for (Common::ArchiveMemberDetails &matchingFile : matchingFiles) {

View File

@ -586,7 +586,7 @@ byte *Resources::getTexts() const {
}
bool Resources::dumpResource(const Resource &resource,
const Common::String &fileName) const {
const Common::Path &fileName) const {
Common::DumpFile dump;
@ -614,7 +614,7 @@ bool Resources::dumpResource(const Resource &resource, uint16 id,
fileName += ".";
fileName += ext;
return dumpResource(resource, fileName);
return dumpResource(resource, Common::Path(fileName));
}
Resource *Resources::getTOTResource(uint16 id) const {

View File

@ -25,6 +25,7 @@
#include "common/str.h"
namespace Common {
class Path;
class SeekableReadStream;
}
@ -88,7 +89,7 @@ public:
byte *getTexts() const;
bool dumpResource(const Resource &resource,
const Common::String &fileName) const;
const Common::Path &fileName) const;
bool dumpResource(const Resource &resource, uint16 id,
const Common::String &ext = "dmp") const;