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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user