diff --git a/source/src/command.cpp b/source/src/command.cpp index 4f7bb798..f18c36ba 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -562,6 +562,16 @@ void writecfg() COMMAND(writecfg, ARG_NONE); +bool deletecfg() +{ + if(!delfile("config/saved.cfg")) + { + conoutf("could not delete the file config/saved.cfg"); + return false; + } + return true; +} + void identnames(vector &names, bool builtinonly) { enumerateht(*idents) if(!builtinonly || idents->enumc->data.type != ID_ALIAS) names.add(idents->enumc->key); diff --git a/source/src/main.cpp b/source/src/main.cpp index 8ad483b2..4562b787 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -24,12 +24,15 @@ void cleanup(char *msg) // single program exit point; SDL_Quit(); } +VARF(resetcfg, 0, 0, 1); + void quit() // normal exit { extern void writeinitcfg(); writeinitcfg(); writeservercfg(); - writecfg(); + if(resetcfg) deletecfg(); + else writecfg(); cleanup(NULL); exit(EXIT_SUCCESS); } diff --git a/source/src/protos.h b/source/src/protos.h index 3ec7728f..6c0e8e3d 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -39,6 +39,7 @@ extern void pop(const char *name); extern void alias(const char *name, const char *action); extern const char *getalias(const char *name); extern void writecfg(); +extern bool deletecfg(); extern void identnames(vector &names, bool builtinonly); extern void changescriptcontext(int newcontext); extern void explodelist(const char *s, vector &elems); diff --git a/source/src/tools.cpp b/source/src/tools.cpp index 6a88ee28..59cf8484 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -228,6 +228,11 @@ int listfiles(const char *dir, const char *ext, vector &files) return dirs; } +bool delfile(const char *path) +{ + return !remove(path); +} + ///////////////////////// misc tools /////////////////////// bool cmpb(void *b, int n, enet_uint32 c) diff --git a/source/src/tools.h b/source/src/tools.h index c87c8de8..7cd8cd25 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -501,6 +501,7 @@ extern gzFile opengzfile(const char *filename, const char *mode); extern char *loadfile(const char *fn, int *size, const char *mode = NULL); extern bool listdir(const char *dir, const char *ext, vector &files); extern int listfiles(const char *dir, const char *ext, vector &files); +extern bool delfile(const char *path); extern bool cmpb(void *b, int n, enet_uint32 c); extern bool cmpf(char *fn, enet_uint32 c); extern void endianswap(void *, int, int);