[util] Save and load cvars to/from plist configs

Other than some backwards compatibility, this completes the
configuration updates for now.
This commit is contained in:
Bill Currie 2021-11-15 22:04:29 +09:00
parent 8cf0d00eda
commit b80c19bd77
3 changed files with 39 additions and 1 deletions

View File

@ -120,6 +120,10 @@ qboolean Cvar_Command (void);
// with the archive flag set to true.
void Cvar_WriteVariables (QFile *f);
struct plitem_s;
void Cvar_SaveConfig (struct plitem_s *config);
void Cvar_LoadConfig (struct plitem_s *config);
// attempts to match a partial variable name for command line completion
// returns NULL if nothing fits
const char *Cvar_CompleteVariable (const char *partial) __attribute__((pure));

View File

@ -45,6 +45,7 @@
#include "QF/cvar.h"
#include "QF/hash.h"
#include "QF/mathlib.h"
#include "QF/plist.h"
#include "QF/qargs.h"
#include "QF/quakefs.h"
#include "QF/sys.h"
@ -330,6 +331,38 @@ Cvar_WriteVariables (QFile *f)
Qprintf (f, "seta %s \"%s\"\n", var->name, var->string);
}
VISIBLE void
Cvar_SaveConfig (plitem_t *config)
{
plitem_t *cvars = PL_NewDictionary (0); //FIXME hashlinks
PL_D_AddObject (config, "cvars", cvars);
for (cvar_t *var = cvar_vars; var; var = var->next) {
if (var->flags & CVAR_ARCHIVE) {
PL_D_AddObject (cvars, var->name, PL_NewString (var->string));
}
}
}
VISIBLE void
Cvar_LoadConfig (plitem_t *config)
{
plitem_t *cvars = PL_ObjectForKey (config, "cvars");
if (!cvars) {
return;
}
for (int i = 0, count = PL_D_NumKeys (cvars); i < count; i++) {
const char *cvar_name = PL_KeyAtIndex (cvars, i);
const char *value = PL_String (PL_ObjectForKey (cvars, cvar_name));
if (value) {
cvar_t *var = Cvar_FindVar (cvar_name);
if (var) {
Cvar_Set (var, value);
}
}
}
}
#define SYS_DEVELOPER(developer) #developer,
static const char *developer_flags[] = {
"dev",

View File

@ -1508,7 +1508,7 @@ Host_WriteConfiguration (void)
if (host_initialized && cl_writecfg->int_val) {
plitem_t *config = PL_NewDictionary (0); //FIXME hashlinks
IN_SaveConfig (config);
//Cvar_WriteVariables (f);
Cvar_SaveConfig (config);
const char *path = va (0, "%s/quakeforge.cfg", qfs_gamedir->dir.def);
QFile *f = QFS_WOpen (path, 0);
@ -1544,6 +1544,7 @@ Host_ReadConfiguration (const char *cfg_name)
}
IN_LoadConfig (config);
Cvar_LoadConfig (config);
PL_Free (config);
return 1;