Cogs.Core
IO.cpp
1#include "IO.h"
2
3#if !defined( EMSCRIPTEN )
4
5static void backup_backup(const std::string& file, int id, int max)
6{
7 std::string backup = file + ".backup" + std::to_string(id+1);
8 if(id < max && Cogs::IO::exists(backup))
9 backup_backup(file, id+1, max);
10 std::string save_file = file + ".backup" + std::to_string(id);
11 fs::rename(save_file, backup);
12}
13
14void Cogs::IO::backupFile(const std::string &file, int max)
15{
16 if(IO::exists(file)){
17 std::string backup = file + ".backup1";
18 if(IO::exists(backup))
19 backup_backup(file, 1, max);
20 fs::rename(file, backup);
21 }
22}
23
24#endif