mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
⚡ cleaner solution to initial save file generation
This commit is contained in:
parent
bf8ecccbb8
commit
21abb82c76
3 changed files with 18 additions and 6 deletions
|
|
@ -82,6 +82,7 @@ lastly type in
|
||||||
```
|
```
|
||||||
cmake <flags of your choice or none> ..
|
cmake <flags of your choice or none> ..
|
||||||
make -j<threads>
|
make -j<threads>
|
||||||
|
./bank
|
||||||
```
|
```
|
||||||
|
|
||||||
## Certs
|
## Certs
|
||||||
|
|
|
||||||
17
main.cpp
17
main.cpp
|
|
@ -29,7 +29,22 @@ void SaveSig(int s)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
std::ofstream users_save(users_location, std::ios::out | std::ios::binary);
|
||||||
|
if (users_save.is_open())
|
||||||
|
{
|
||||||
|
uint8_t temp[16]{16, 0, 0, 0, 4};
|
||||||
|
users_save.write((char *)temp, 16);
|
||||||
|
users_save.close();
|
||||||
|
std::cout << "User save file generated\nUsage: sudo ./bank <admin account> <saving frequency in minutes>\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "File cannot be created\n";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
{
|
{
|
||||||
std::cerr << "Usage: sudo ./bank <admin account> <saving frequency in minutes>\n";
|
std::cerr << "Usage: sudo ./bank <admin account> <saving frequency in minutes>\n";
|
||||||
|
|
|
||||||
|
|
@ -341,11 +341,7 @@ void Bank::Load()
|
||||||
std::ifstream users_load(users_location, std::ios::out | std::ios::binary);
|
std::ifstream users_load(users_location, std::ios::out | std::ios::binary);
|
||||||
if (!users_load.is_open())
|
if (!users_load.is_open())
|
||||||
{
|
{
|
||||||
std::ofstream users_save(users_location, std::ios::out | std::ios::binary);
|
throw std::invalid_argument("Cannot find save file, to generate a new one run ./bank\n");
|
||||||
uint8_t temp[16]{16, 0, 0, 0, 4};
|
|
||||||
users_save.write((char *)temp, 16);
|
|
||||||
users_save.close();
|
|
||||||
throw std::invalid_argument("Cannot find users.dat, file has been created\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t buffer_size;
|
uint32_t buffer_size;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue