From 597a710e2bf6bbdfa30606a5a1bbe0fad90dbba8 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 5 Jul 2021 18:49:13 -0700 Subject: [PATCH] :rewind: made save function absolute --- src/bank.cpp | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/src/bank.cpp b/src/bank.cpp index 2ec8bda..2602116 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -250,40 +250,34 @@ BankResponse Bank::DelUser(const std::string &name) noexcept } void Bank::Save() { -#if CONSERVATIVE_DISK_SAVE - if (GetChangeState()) - { -#endif - Json::Value temp; + Json::Value temp; - //loading info into json temp + //loading info into json temp + { + std::unique_lock lock{save_lock}; + for (const auto &u : users) { - std::unique_lock lock{save_lock}; - for (const auto &u : users) - { - //we know it contains this key but we call this func to grab mutex - users.if_contains(u.first, [&temp, &u](const User &u_val) { temp[u.first] = u_val.Serialize(); }); - } - } - if (temp.isNull()) - { - throw std::invalid_argument("Saving Failed\n"); - } - else - { - std::ofstream user_save(users_location); - Json::StreamWriterBuilder builder; - const std::unique_ptr writer(builder.newStreamWriter()); - writer->write(temp, &user_save); - user_save.close(); + //we know it contains this key but we call this func to grab mutex + users.if_contains(u.first, [&temp, &u](const User &u_val) { temp[u.first] = u_val.Serialize(); }); } + } + if (temp.isNull()) + { + throw std::invalid_argument("Saving Failed\n"); + } + else + { + std::ofstream user_save(users_location); + Json::StreamWriterBuilder builder; + const std::unique_ptr writer(builder.newStreamWriter()); + writer->write(temp, &user_save); + user_save.close(); + } #if CONSERVATIVE_DISK_SAVE #if MULTI_THREADED - save_flag.SetChangesOff(); + save_flag.SetChangesOff(); #else - save_flag = true; -#endif - } + save_flag = true; #endif }