mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
⏪ made save function absolute
This commit is contained in:
parent
94fce9cd1f
commit
597a710e2b
1 changed files with 22 additions and 28 deletions
50
src/bank.cpp
50
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<std::shared_mutex> lock{save_lock};
|
||||
for (const auto &u : users)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> 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<Json::StreamWriter> 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<Json::StreamWriter> 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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue