@@ -19,10 +19,22 @@ recorder::RecordingWriter::RecordingWriter(RecordingWriter&& old) noexcept
1919helper::expected<recorder::RecordingWriter, std::string> recorder::RecordingWriter::get_writer (
2020 const std::filesystem::path& path,
2121 std::vector<TetrionHeader>&& tetrion_headers,
22- AdditionalInformation&& information
22+ AdditionalInformation&& information,
23+ bool overwrite
2324) {
25+ auto mode = std::ios::out | std::ios::binary;
26+ if (overwrite) {
27+ if (std::filesystem::exists (path)) {
28+ return helper::unexpected<std::string>{
29+ fmt::format (" file already exists, not overwriting it: \" {}\" " , path.string ())
30+ };
31+ }
32+ } else {
33+ mode |= std::ios::trunc;
34+ }
35+
2436
25- auto output_file = std::ofstream{ path, std::ios::out | std::ios::binary };
37+ auto output_file = std::ofstream{ path, mode };
2638
2739 if (not output_file) {
2840 return helper::unexpected<std::string>{ fmt::format (" failed to open output file \" {}\" " , path.string ()) };
@@ -74,7 +86,7 @@ helper::expected<recorder::RecordingWriter, std::string> recorder::RecordingWrit
7486 return RecordingWriter{ std::move (output_file), std::move (tetrion_headers), std::move (information) };
7587}
7688
77- helper::expected<void , std::string> recorder::RecordingWriter::add_event (
89+ helper::expected<void , std::string> recorder::RecordingWriter::add_record (
7890 const u8 tetrion_index, // NOLINT(bugprone-easily-swappable-parameters)
7991 const u64 simulation_step_index,
8092 const InputEvent event
@@ -108,7 +120,6 @@ helper::expected<void, std::string> recorder::RecordingWriter::add_event(
108120}
109121
110122helper::expected<void , std::string> recorder::RecordingWriter::add_snapshot (
111- const u8 tetrion_index,
112123 const u64 simulation_step_index,
113124 std::unique_ptr<TetrionCoreInformation> information
114125) {
@@ -121,9 +132,8 @@ helper::expected<void, std::string> recorder::RecordingWriter::add_snapshot(
121132 return helper::unexpected<std::string>{ result.error () };
122133 }
123134
124- const auto snapshot = TetrionSnapshot{ tetrion_index, information->level ,
125- information->score , information->lines_cleared ,
126- simulation_step_index, information->mino_stack };
135+ const auto snapshot = TetrionSnapshot{ information->tetrion_index , information->level , information->score ,
136+ information->lines_cleared , simulation_step_index, information->mino_stack };
127137
128138 const auto bytes = snapshot.to_bytes ();
129139 result = helper::writer::write_vector_to_file (m_output_file, bytes);
0 commit comments