From eee7eb7d2faa220540cd3be78d6c6020e7ce72a2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 10 Oct 2024 15:05:56 -0700 Subject: [PATCH] Search the app-local directories separately first --- core/helpers.cpp | 46 ++++++++++++++++++++++++++++++++-------------- core/helpers.h | 4 +++- core/hrtf.cpp | 3 +++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/core/helpers.cpp b/core/helpers.cpp index 5e973bf2..a6573d25 100644 --- a/core/helpers.cpp +++ b/core/helpers.cpp @@ -137,7 +137,22 @@ struct CoTaskMemDeleter { } // namespace -std::vector SearchDataFiles(const std::string_view ext, const std::string_view subdir) +auto SearchDataFiles(const std::string_view ext) -> std::vector +{ + auto srchlock = std::lock_guard{gSearchLock}; + + /* Search the app-local directory. */ + auto results = std::vector{}; + if(auto localpath = al::getenv(L"ALSOFT_LOCAL_PATH")) + DirectorySearch(*localpath, ext, &results); + else if(auto curpath = std::filesystem::current_path(); !curpath.empty()) + DirectorySearch(curpath, ext, &results); + + return results; +} + +auto SearchDataFiles(const std::string_view ext, const std::string_view subdir) + -> std::vector { std::lock_guard srchlock{gSearchLock}; @@ -150,12 +165,6 @@ std::vector SearchDataFiles(const std::string_view ext, const std:: return results; } - /* Search the app-local directory. */ - if(auto localpath = al::getenv(L"ALSOFT_LOCAL_PATH")) - DirectorySearch(*localpath, ext, &results); - else if(auto curpath = std::filesystem::current_path(); !curpath.empty()) - DirectorySearch(curpath, ext, &results); - #if !defined(ALSOFT_UWP) && !defined(_GAMING_XBOX) /* Search the local and global data dirs. */ for(const auto &folderid : std::array{FOLDERID_RoamingAppData, FOLDERID_ProgramData}) @@ -295,7 +304,22 @@ const PathNamePair &GetProcBinary() return procbin; } -std::vector SearchDataFiles(const std::string_view ext, const std::string_view subdir) +auto SearchDataFiles(const std::string_view ext) -> std::vector +{ + auto srchlock = std::lock_guard{gSearchLock}; + + /* Search the app-local directory. */ + auto results = std::vector{}; + if(auto localpath = al::getenv("ALSOFT_LOCAL_PATH")) + DirectorySearch(*localpath, ext, &results); + else if(auto curpath = std::filesystem::current_path(); !curpath.empty()) + DirectorySearch(curpath, ext, &results); + + return results; +} + +auto SearchDataFiles(const std::string_view ext, const std::string_view subdir) + -> std::vector { std::lock_guard srchlock{gSearchLock}; @@ -307,12 +331,6 @@ std::vector SearchDataFiles(const std::string_view ext, const std:: return results; } - /* Search the app-local directory. */ - if(auto localpath = al::getenv("ALSOFT_LOCAL_PATH")) - DirectorySearch(*localpath, ext, &results); - else if(auto curpath = std::filesystem::current_path(); !curpath.empty()) - DirectorySearch(curpath, ext, &results); - /* Search local data dir */ if(auto datapath = al::getenv("XDG_DATA_HOME")) DirectorySearch(std::filesystem::path{*datapath}/path, ext, &results); diff --git a/core/helpers.h b/core/helpers.h index 3a987c9d..96987a2e 100644 --- a/core/helpers.h +++ b/core/helpers.h @@ -19,6 +19,8 @@ inline bool AllowRTTimeLimit{true}; void SetRTPriority(); -std::vector SearchDataFiles(const std::string_view ext, const std::string_view subdir); +auto SearchDataFiles(const std::string_view ext) -> std::vector; +auto SearchDataFiles(const std::string_view ext, const std::string_view subdir) + -> std::vector; #endif /* CORE_HELPERS_H */ diff --git a/core/hrtf.cpp b/core/hrtf.cpp index e2f0d893..9833b125 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -1210,6 +1210,9 @@ std::vector EnumerateHrtf(std::optional pathopt) std::lock_guard enumlock{EnumeratedHrtfLock}; EnumeratedHrtfs.clear(); + for(const auto &fname : SearchDataFiles(".mhr"sv)) + AddFileEntry(fname); + bool usedefaults{true}; if(pathopt) { -- 2.11.4.GIT