File tree Expand file tree Collapse file tree 2 files changed +34
-15
lines changed
Expand file tree Collapse file tree 2 files changed +34
-15
lines changed Original file line number Diff line number Diff line change @@ -52,18 +52,37 @@ std::unique_ptr<DirectoryTree> DirectoryTree::Create(Filesystem& fs) {
5252}
5353
5454bool 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+ // Pattern and text are already normalized
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+ return std::equal (pattern.begin (), pattern.end (),
81+ text.begin (),
82+ [](char p, char t) {
83+ return p == ' ?' || p == t;
84+ });
85+ }
6786}
6887
6988DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory (StringView path) const {
Original file line number Diff line number Diff 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;
You can’t perform that action at this time.
0 commit comments