AGS: Fix FillDirList implementation

This function is used to list files that match a given pattern.
For example Kathy Rain uses it to list ./*.tra files. The
original engine uses al_findfirst() and al_findnext().
This fixes listing the available languages in the Kathy
Rain in-game options.
This commit is contained in:
Thierry Crozat
2021-03-13 03:28:22 +00:00
parent 1bad267805
commit 8fb9b5f9d5
2 changed files with 31 additions and 7 deletions
+9 -2
View File
@@ -312,8 +312,15 @@ bool ResolveScriptPath(const String &orig_sc_path, bool read_only, ResolvedPath
// Remap "agsgame.*"
const char *agsSavePrefix = "/agssave.";
if (child_path.CompareLeft(agsSavePrefix) == 0) {
int slotNum = child_path.Mid(strlen(agsSavePrefix)).ToInt();
child_path = ::AGS::g_vm->getSaveStateName(slotNum);
String suffix = child_path.Mid(strlen(agsSavePrefix));
if (suffix.CompareLeft("*") == 0) {
Common::String file_name = ::AGS::g_vm->getSaveStateName(999);
Common::replace(file_name, "999", "*");
child_path = file_name;
} else {
int slotNum = suffix.ToInt();
child_path = ::AGS::g_vm->getSaveStateName(slotNum);
}
}
#endif
} else if (sc_path.CompareLeft(GameDataDirToken) == 0) {
+22 -5
View File
@@ -33,6 +33,7 @@
#include "ags/engine/debugging/debug_log.h"
#include "ags/shared/debugging/out.h"
#include "ags/shared/util/path.h"
#include "ags/engine/script/script_api.h"
#include "ags/engine/script/script_runtime.h"
#include "ags/engine/ac/dynobj/scriptstring.h"
@@ -40,6 +41,7 @@
#include "ags/ags.h"
#include "common/fs.h"
#include "common/savefile.h"
#include "common/config-manager.h"
namespace AGS3 {
@@ -72,12 +74,26 @@ void ListBox_Clear(GUIListBox *listbox) {
}
void FillDirList(std::set<String> &files, const String &path) {
Common::FSNode folder(path);
Common::FSList fsList;
folder.getChildren(fsList, Common::FSNode::kListAll);
String dirName = Path::GetDirectoryPath(path);
String filePattern = Path::get_filename(path);
if (dirName.CompareLeftNoCase(get_install_dir()) == 0) {
String subDir = dirName.Mid(get_install_dir().GetLength());
if (!subDir.IsEmpty() && subDir[0u] == '/')
subDir.ClipLeft(1);
dirName = ConfMan.get("path");
} else if (dirName.CompareLeftNoCase(get_save_game_directory()) == 0) {
String subDir = dirName.Mid(get_save_game_directory().GetLength());
if (!subDir.IsEmpty() && subDir[0u] == '/')
subDir.ClipLeft(1);
dirName = Path::ConcatPaths(ConfMan.get("savepath"), subDir);
}
for (uint idx = 0; idx < fsList.size(); ++idx)
files.insert(fsList[idx].getName());
Common::FSDirectory dir(dirName);
Common::ArchiveMemberList fileList;
dir.listMatchingMembers(fileList, filePattern);
for (Common::ArchiveMemberList::iterator iter = fileList.begin(); iter != fileList.end(); ++iter) {
files.insert((*iter)->getName());
}
}
void ListBox_FillDirList(GUIListBox *listbox, const char *filemask) {
@@ -85,6 +101,7 @@ void ListBox_FillDirList(GUIListBox *listbox, const char *filemask) {
guis_need_update = 1;
ResolvedPath rp;
ResolveScriptPath("$SAVEGAMEDIR$/agssave.*", true, rp);
if (!ResolveScriptPath(filemask, true, rp))
return;