Skip to content

Commit

Permalink
fix: 修复文件夹创建错误
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Dec 9, 2024
1 parent 19bce7e commit aee9c00
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 19 deletions.
5 changes: 1 addition & 4 deletions source/MaaFramework/Controller/ControllerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
9 changes: 4 additions & 5 deletions source/MaaProjectInterface/Impl/Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions source/MaaToolkit/Config/GlobalOptionConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions source/MaaUtils/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion source/include/ProjectInterface/Configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions source/include/Utils/ImageIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit aee9c00

Please sign in to comment.