AGS: Migrate engine to Path

This commit is contained in:
Le Philousophe 2023-09-17 18:23:40 +02:00 committed by Eugene Sandulenko
parent d614b5d31c
commit 728b2cbac7
11 changed files with 30 additions and 27 deletions

View File

@ -124,7 +124,7 @@ Common::Error AGSEngine::run() {
if (debugChannelSet(-1, kDebugScan)) {
// Scan the given folder and subfolders for unknown games
AGS3::GameScanner scanner;
scanner.scan(ConfMan.get("path"));
scanner.scan(ConfMan.getPath("path"));
return Common::kNoError;
}
@ -295,7 +295,7 @@ bool AGSEngine::is64BitGame() const {
}
Common::FSNode AGSEngine::getGameFolder() {
return Common::FSNode(ConfMan.get("path"));
return Common::FSNode(ConfMan.getPath("path"));
}
bool AGSEngine::canLoadGameStateCurrently(Common::U32String *msg) {

View File

@ -225,7 +225,7 @@ bool AGSConsole::Cmd_dumpSprite(int argc, const char **argv) {
return true;
}
Common::String pngFile = Common::String::format("%s-sprite%03d.png", _vm->getGameId().c_str(), spriteId);
Common::Path pngFile(Common::String::format("%s-sprite%03d.png", _vm->getGameId().c_str(), spriteId));
Common::DumpFile df;
if (df.open(pngFile)) {
byte *palette = nullptr;

View File

@ -147,14 +147,14 @@ ADDetectedGame AGSMetaEngineDetection::fallbackDetect(const FileMap &allFiles, c
if (file->isDirectory())
continue;
Common::String filename = file->getName();
if (!filename.hasSuffixIgnoreCase(".exe") &&
!filename.hasSuffixIgnoreCase(".ags") &&
Common::Path filename = file->getPathInArchive();
if (!filename.baseName().hasSuffixIgnoreCase(".exe") &&
!filename.baseName().hasSuffixIgnoreCase(".ags") &&
!filename.equalsIgnoreCase("ac2game.dat"))
// Neither, so move on
continue;
filename = Common::punycode_encodefilename(filename);
filename = filename.punycodeEncode();
Common::File f;
if (!allFiles.contains(filename) || !f.open(allFiles[filename]))
continue;
@ -177,7 +177,7 @@ ADDetectedGame AGSMetaEngineDetection::fallbackDetect(const FileMap &allFiles, c
AGS::g_fallbackDesc.desc.gameId = _gameid.c_str();
AGS::g_fallbackDesc.desc.extra = _extra.c_str();
AGS::g_fallbackDesc.desc.filesDescriptions[0].fileName = _filename.c_str();
AGS::g_fallbackDesc.desc.filesDescriptions[0].fileName = _filename.toString('/').c_str();
AGS::g_fallbackDesc.desc.filesDescriptions[0].fileSize = f.size();
AGS::g_fallbackDesc.desc.filesDescriptions[0].md5 = _md5.c_str();

View File

@ -67,7 +67,7 @@ enum AGSSpriteFontVersion { kAGSSpriteFont = 0, kClifftopGames = 1 };
class AGSMetaEngineDetection : public AdvancedMetaEngineDetection {
mutable Common::String _gameid;
mutable Common::String _extra;
mutable Common::String _filename;
mutable Common::Path _filename;
mutable Common::String _md5;
static const DebugChannelDef debugFlagList[];

View File

@ -64,7 +64,7 @@ AGSOptionsWidget::AGSOptionsWidget(GuiObject *boss, const Common::String &name,
_langPopUp = new GUI::PopUpWidget(widgetsBoss(), _dialogLayout + ".translation");
_langPopUp->appendEntry(_("<default>"), (uint32) - 1);
Common::String path = ConfMan.get("path", _domain);
Common::Path path = ConfMan.getPath("path", _domain);
Common::FSDirectory dir(path);
Common::ArchiveMemberList traFileList;
dir.listMatchingMembers(traFileList, "*.tra");

View File

@ -86,7 +86,7 @@ void FillDirList(std::set<String> &files, const String &path) {
String subDir = dirName.Mid(_GP(ResPaths).DataDir.GetLength());
if (!subDir.IsEmpty() && subDir[0u] == '/')
subDir.ClipLeft(1);
dirName = ConfMan.get("path");
dirName = ConfMan.getPath("path").toString('/');
} else if (dirName.CompareLeftNoCase(get_save_game_directory()) == 0) {
// Save files listing
FillSaveList(files, filePattern);

View File

@ -46,7 +46,7 @@ extern bool define_gamedata_location(const AGS::Shared::String &exe_path);
extern bool engine_try_init_gamedata(AGS::Shared::String gamepak_path);
void GameScanner::scan(const Common::String &startFolder) {
void GameScanner::scan(const Common::Path &startFolder) {
detectClashes();
Common::FSNode folder(startFolder);
@ -91,13 +91,13 @@ void GameScanner::scanFolder(const Common::FSNode &folder) {
} else if (filename.hasSuffixIgnoreCase(".exe") ||
filename.hasSuffixIgnoreCase(".ags") ||
filename.equalsIgnoreCase("ac2game.dat")) {
Common::String path = node.getPath();
Common::Path path = node.getPath();
scanFile(path);
}
}
}
void GameScanner::scanFile(const Common::String &filename) {
void GameScanner::scanFile(const Common::Path &filename) {
#ifdef TODO
Common::File f;
Common::FSNode fsNode(filename);

View File

@ -50,7 +50,7 @@ private:
/**
* Scans a single file that may be an AGS game
*/
void scanFile(const Common::String &filename);
void scanFile(const Common::Path &filename);
/**
* Convert a game name to an appropriate game Id
@ -65,7 +65,7 @@ public:
/**
* Main execution method
*/
void scan(const Common::String &startFolder);
void scan(const Common::Path &startFolder);
};
} // namespace AGS3

View File

@ -132,12 +132,12 @@ String FindGameData(const String &path, bool(*fn_testfile)(const String &)) {
if (folder.getChildren(files, Common::FSNode::kListFilesOnly)) {
for (Common::FSList::iterator it = files.begin(); it != files.end(); ++it) {
Common::String test_file = it->getName();
Common::String filePath = it->getPath();
Common::Path filePath = it->getPath();
if (test_file.hasSuffixIgnoreCase(".ags") ||
test_file.equalsIgnoreCase("ac2game.dat") ||
test_file.hasSuffixIgnoreCase(".exe")) {
if (IsMainGameLibrary(test_file.c_str()) && fn_testfile(filePath.c_str())) {
if (IsMainGameLibrary(test_file.c_str()) && fn_testfile(filePath.toString('/'))) {
Debug::Printf("Found game data pak: %s", test_file.c_str());
return test_file.c_str();
}

View File

@ -86,7 +86,8 @@ String GetCurrentDirectory() {
Path::FixupPath(str);
return str;
#else
return ConfMan.get("path");
// Use / separator
return ConfMan.getPath("path").toString('/');
#endif
}

View File

@ -54,18 +54,18 @@ static Common::FSNode getFSNode(const char *path) {
Common::FSNode node;
Common::String filePath(path);
if (filePath.empty() || filePath == "." || filePath == "./")
return Common::FSNode(ConfMan.get("path"));
return Common::FSNode(ConfMan.getPath("path"));
else if (filePath.hasPrefix("./")) {
filePath = filePath.substr(2);
node = Common::FSNode(ConfMan.get("path"));
node = Common::FSNode(ConfMan.getPath("path"));
} else if (filePath.hasPrefixIgnoreCase(AGS::Shared::SAVE_FOLDER_PREFIX)) {
filePath = filePath.substr(strlen(AGS::Shared::SAVE_FOLDER_PREFIX));
node = Common::FSNode(ConfMan.getPath("savepath"));
} else {
node = Common::FSNode(filePath);
node = Common::FSNode(Common::Path(filePath, '/'));
if (node.isReadable())
return node;
node = Common::FSNode(ConfMan.get("path"));
node = Common::FSNode(ConfMan.getPath("path"));
}
// Use FSDirectory for case-insensitive search
@ -74,7 +74,8 @@ static Common::FSNode getFSNode(const char *path) {
// Iterate through any further subfolders or filename
size_t separator;
while ((separator = filePath.find('/')) != Common::String::npos) {
dir.reset(dir->getSubDirectory(filePath.substr(0, separator)));
Common::Path member(filePath.substr(0, separator));
dir.reset(dir->getSubDirectory(member));
if (!dir)
return Common::FSNode();
filePath = Common::String(filePath.c_str() + separator + 1);
@ -83,13 +84,14 @@ static Common::FSNode getFSNode(const char *path) {
if (filePath.empty())
return dir->getFSNode();
if (dir->hasFile(filePath)) {
Common::ArchiveMemberPtr file = dir->getMember(filePath);
Common::Path member(filePath);
if (dir->hasFile(member)) {
Common::ArchiveMemberPtr file = dir->getMember(member);
if (file)
return dir->getFSNode().getChild(file->getName());
}
Common::FSDirectory *subDir = dir->getSubDirectory(filePath);
Common::FSDirectory *subDir = dir->getSubDirectory(member);
if (subDir) {
dir.reset(subDir);
return dir->getFSNode();