From aee9c003ef1ae0208275ae7573ac3afbd0f56a9b Mon Sep 17 00:00:00 2001 From: MistEO Date: Mon, 9 Dec 2024 14:55:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=88=9B=E5=BB=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/MaaFramework/Controller/ControllerAgent.cpp | 5 +---- source/MaaProjectInterface/Impl/Configurator.cpp | 9 ++++----- source/MaaToolkit/Config/GlobalOptionConfig.cpp | 5 ++--- source/MaaUtils/Logger/Logger.cpp | 5 +---- source/include/ProjectInterface/Configurator.h | 2 +- source/include/Utils/ImageIo.h | 4 ++-- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/source/MaaFramework/Controller/ControllerAgent.cpp b/source/MaaFramework/Controller/ControllerAgent.cpp index 053703ec7..fea4bf6b2 100644 --- a/source/MaaFramework/Controller/ControllerAgent.cpp +++ b/source/MaaFramework/Controller/ControllerAgent.cpp @@ -601,10 +601,7 @@ bool ControllerAgent::recording() const void ControllerAgent::init_recording() { auto recording_dir = GlobalOptionMgr::get_instance().log_dir() / "recording"; - if (std::error_code ec; !std::filesystem::create_directories(recording_dir, ec)) { - LogError << "failed to create_directories" << VAR(recording_dir) << VAR(ec.message()); - return; - } + std::filesystem::create_directories(recording_dir); recording_path_ = recording_dir / std::format("maa_recording_{}.txt", format_now_for_filename()); } diff --git a/source/MaaProjectInterface/Impl/Configurator.cpp b/source/MaaProjectInterface/Impl/Configurator.cpp index cf876ec3e..354de600a 100644 --- a/source/MaaProjectInterface/Impl/Configurator.cpp +++ b/source/MaaProjectInterface/Impl/Configurator.cpp @@ -24,7 +24,7 @@ bool Configurator::load(const std::filesystem::path& resource_dir, const std::fi return false; } - if (auto cfg_opt = Parser::parse_config(user_dir / kConfigFilename)) { + if (auto cfg_opt = Parser::parse_config(user_dir / kConfigPath)) { config_ = *std::move(cfg_opt); first_time_use_ = false; } @@ -51,10 +51,9 @@ void Configurator::save(const std::filesystem::path& user_dir) { LogInfo << VAR(user_dir); - const auto config_path = user_dir / kConfigFilename; - if (std::error_code ec; config_path.has_parent_path() && !std::filesystem::create_directories(config_path.parent_path(), ec)) { - LogError << "failed to create_directories" << VAR(config_path.parent_path()) << VAR(ec.message()); - return; + const auto config_path = user_dir / kConfigPath; + if (config_path.has_parent_path()) { + std::filesystem::create_directories(config_path.parent_path()); } std::ofstream ofs(config_path); diff --git a/source/MaaToolkit/Config/GlobalOptionConfig.cpp b/source/MaaToolkit/Config/GlobalOptionConfig.cpp index a953148bd..0674af219 100644 --- a/source/MaaToolkit/Config/GlobalOptionConfig.cpp +++ b/source/MaaToolkit/Config/GlobalOptionConfig.cpp @@ -88,9 +88,8 @@ bool GlobalOptionConfig::save() const { LogInfo; - if (std::error_code ec; config_path_.has_parent_path() && !std::filesystem::create_directories(config_path_.parent_path(), ec)) { - LogError << "failed to create_directories" << VAR(config_path_.parent_path()) << VAR(ec.message()); - return false; + if (config_path_.has_parent_path()) { + std::filesystem::create_directories(config_path_.parent_path()); } std::ofstream ofs(config_path_, std::ios::out); diff --git a/source/MaaUtils/Logger/Logger.cpp b/source/MaaUtils/Logger/Logger.cpp index b59867e41..3b49e5c08 100644 --- a/source/MaaUtils/Logger/Logger.cpp +++ b/source/MaaUtils/Logger/Logger.cpp @@ -154,10 +154,7 @@ void Logger::open() if (log_path_.empty()) { return; } - - if (std::error_code ec; !std::filesystem::create_directories(log_dir_, ec)) { - return; - } + std::filesystem::create_directories(log_dir_); std::unique_lock trace_lock(trace_mutex_); if (ofs_.is_open()) { diff --git a/source/include/ProjectInterface/Configurator.h b/source/include/ProjectInterface/Configurator.h index 92a292a58..9580ad769 100644 --- a/source/include/ProjectInterface/Configurator.h +++ b/source/include/ProjectInterface/Configurator.h @@ -10,7 +10,7 @@ MAA_PROJECT_INTERFACE_NS_BEGIN class Configurator { static constexpr std::string_view kInterfaceFilename = "interface.json"; - static constexpr std::string_view kConfigFilename = "config/maa_pi_config.json"; + static constexpr std::string_view kConfigPath = "config/maa_pi_config.json"; public: bool load(const std::filesystem::path& project_dir, const std::filesystem::path& user_dir); diff --git a/source/include/Utils/ImageIo.h b/source/include/Utils/ImageIo.h index 0d0a3284a..78d581336 100644 --- a/source/include/Utils/ImageIo.h +++ b/source/include/Utils/ImageIo.h @@ -28,8 +28,8 @@ inline cv::Mat imread(const std::string& utf8_path, int flags = cv::IMREAD_COLOR inline bool imwrite(const std::filesystem::path& path, cv::InputArray img) { - if (std::error_code ec; path.has_parent_path() && !std::filesystem::create_directories(path.parent_path(), ec)) { - return false; + if (path.has_parent_path()) { + std::filesystem::create_directories(path.parent_path()); } auto ext = path_to_utf8_string(path.extension());