From ed2036432b6907820a1585f419c6d2d119cfa3dd Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sat, 27 Apr 2024 19:20:11 -0500 Subject: [PATCH] Use raw file IO instead of buffered when saving --- src/g_gamedata.cpp | 11 ++++------- src/k_profiles.cpp | 17 +++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/g_gamedata.cpp b/src/g_gamedata.cpp index 14ad25d1a..6fe481c5e 100644 --- a/src/g_gamedata.cpp +++ b/src/g_gamedata.cpp @@ -294,17 +294,14 @@ void srb2::save_ng_gamedata() { std::string tmpsavepathstring = tmpsavepath.string(); srb2::io::FileStream file {tmpsavepathstring, srb2::io::FileStreamMode::kWrite}; - srb2::io::BufferedOutputStream bos {std::move(file)}; // The header is necessary to validate during loading. - srb2::io::write(static_cast(GD_VERSION_MAJOR), bos); // major - srb2::io::write(static_cast(GD_VERSION_MINOR), bos); // minor/flags - srb2::io::write(static_cast(gamedata->evercrashed), bos); // dirty (crash recovery) + srb2::io::write(static_cast(GD_VERSION_MAJOR), file); // major + srb2::io::write(static_cast(GD_VERSION_MINOR), file); // minor/flags + srb2::io::write(static_cast(gamedata->evercrashed), file); // dirty (crash recovery) std::vector ubjson = json::to_ubjson(ng); - srb2::io::write_exact(bos, tcb::as_bytes(tcb::make_span(ubjson))); - bos.flush(); - file = bos.stream(); + srb2::io::write_exact(file, tcb::as_bytes(tcb::make_span(ubjson))); file.close(); } catch (const srb2::io::FileStreamException& ex) diff --git a/src/k_profiles.cpp b/src/k_profiles.cpp index 1d8a9a8f8..cc15ee1af 100644 --- a/src/k_profiles.cpp +++ b/src/k_profiles.cpp @@ -320,17 +320,14 @@ void PR_SaveProfiles(void) try { io::FileStream file {tmppath, io::FileStreamMode::kWrite}; - io::BufferedOutputStream bos {std::move(file)}; - io::write(static_cast(0x52494E47), bos, io::Endian::kBE); // "RING" - io::write(static_cast(0x5052464C), bos, io::Endian::kBE); // "PRFL" - io::write(static_cast(0), bos); // reserved1 - io::write(static_cast(0), bos); // reserved2 - io::write(static_cast(0), bos); // reserved3 - io::write(static_cast(0), bos); // reserved4 - io::write_exact(bos, tcb::as_bytes(tcb::make_span(ubjson))); - bos.flush(); - file = bos.stream(); + io::write(static_cast(0x52494E47), file, io::Endian::kBE); // "RING" + io::write(static_cast(0x5052464C), file, io::Endian::kBE); // "PRFL" + io::write(static_cast(0), file); // reserved1 + io::write(static_cast(0), file); // reserved2 + io::write(static_cast(0), file); // reserved3 + io::write(static_cast(0), file); // reserved4 + io::write_exact(file, tcb::as_bytes(tcb::make_span(ubjson))); file.close(); fs::rename(tmppath, realpath);