[Scummvm-git-logs] scummvm master -> 7dfb0020266fbecb912eedae2e0ff00ec573f585
sev-
sev at scummvm.org
Mon May 24 20:52:05 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
fdc5e88e30 DIRECTOR: modify the logic of lingo-builtin function NthFileName
7dfb002026 DIRECTOR: use tokenizer to replace the split
Commit: fdc5e88e30751285ac4f0fcc936c5ccb0b01eae4
https://github.com/scummvm/scummvm/commit/fdc5e88e30751285ac4f0fcc936c5ccb0b01eae4
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-05-24T22:52:01+02:00
Commit Message:
DIRECTOR: modify the logic of lingo-builtin function NthFileName
Changed paths:
engines/director/lingo/lingo-builtins.cpp
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 3e082b0b20..a42ffef18d 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1083,7 +1083,47 @@ void LB::b_getNthFileNameInFolder(int nargs) {
int fileNum = g_lingo->pop().asInt() - 1;
Common::String path = pathMakeRelative(g_lingo->pop().asString(), true, false, true);
- Common::FSNode d = Common::FSNode(*g_director->getGameDataDir()).getChild(path);
+ Common::Array<Common::String> directory_list;
+
+ // this part is to split string by /
+ // i think we need to wrap this to function
+ uint last = 0;
+ for (uint i = 0; i < path.size(); i++) {
+ if (path[i] == '/') {
+ directory_list.push_back(path.substr(last, i - last));
+ last = i + 1;
+ }
+ }
+ if (last != path.size())
+ directory_list.push_back(path.substr(last, path.size() - last));
+
+ Common::FSNode d = Common::FSNode(*g_director->getGameDataDir());
+ if (d.getChild(directory_list[0]).exists()) {
+ // then this part is for the "relative to current directory"
+ // we find the child directory recursively
+ uint current_pos = 0;
+ while (current_pos < directory_list.size() && d.exists()) {
+ d = d.getChild(directory_list[current_pos]);
+ current_pos++;
+ }
+ } else {
+ // we first match the path with game data dir
+ uint current_pos = 0;
+ while (current_pos < directory_list.size()) {
+ if (directory_list[current_pos].equalsIgnoreCase(d.getName()))
+ break;
+ current_pos++;
+ }
+ if (current_pos == directory_list.size())
+ error("Cannot find game directory in path %s\n", path.c_str());
+ // then we go deep to the end of path
+ // skip the current directory which is the game data directory
+ current_pos++;
+ while (current_pos < directory_list.size() && d.exists()) {
+ d = d.getChild(directory_list[current_pos]);
+ current_pos++;
+ }
+ }
Datum r;
if (d.exists()) {
@@ -1091,8 +1131,14 @@ void LB::b_getNthFileNameInFolder(int nargs) {
if (!d.getChildren(f, Common::FSNode::kListAll)) {
warning("Cannot acces directory %s", path.c_str());
} else {
- if ((uint)fileNum < f.size())
- r = Datum(f.operator[](fileNum).getName());
+ if ((uint)fileNum < f.size()) {
+ // here, we sort all the fileNames
+ Common::Array<Common::String> fileNameList;
+ for (uint i = 0; i < f.size(); i++)
+ fileNameList.push_back(f[i].getName());
+ Common::sort(fileNameList.begin(), fileNameList.end());
+ r = Datum(fileNameList[fileNum]);
+ }
}
}
Commit: 7dfb0020266fbecb912eedae2e0ff00ec573f585
https://github.com/scummvm/scummvm/commit/7dfb0020266fbecb912eedae2e0ff00ec573f585
Author: ysj1173886760 (1173886760 at qq.com)
Date: 2021-05-24T22:52:01+02:00
Commit Message:
DIRECTOR: use tokenizer to replace the split
Changed paths:
engines/director/lingo/lingo-builtins.cpp
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index a42ffef18d..ec2e5cf13b 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -21,6 +21,7 @@
*/
#include "common/system.h"
+#include "common/tokenizer.h"
#include "gui/message.h"
@@ -1083,46 +1084,25 @@ void LB::b_getNthFileNameInFolder(int nargs) {
int fileNum = g_lingo->pop().asInt() - 1;
Common::String path = pathMakeRelative(g_lingo->pop().asString(), true, false, true);
- Common::Array<Common::String> directory_list;
-
- // this part is to split string by /
- // i think we need to wrap this to function
- uint last = 0;
- for (uint i = 0; i < path.size(); i++) {
- if (path[i] == '/') {
- directory_list.push_back(path.substr(last, i - last));
- last = i + 1;
- }
- }
- if (last != path.size())
- directory_list.push_back(path.substr(last, path.size() - last));
+ Common::StringTokenizer directory_list(path, "/");
Common::FSNode d = Common::FSNode(*g_director->getGameDataDir());
- if (d.getChild(directory_list[0]).exists()) {
+ if (d.getChild(directory_list.nextToken()).exists()) {
// then this part is for the "relative to current directory"
// we find the child directory recursively
- uint current_pos = 0;
- while (current_pos < directory_list.size() && d.exists()) {
- d = d.getChild(directory_list[current_pos]);
- current_pos++;
- }
+ directory_list.reset();
+ while (!directory_list.empty() && d.exists())
+ d = d.getChild(directory_list.nextToken());
} else {
// we first match the path with game data dir
- uint current_pos = 0;
- while (current_pos < directory_list.size()) {
- if (directory_list[current_pos].equalsIgnoreCase(d.getName()))
+ while (!directory_list.empty())
+ if (directory_list.nextToken().equalsIgnoreCase(d.getName()))
break;
- current_pos++;
- }
- if (current_pos == directory_list.size())
- error("Cannot find game directory in path %s\n", path.c_str());
// then we go deep to the end of path
// skip the current directory which is the game data directory
- current_pos++;
- while (current_pos < directory_list.size() && d.exists()) {
- d = d.getChild(directory_list[current_pos]);
- current_pos++;
- }
+ directory_list.nextToken();
+ while (!directory_list.empty() && d.exists())
+ d = d.getChild(directory_list.nextToken());
}
Datum r;
More information about the Scummvm-git-logs
mailing list