diff --git a/doomsday/engine/portable/include/con_config.h b/doomsday/engine/portable/include/con_config.h index c44764b079..6799d86574 100644 --- a/doomsday/engine/portable/include/con_config.h +++ b/doomsday/engine/portable/include/con_config.h @@ -29,8 +29,17 @@ #ifndef LIBDENG_CONSOLE_CONFIG_H #define LIBDENG_CONSOLE_CONFIG_H -boolean Con_ParseCommands(const char* fileName, boolean setdefault); +// Flags for Con_ParseCommands2. +#define CPCF_SET_DEFAULT 0x1 +#define CPCF_ALLOW_SAVE_STATE 0x2 +#define CPCF_ALLOW_SAVE_BINDINGS 0x4 + +boolean Con_ParseCommands(const char* fileName); + +boolean Con_ParseCommands2(const char* fileName, int flags); + void Con_SaveDefaults(void); + boolean Con_WriteState(const char* fileName, const char* bindingsFileName); D_CMD(WriteConsole); diff --git a/doomsday/engine/portable/src/con_config.c b/doomsday/engine/portable/src/con_config.c index 12ae5d6a43..6948d0cf91 100644 --- a/doomsday/engine/portable/src/con_config.c +++ b/doomsday/engine/portable/src/con_config.c @@ -51,6 +51,7 @@ // PUBLIC DATA DEFINITIONS ------------------------------------------------- static filename_t cfgFile; +static int flagsAllow = 0; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -155,6 +156,8 @@ static boolean writeConsoleState(const char* fileName) FILE* file; if(!fileName || !fileName[0]) return false; + VERBOSE(Con_Message("Writing state to \"%s\"...\n", fileName)); + Str_Init(&nativePath); Str_Set(&nativePath, fileName); F_ToNativeSlashes(&nativePath, &nativePath); @@ -191,6 +194,8 @@ static boolean writeBindingsState(const char* fileName) FILE* file; if(!fileName || !fileName[0]) return false; + VERBOSE(Con_Message("Writing bindings to \"%s\"...\n", fileName)); + Str_Init(&nativePath); Str_Set(&nativePath, fileName); F_ToNativeSlashes(&nativePath, &nativePath); @@ -217,10 +222,16 @@ static boolean writeBindingsState(const char* fileName) return false; } -boolean Con_ParseCommands(const char* fileName, boolean setdefault) +boolean Con_ParseCommands(const char* fileName) +{ + return Con_ParseCommands2(fileName, 0); +} + +boolean Con_ParseCommands2(const char* fileName, int flags) { DFile* file; char buff[512]; + boolean setdefault = (flags & CPCF_SET_DEFAULT) != 0; // Is this supposed to be the default? if(setdefault) @@ -253,6 +264,10 @@ boolean Con_ParseCommands(const char* fileName, boolean setdefault) }} F_Delete(file); + + // Update the allowed operations. + flagsAllow |= flags & (CPCF_ALLOW_SAVE_STATE | CPCF_ALLOW_SAVE_BINDINGS); + return true; } @@ -262,18 +277,12 @@ boolean Con_ParseCommands(const char* fileName, boolean setdefault) */ boolean Con_WriteState(const char* fileName, const char* bindingsFileName) { - if(fileName || bindingsFileName) + if(fileName && (flagsAllow & CPCF_ALLOW_SAVE_STATE)) { - VERBOSE( - Con_Printf("Writing"); - if(fileName) - Con_Printf(" state:\"%s\"", fileName); - if(bindingsFileName) - Con_Printf(" bindings:\"%s\"", bindingsFileName); - Con_Printf("...\n") - ) - writeConsoleState(fileName); + } + if(bindingsFileName && (flagsAllow & CPCF_ALLOW_SAVE_BINDINGS)) + { // Bindings go into a separate file. writeBindingsState(bindingsFileName); } diff --git a/doomsday/engine/portable/src/con_main.c b/doomsday/engine/portable/src/con_main.c index a9a0be140d..a1d5ec216a 100644 --- a/doomsday/engine/portable/src/con_main.c +++ b/doomsday/engine/portable/src/con_main.c @@ -2250,7 +2250,7 @@ D_CMD(Parse) for(i = 1; i < argc; ++i) { Con_Printf("Parsing %s.\n", argv[i]); - Con_ParseCommands(argv[i], false); + Con_ParseCommands(argv[i]); } return true; } diff --git a/doomsday/engine/portable/src/dd_main.c b/doomsday/engine/portable/src/dd_main.c index 1bc3958eae..4b29167922 100644 --- a/doomsday/engine/portable/src/dd_main.c +++ b/doomsday/engine/portable/src/dd_main.c @@ -993,7 +993,7 @@ static int DD_ActivateGameWorker(void* paramaters) } Con_Message("Parsing primary config \"%s\"...\n", F_PrettyPath(Str_Text(configFileName))); - Con_ParseCommands(Str_Text(configFileName), true); + Con_ParseCommands2(Str_Text(configFileName), CPCF_SET_DEFAULT | CPCF_ALLOW_SAVE_STATE); if(configFileName == &tmp) Str_Free(&tmp); } @@ -1004,7 +1004,7 @@ static int DD_ActivateGameWorker(void* paramaters) B_BindGameDefaults(); // Read bindings for this game and merge with the working set. - Con_ParseCommands(Str_Text(Game_BindingConfig(theGame)), false); + Con_ParseCommands2(Str_Text(Game_BindingConfig(theGame)), CPCF_ALLOW_SAVE_BINDINGS); } if(p->initiatedBusyMode) @@ -1641,7 +1641,7 @@ boolean DD_Init(void) // Try to load the autoexec file. This is done here to make sure everything is // initialized: the user can do here anything that s/he'd be able to do in-game // provided a game was loaded during startup. - Con_ParseCommands("autoexec.cfg", false); + Con_ParseCommands("autoexec.cfg"); // Read additional config files that should be processed post engine init. if(ArgCheckWith("-parse", 1)) @@ -1655,7 +1655,7 @@ boolean DD_Init(void) if(!arg || arg[0] == '-') break; Con_Message(" Processing \"%s\"...\n", F_PrettyPath(arg)); - Con_ParseCommands(arg, false); + Con_ParseCommands(arg); } VERBOSE( Con_Message(" Done in %.2f seconds.\n", (Sys_GetRealTime() - startTime) / 1000.0f) ); } @@ -1791,7 +1791,7 @@ static int DD_StartupWorker(void* parm) if(!arg || arg[0] == '-') break; Con_Message(" Processing \"%s\"...\n", F_PrettyPath(arg)); - Con_ParseCommands(arg, false); + Con_ParseCommands(arg); } VERBOSE( Con_Message(" Done in %.2f seconds.\n", (Sys_GetRealTime() - startTime) / 1000.0f) ); } @@ -1815,7 +1815,7 @@ static int DD_StartupWorker(void* parm) Con_SetProgress(60); // Execute the startup script (Startup.cfg). - Con_ParseCommands("startup.cfg", false); + Con_ParseCommands("startup.cfg"); // Get the material manager up and running. Con_SetProgress(90);