Skip to content

Commit f9f0747

Browse files
committed
(Sim)RM95: Use detection suggested by @florianessl
1 parent 9dc544e commit f9f0747

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

src/directory_tree.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,40 @@ std::unique_ptr<DirectoryTree> DirectoryTree::Create(Filesystem& fs) {
5252
}
5353

5454
bool DirectoryTree::WildcardMatch(const StringView& pattern, const StringView& text) {
55-
if (pattern.length() != text.length()) {
56-
return false;
55+
// Limitations: * and ? cannot be mixed, * only at beginning and end of string
56+
// Input is already lower-cased
57+
if (pattern.empty() && text.empty()) {
58+
return true;
5759
}
5860

59-
std::string pattern_norm = make_key(pattern);
60-
std::string text_norm = make_key(text);
61+
bool begin_wildcard = pattern.starts_with('*');
62+
bool end_wildcard = pattern.ends_with('*');
6163

62-
return std::equal(pattern_norm.begin(), pattern_norm.end(),
63-
text_norm.begin(),
64-
[](char p, char t) {
65-
return p == '?' || p == t;
66-
});
64+
if ((begin_wildcard || end_wildcard) && text.size() > 0) {
65+
// * handling
66+
bool found = false;
67+
if (begin_wildcard) {
68+
found |= text.ends_with(pattern.substr(1));
69+
}
70+
if (end_wildcard) {
71+
found |= text.starts_with(pattern.substr(0, pattern.size() - 1));
72+
}
73+
return found;
74+
} else {
75+
// ? handling
76+
if (pattern.length() != text.length()) {
77+
return false;
78+
}
79+
80+
std::string pattern_norm = make_key(pattern);
81+
std::string text_norm = make_key(text);
82+
83+
return std::equal(pattern_norm.begin(), pattern_norm.end(),
84+
text_norm.begin(),
85+
[](char p, char t) {
86+
return p == '?' || p == t;
87+
});
88+
}
6789
}
6890

6991
DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory(StringView path) const {

src/filefinder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ FileFinder::ProjectType FileFinder::GetProjectType(const FilesystemView &fs) {
347347
return FileFinder::ProjectType::Encrypted2k3Maniacs;
348348
}
349349

350-
if (!fs.FindFile("Game.RPG").empty()) {
351-
return FileFinder::ProjectType::RpgMaker95;
352-
}
353-
354-
if (!fs.FindFile("Game.DAT").empty()) {
355-
return FileFinder::ProjectType::SimRpgMaker95;
350+
if (!fs.FindFile("SWNAME.DAT").empty()) {
351+
if (!fs.FindFile("GEOLOGY.DAT").empty()) {
352+
return FileFinder::ProjectType::SimRpgMaker95;
353+
} else if (args.path = "*.RPG"; !fs.FindFile(args).empty()) {
354+
return FileFinder::ProjectType::RpgMaker95;
355+
}
356356
}
357357

358358
return FileFinder::ProjectType::Unknown;

0 commit comments

Comments
 (0)