| 
13 | 13 | #include "input_creator.hpp"  | 
14 | 14 | 
 
  | 
15 | 15 | #include <fmt/format.h>  | 
 | 16 | +#include <spdlog/spdlog.h>  | 
16 | 17 | #include <stdexcept>  | 
17 | 18 | 
 
  | 
18 | 19 | namespace {  | 
@@ -123,32 +124,34 @@ input::get_game_parameters_for_replay(  | 
123 | 124 | 
 
  | 
124 | 125 |     const auto recording_directory_path = utils::get_root_folder() / constants::recordings_directory;  | 
125 | 126 | 
 
  | 
126 |  | -    if (not std::filesystem::exists(recording_directory_path)) {  | 
127 |  | -        std::filesystem::create_directory(recording_directory_path);  | 
128 |  | -    }  | 
129 | 127 | 
 
  | 
130 |  | -    const auto date_time_str = date.to_string();  | 
 | 128 | +    auto dir_result = utils::create_directory(recording_directory_path, true);  | 
 | 129 | +    if (not dir_result.has_value()) {  | 
131 | 130 | 
 
  | 
132 |  | -    if (not date_time_str.has_value()) {  | 
133 |  | -        throw std::runtime_error{ fmt::format("Erro in date to string conversion: {}", date_time_str.error()) };  | 
134 |  | -    }  | 
 | 131 | +        const auto date_time_str = date.to_string();  | 
135 | 132 | 
 
  | 
136 |  | -    const auto filename = fmt::format("{}.{}", date_time_str.value(), constants::recording::extension);  | 
137 |  | -    const auto file_path = recording_directory_path / filename;  | 
 | 133 | +        if (not date_time_str.has_value()) {  | 
 | 134 | +            throw std::runtime_error{ fmt::format("Erro in date to string conversion: {}", date_time_str.error()) };  | 
 | 135 | +        }  | 
138 | 136 | 
 
  | 
 | 137 | +        const auto filename = fmt::format("{}.{}", date_time_str.value(), constants::recording::extension);  | 
 | 138 | +        const auto file_path = recording_directory_path / filename;  | 
139 | 139 | 
 
  | 
140 |  | -    auto recording_writer_create_result =  | 
141 |  | -            recorder::RecordingWriter::get_writer(file_path, std::move(tetrion_headers), std::move(information));  | 
142 |  | -    if (not recording_writer_create_result.has_value()) {  | 
143 |  | -        throw std::runtime_error(recording_writer_create_result.error());  | 
144 |  | -    }  | 
145 | 140 | 
 
  | 
146 |  | -    const auto recording_writer =  | 
147 |  | -            std::make_shared<recorder::RecordingWriter>(std::move(recording_writer_create_result.value()));  | 
 | 141 | +        auto recording_writer_create_result =  | 
 | 142 | +                recorder::RecordingWriter::get_writer(file_path, std::move(tetrion_headers), std::move(information));  | 
 | 143 | +        if (not recording_writer_create_result.has_value()) {  | 
 | 144 | +            throw std::runtime_error(recording_writer_create_result.error());  | 
 | 145 | +        }  | 
148 | 146 | 
 
  | 
 | 147 | +        const auto recording_writer =  | 
 | 148 | +                std::make_shared<recorder::RecordingWriter>(std::move(recording_writer_create_result.value()));  | 
149 | 149 | 
 
  | 
150 |  | -    std::get<1>(result).recording_writer = recording_writer;  | 
151 | 150 | 
 
  | 
 | 151 | +        std::get<1>(result).recording_writer = recording_writer;  | 
 | 152 | +    } else {  | 
 | 153 | +        spdlog::warn("Couldn't create recordings folder {}: skipping creation of a recording", dir_result.value());  | 
 | 154 | +    }  | 
152 | 155 | 
 
  | 
153 | 156 |     return result;  | 
154 | 157 | }  | 
0 commit comments