COMPOSER: Migrate engine to Path

This commit is contained in:
Le Philousophe 2023-09-17 18:23:41 +02:00 committed by Eugene Sandulenko
parent f3c7cd6393
commit bbc4d51fc4
5 changed files with 20 additions and 18 deletions

View File

@ -94,7 +94,7 @@ Common::Error ComposerEngine::run() {
}
if (getPlatform() == Common::kPlatformMacintosh) {
const Common::FSNode gameDataDir(ConfMan.get("path"));
const Common::FSNode gameDataDir(ConfMan.getPath("path"));
if (gameId == "sleepingcub")
SearchMan.addSubDirectoryMatching(gameDataDir, "sleepcub");
if (gameId == "princess")
@ -348,14 +348,14 @@ Common::String ComposerEngine::getStringFromConfig(const Common::String &section
return value;
}
Common::String ComposerEngine::getFilename(const Common::String &section, uint id) {
Common::Path ComposerEngine::getFilename(const Common::String &section, uint id) {
Common::String key = Common::String::format("%d", id);
Common::String filename = getStringFromConfig(section, key);
return mangleFilename(filename);
}
Common::String ComposerEngine::mangleFilename(Common::String filename) {
Common::Path ComposerEngine::mangleFilename(Common::String filename) {
while (filename.size() && (filename[0] == '~' || filename[0] == ':' || filename[0] == '\\'))
filename = filename.c_str() + 1;
@ -380,7 +380,7 @@ Common::String ComposerEngine::mangleFilename(Common::String filename) {
else
outFilename += filename[i];
}
return outFilename;
return Common::Path(outFilename, '/');
}
void ComposerEngine::loadLibrary(uint id) {
@ -395,9 +395,10 @@ void ComposerEngine::loadLibrary(uint id) {
unloadLibrary(library->_id);
}
Common::String filename;
Common::Path path;
Common::String oldGroup = _bookGroup;
if (getGameType() == GType_ComposerV1) {
Common::String filename;
if (getPlatform() == Common::kPlatformMacintosh) {
if (!id || _bookGroup.empty())
filename = getStringFromConfig("splash.rsc", "100");
@ -410,7 +411,7 @@ void ComposerEngine::loadLibrary(uint id) {
else
filename = getStringFromConfig(_bookGroup, Common::String::format("%d", id));
}
filename = mangleFilename(filename);
path = mangleFilename(filename);
// bookGroup is the basename of the path.
// TODO: tidy this up.
@ -432,7 +433,7 @@ void ComposerEngine::loadLibrary(uint id) {
} else {
if (!id)
id = atoi(getStringFromConfig("Common", "StartUp").c_str());
filename = getFilename("Libs", id);
path = getFilename("Libs", id);
}
Library library;
@ -440,8 +441,8 @@ void ComposerEngine::loadLibrary(uint id) {
library._id = id;
library._group = oldGroup;
library._archive = new ComposerArchive();
if (!library._archive->openFile(filename))
error("failed to open '%s'", filename.c_str());
if (!library._archive->openFile(path))
error("failed to open '%s'", path.toString(Common::Path::kNativeSeparator).c_str());
_libraries.push_front(library);
Library &newLib = _libraries.front();

View File

@ -219,8 +219,8 @@ private:
Common::String getSaveStateName(int slot) const override;
Common::String getStringFromConfig(const Common::String &section, const Common::String &key);
Common::String getFilename(const Common::String &section, uint id);
Common::String mangleFilename(Common::String filename);
Common::Path getFilename(const Common::String &section, uint id);
Common::Path mangleFilename(Common::String filename);
void loadLibrary(uint id);
void unloadLibrary(uint id);

View File

@ -41,7 +41,7 @@ Archive::~Archive() {
close();
}
bool Archive::openFile(const Common::String &fileName) {
bool Archive::openFile(const Common::Path &fileName) {
Common::SeekableReadStream *file
= Common::MacResManager::openFileOrDataFork(fileName);

View File

@ -54,7 +54,7 @@ public:
Archive();
virtual ~Archive();
bool openFile(const Common::String &fileName);
bool openFile(const Common::Path &fileName);
virtual bool openStream(Common::SeekableReadStream *stream) = 0;
void close();

View File

@ -616,9 +616,10 @@ int16 ComposerEngine::scriptFuncCall(uint16 id, int16 param1, int16 param2, int1
if (!stream) {
if (!_bookIni.hasKey(Common::String::format("%d", param1), "Data"))
return 0;
filename = getFilename("Data", param1);
Common::Path path = getFilename("Data", param1);
Common::SeekableReadStream *file =
Common::MacResManager::openFileOrDataFork(filename);
Common::MacResManager::openFileOrDataFork(path);
filename = path.toString(Common::Path::kNativeSeparator);
if (!file)
error("couldn't open '%s' to get vars id '%d'", filename.c_str(), param1);
stream = file;
@ -684,14 +685,14 @@ int16 ComposerEngine::scriptFuncCall(uint16 id, int16 param1, int16 param2, int1
case kFuncLoadData:
debug(3, "kFuncLoadData(%d, %d, %d)", param1, param2, param3);
{
Common::String filename = getFilename("Data", param1);
Common::Path filename = getFilename("Data", param1);
Common::File *file = new Common::File();
if (!file->open(filename))
error("couldn't open '%s' to get data id '%d'", filename.c_str(), param1);
error("couldn't open '%s' to get data id '%d'", filename.toString(Common::Path::kNativeSeparator).c_str(), param1);
if (param3 == 0)
param3 = 1000;
if (param2 < 0 || param3 < 0 || param2 + param3 > 1000)
error("can't read %d entries into %d from file '%s' for data id '%d'", param3, param2, filename.c_str(), param1);
error("can't read %d entries into %d from file '%s' for data id '%d'", param3, param2, filename.toString(Common::Path::kNativeSeparator).c_str(), param1);
for (uint i = 0; i < (uint)param3; i++) {
if (file->pos() + 1 > file->size())
break;