From 8f0d2b3aef5457a7a0109b018b97d6f3329998cc Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 9 Oct 2023 18:10:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=AE=80=E5=8D=95=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8Bpipeline=E8=AF=BB=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaaFramework/Resource/PipelineResMgr.cpp | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/source/MaaFramework/Resource/PipelineResMgr.cpp b/source/MaaFramework/Resource/PipelineResMgr.cpp index 0e758bfdd..d04476baa 100644 --- a/source/MaaFramework/Resource/PipelineResMgr.cpp +++ b/source/MaaFramework/Resource/PipelineResMgr.cpp @@ -1,6 +1,7 @@ #include "PipelineResMgr.h" #include "Utils/Logger.h" +#include "Utils/StringMisc.hpp" #include "Vision/VisionTypes.h" #include @@ -50,29 +51,30 @@ bool PipelineResMgr::load_all_json(const std::filesystem::path& path) } bool loaded = false; - if (std::filesystem::is_directory(path)) { - for (auto& entry : std::filesystem::recursive_directory_iterator(path)) { - if (!entry.is_regular_file() || entry.path().extension() != ".json") { - continue; - } - loaded = open_and_parse_file(entry.path()); - if (!loaded) { - LogError << "open_and_parse_file failed" << VAR(entry.path()); - return false; - } - } + if (!std::filesystem::is_directory(path)) { + LogError << "path is not directory" << VAR(path); + return false; } - else if (std::filesystem::is_regular_file(path) && path.extension() == ".json") { - loaded = open_and_parse_file(path); + + for (auto& entry : std::filesystem::recursive_directory_iterator(path)) { + auto& entry_path = entry.path(); + if (!entry.is_regular_file()) { + LogWarn << "entry is not regular file, skip" << VAR(entry_path); + continue; + } + auto ext = path_to_utf8_string(entry_path.extension()); + tolowers_(ext); + if (ext != ".json") { + LogWarn << "entry is not *.json, skip" << VAR(entry_path) << VAR(ext); + continue; + } + + loaded &= open_and_parse_file(entry_path); if (!loaded) { - LogError << "open_and_parse_file failed" << VAR(path); + LogError << "open_and_parse_file failed" << VAR(entry_path); return false; } } - else { - LogError << "path is not directory or regular file"; - return false; - } return loaded; }