mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
🎨 made save results from Save()
This commit is contained in:
parent
f87ec947b6
commit
518c1b1203
3 changed files with 45 additions and 51 deletions
|
|
@ -63,6 +63,6 @@ public:
|
||||||
BankResponse AddUser(const std::string &name, uint32_t init_bal, std::string &&init_pass) noexcept;
|
BankResponse AddUser(const std::string &name, uint32_t init_bal, std::string &&init_pass) noexcept;
|
||||||
BankResponse DelUser(const std::string &name) noexcept;
|
BankResponse DelUser(const std::string &name) noexcept;
|
||||||
|
|
||||||
void Save();
|
const char *Save();
|
||||||
void Load();
|
void Load();
|
||||||
};
|
};
|
||||||
27
main.cpp
27
main.cpp
|
|
@ -21,16 +21,8 @@ static Bank bank;
|
||||||
|
|
||||||
void SaveSig(int s)
|
void SaveSig(int s)
|
||||||
{
|
{
|
||||||
std::cout << "\nSaving on close...\n";
|
std::cout << "\nSaving on close...\n"
|
||||||
if (bank.GetChangeState())
|
<< bank.Save();
|
||||||
{
|
|
||||||
std::cout << " to disk...\n";
|
|
||||||
bank.Save();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << " no changes...\n";
|
|
||||||
}
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,21 +79,12 @@ int main(int argc, char **argv)
|
||||||
const unsigned long saving_freq = std::stoul(std::string(argv[2]));
|
const unsigned long saving_freq = std::stoul(std::string(argv[2]));
|
||||||
if (saving_freq) //if saving frequency is 0 then auto saving is turned off
|
if (saving_freq) //if saving frequency is 0 then auto saving is turned off
|
||||||
{
|
{
|
||||||
std::thread([saving_freq]()
|
std::thread([saving_freq]() {
|
||||||
{
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::minutes(saving_freq));
|
std::this_thread::sleep_for(std::chrono::minutes(saving_freq));
|
||||||
std::cout << "Saving " << std::time(0) << "...\n";
|
std::cout << "Saving " << std::time(0) << "...\n"
|
||||||
if (bank.GetChangeState())
|
<< bank.Save();
|
||||||
{
|
|
||||||
std::cout << " to disk...\n";
|
|
||||||
bank.Save();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << " no changes...\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
|
|
|
||||||
13
src/bank.cpp
13
src/bank.cpp
|
|
@ -263,8 +263,14 @@ BankResponse Bank::DelUser(const std::string &name) noexcept
|
||||||
return {k404NotFound, "\"User not found\""};
|
return {k404NotFound, "\"User not found\""};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Bank::Save()
|
const char *Bank::Save()
|
||||||
{
|
{
|
||||||
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
|
if (GetChangeState())
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
return " to disk...\n";
|
||||||
|
|
||||||
static thread_local Json::Value temp;
|
static thread_local Json::Value temp;
|
||||||
|
|
||||||
//loading info into json temp
|
//loading info into json temp
|
||||||
|
|
@ -294,6 +300,11 @@ void Bank::Save()
|
||||||
#else
|
#else
|
||||||
save_flag = true;
|
save_flag = true;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return " no changes...\n";
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue