From f9f0747353654253667e720821b2a3d182dc2840 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 20 Jan 2025 19:03:54 +0100 Subject: [PATCH] (Sim)RM95: Use detection suggested by @florianessl --- src/directory_tree.cpp | 40 +++++++++++++++++++++++++++++++--------- src/filefinder.cpp | 12 ++++++------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/directory_tree.cpp b/src/directory_tree.cpp index d20f4b12b9..639ae88a36 100644 --- a/src/directory_tree.cpp +++ b/src/directory_tree.cpp @@ -52,18 +52,40 @@ std::unique_ptr DirectoryTree::Create(Filesystem& fs) { } bool DirectoryTree::WildcardMatch(const StringView& pattern, const StringView& text) { - if (pattern.length() != text.length()) { - return false; + // Limitations: * and ? cannot be mixed, * only at beginning and end of string + // Input is already lower-cased + if (pattern.empty() && text.empty()) { + return true; } - std::string pattern_norm = make_key(pattern); - std::string text_norm = make_key(text); + bool begin_wildcard = pattern.starts_with('*'); + bool end_wildcard = pattern.ends_with('*'); - return std::equal(pattern_norm.begin(), pattern_norm.end(), - text_norm.begin(), - [](char p, char t) { - return p == '?' || p == t; - }); + if ((begin_wildcard || end_wildcard) && text.size() > 0) { + // * handling + bool found = false; + if (begin_wildcard) { + found |= text.ends_with(pattern.substr(1)); + } + if (end_wildcard) { + found |= text.starts_with(pattern.substr(0, pattern.size() - 1)); + } + return found; + } else { + // ? handling + if (pattern.length() != text.length()) { + return false; + } + + std::string pattern_norm = make_key(pattern); + std::string text_norm = make_key(text); + + return std::equal(pattern_norm.begin(), pattern_norm.end(), + text_norm.begin(), + [](char p, char t) { + return p == '?' || p == t; + }); + } } DirectoryTree::DirectoryListType* DirectoryTree::ListDirectory(StringView path) const { diff --git a/src/filefinder.cpp b/src/filefinder.cpp index dfb680e7f7..ccc2b841e5 100644 --- a/src/filefinder.cpp +++ b/src/filefinder.cpp @@ -347,12 +347,12 @@ FileFinder::ProjectType FileFinder::GetProjectType(const FilesystemView &fs) { return FileFinder::ProjectType::Encrypted2k3Maniacs; } - if (!fs.FindFile("Game.RPG").empty()) { - return FileFinder::ProjectType::RpgMaker95; - } - - if (!fs.FindFile("Game.DAT").empty()) { - return FileFinder::ProjectType::SimRpgMaker95; + if (!fs.FindFile("SWNAME.DAT").empty()) { + if (!fs.FindFile("GEOLOGY.DAT").empty()) { + return FileFinder::ProjectType::SimRpgMaker95; + } else if (args.path = "*.RPG"; !fs.FindFile(args).empty()) { + return FileFinder::ProjectType::RpgMaker95; + } } return FileFinder::ProjectType::Unknown;