/* example how it works === ./ezquake -game testmod -config testcfg homedir/testmod/testcfg.cfg (fullname) homedir/testcfg.cfg (fullname_moddefault) quakedir/testmod/configs/testcfg.cfg quakedir/ezquake/configs/testcfg.cfg built-in ezquake config */ void LoadConfig_f(void) { FILE *f = NULL; char filename[MAX_PATH] = {0}, fullname[MAX_PATH] = {0}, fullname_moddefault[MAX_PATH] = {0}, *arg1; int use_home; arg1 = COM_SkipPathWritable(Cmd_Argv(1)); snprintf(filename, sizeof(filename) - 4, "%s", arg1[0] ? arg1 : MAIN_CONFIG_FILENAME); // use config.cfg if no params was specified COM_ForceExtensionEx (filename, ".cfg", sizeof (filename)); use_home = cfg_use_home.integer || !host_everything_loaded; // home snprintf(fullname, sizeof(fullname), "%s/%s%s", com_homedir, (strcmp(com_gamedirfile, "qw") == 0) ? "" : va("%s/", com_gamedirfile), filename); snprintf(fullname_moddefault, sizeof(fullname_moddefault), "%s/%s", com_homedir, filename); if(use_home && !((f = fopen(fullname, "rb")) && cfg_use_gamedir.integer) && !(f = fopen(fullname_moddefault, "rb"))) { use_home = false; } // basedir snprintf(fullname, sizeof(fullname), "%s/%s/configs/%s", com_basedir, (strcmp(com_gamedirfile, "qw") == 0) ? "ezquake" : com_gamedirfile, filename); snprintf(fullname_moddefault, sizeof(fullname_moddefault), "%s/ezquake/configs/%s", com_basedir, filename); if(!use_home && !((f = fopen(fullname, "rb")) && cfg_use_gamedir.integer) && !(f = fopen(fullname_moddefault, "rb"))) { Com_Printf("Couldn't load %s %s\n", filename, (cfg_use_gamedir.integer) ? "(using gamedir search)": "(not using gamedir search)"); return; } con_suppress = true; ResetConfigs(false, true); con_suppress = false; if(use_home) Com_Printf("Loading %s%s (Using Home Directory) ...\n", (strcmp(com_gamedirfile, "qw") == 0) ? "" : va("%s/",com_gamedirfile), filename); else Com_Printf("Loading %s/configs/%s ...\n", (strcmp(com_gamedirfile, "qw") == 0) ? "ezquake" : com_gamedirfile, filename); Cbuf_AddText ("cl_warncmd 0\n"); LoadCfg(f); fclose(f); /* johnnycz: This should be called with TP_ExecTrigger("f_cfgload"); but definition of f_cfgload alias is stored in config which is waiting to be executed in command queue so nothing would happen. We have to add f_cfgload as a standard command to the queue. Since warnings are off this is OK but regarding to other f_triggers non-standard. */ Cbuf_AddText ("f_cfgload\n"); Cbuf_AddText ("cl_warncmd 1\n"); }
void ResetConfigs_f(void) { int argc = Cmd_Argc(); qbool read_legacy_configs = argc == 2 && !strcmp(Cmd_Argv(1), "full"); if (argc != 1 && !read_legacy_configs) { Com_Printf("Usage: %s [full]\n", Cmd_Argv(0)); return; } Com_Printf("Resetting configuration to default state...\n"); ResetConfigs(true, read_legacy_configs); }
void LoadConfig_f(void) { FILE *f; char filename[MAX_PATH] = {0}, fullname[MAX_PATH] = {0}, *arg1; int use_home; /* load config.cfg by default if no params if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0)); return; } */ arg1 = COM_SkipPathWritable(Cmd_Argv(1)); snprintf(filename, sizeof(filename) - 4, "%s", arg1[0] ? arg1 : "config.cfg"); // use config.cfg if no params was specified COM_ForceExtensionEx (filename, ".cfg", sizeof (filename)); use_home = cfg_use_home.integer; if (use_home) // use home dir for cfg snprintf(fullname, sizeof(fullname), "%s/%s", com_homedir, filename); else // use ezquake dir snprintf(fullname, sizeof(fullname), "%s/ezquake/configs/%s", com_basedir, filename); if (!(f = fopen(fullname, "r"))) { use_home = !use_home; // cfg was't found, invert setting and repeat search, mostly this need only at load time if (use_home) // use home dir for cfg snprintf(fullname, sizeof(fullname), "%s/%s", com_homedir, filename); else // use ezquake dir snprintf(fullname, sizeof(fullname), "%s/ezquake/configs/%s", com_basedir, filename); if (!(f = fopen(fullname, "r"))) { Com_Printf("Couldn't load config %s\n", filename); return; } } fclose(f); con_suppress = true; ResetConfigs(false, true); con_suppress = false; Com_Printf("Loading config %s ...\n", filename); Cbuf_AddText ("cl_warncmd 0\n"); if (use_home) LoadHomeCfg(filename); // well, we can't use exec here, because exec does't support full path by design else Cbuf_AddText(va("exec configs/%s\n", filename)); /* johnnycz: This should be called with TP_ExecTrigger("f_cfgload"); but definition of f_cfgload alias is stored in config which is waiting to be executed in command queue so nothing would happen. We have to add f_cfgload as a standard command to the queue. Since warnings are off this is OK but regarding to other f_triggers non-standard. */ Cbuf_AddText ("f_cfgload\n"); Cbuf_AddText ("cl_warncmd 1\n"); }