From 5bf14750f0d8be98a609647cf118555b278f002a Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 7 May 2024 07:14:11 -0400 Subject: [PATCH] Remove system::glob(). Use regex to find Fundamental package path in plugin::init(). --- include/system.hpp | 4 ---- src/plugin.cpp | 12 +++++++++++- src/system.cpp | 17 ----------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/system.hpp b/include/system.hpp index 4419939c..16172c91 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -24,10 +24,6 @@ std::string join(const std::string& path1, const std::string& path2, Paths... pa `depth` is the number of directories to recurse. 0 depth does not recurse. -1 depth recurses infinitely. */ std::vector getEntries(const std::string& dirPath, int depth = 0); -/** Expands a glob pattern such as `dir/file*.txt` to a list of paths. -Paths are sorted. -*/ -std::vector glob(const std::string& pattern); bool exists(const std::string& path); /** Returns whether the given path is a file. */ bool isFile(const std::string& path); diff --git a/src/plugin.cpp b/src/plugin.cpp index cff9a5c5..68940de7 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -244,6 +245,15 @@ static void extractPackages(std::string path) { } } +static std::string getFundamentalPackagePath() { + std::regex r("Fundamental-.*-" + APP_OS + "-" + APP_CPU + "\\.vcvplugin"); + for (const std::string& path : system::getEntries(asset::systemDir)) { + if (std::regex_match(system::getFilename(path), r)) + return path; + } + return ""; +} + //////////////////// // public API //////////////////// @@ -284,7 +294,7 @@ void init() { // If Fundamental wasn't loaded, copy the bundled Fundamental package and load it if (!settings::devMode && !getPlugin("Fundamental")) { - std::string fundamentalPackage = get(system::glob(asset::system("Fundamental-*-" + APP_OS + "-" + APP_CPU + ".vcvplugin")), 0); + std::string fundamentalPackage = getFundamentalPackagePath(); std::string fundamentalDir = system::join(pluginsPath, "Fundamental"); if (fundamentalPackage != "" && system::isFile(fundamentalPackage)) { INFO("Extracting bundled Fundamental package"); diff --git a/src/system.cpp b/src/system.cpp index 2e0a1bc3..d4130b18 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -9,7 +9,6 @@ #include #include #include // for abi::__cxa_demangle -#include #if defined ARCH_LIN || defined ARCH_MAC #include @@ -89,22 +88,6 @@ std::vector getEntries(const std::string& dirPath, int depth) { } -std::vector glob(const std::string& pattern) { - glob_t glob_result; - memset(&glob_result, 0, sizeof(glob_result)); - std::vector paths; - - if (!glob(pattern.c_str(), GLOB_BRACE, NULL, &glob_result)) { - for (size_t i = 0; i < glob_result.gl_pathc; i++) { - paths.push_back(std::string(glob_result.gl_pathv[i])); - } - } - - globfree(&glob_result); - return paths; -} - - bool exists(const std::string& path) { try { return fs::exists(fs::u8path(path));