keep the last five versions of saved.cfg and init.cfg

Renames the existing saved.cfg to saved-old-1.cfg (and an existing -1 to
-2, and so on) before the new saved.cfg is written.

This should help in cases where players mess up their config, because the
config is deleted with a five-game-starts delay.
This commit is contained in:
ac-stef
2014-11-02 23:17:00 +01:00
parent bc3be8136e
commit 6ede08d011
5 changed files with 22 additions and 11 deletions
+16
View File
@@ -787,3 +787,19 @@ char *loadfile(const char *fn, int *size, const char *mode)
return buf;
}
void filerotate(const char *basename, const char *ext, int keepold, const char *oldformat) // rotate old logfiles
{
char fname1[MAXSTRLEN * 2], fname2[MAXSTRLEN] = "";
copystring(fname1, findfile(basename, "w"));
int mid = strlen(fname1);
if(!oldformat) oldformat = "-old-%d";
for(; keepold >= 0; keepold--)
{
formatstring(fname1 + mid)(keepold ? oldformat : "", keepold);
concatformatstring(fname1 + mid, ".%s", ext);
if(fname2[0]) rename(fname1, fname2);
else remove(fname1);
copystring(fname2, fname1);
}
}