/* 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 DumpHUD_f(void) { char *filename; char buf[MAX_PATH]; if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0)); return; } filename = COM_SkipPathWritable(Cmd_Argv(1)); strlcpy(buf, filename, sizeof(buf)); COM_ForceExtensionEx (buf, ".cfg", sizeof(buf)); DumpHUD(buf); Com_Printf("HUD variables exported to %s\n",buf); }
// // Makes a path fit in a specified sized string "c:\quake\bla\bla\bla" => "c:\quake...la\bla" // char *COM_FitPath(char *dest, int destination_size, char *src, int size_to_fit) { if (!src) { return dest; } if (size_to_fit > destination_size) { size_to_fit = destination_size; } if (strlen(src) <= size_to_fit) { // Entire path fits in the destination. strlcpy(dest, src, destination_size); } else { #define DOT_SIZE 3 #define MIN_LEFT_SIZE 3 int right_size = 0; int left_size = 0; int temp = 0; char *right_dir = COM_SkipPathWritable(src); // Get the size of the right-most part of the path (filename/directory). right_size = strlen (right_dir); // Try to fit the dir/filename if possible. temp = right_size + DOT_SIZE + MIN_LEFT_SIZE; right_size = (temp > size_to_fit) ? abs(right_size - (temp - size_to_fit)) : right_size; // Let the left have the rest. left_size = size_to_fit - right_size - DOT_SIZE; // Only let the left have 35% of the total size. left_size = min (left_size, Q_rint(0.35 * size_to_fit)); // Get the final right size. right_size = size_to_fit - left_size - DOT_SIZE - 1; // Make sure we don't have negative values, // because then our safety checks won't work. left_size = max (0, left_size); right_size = max (0, right_size); if (left_size < destination_size) { strlcpy (dest, src, destination_size); strlcpy (dest + left_size, "...", destination_size); if (left_size + DOT_SIZE + right_size < destination_size) { strlcpy (dest + left_size + DOT_SIZE, src + strlen(src) - right_size, right_size + 1); } } } return dest; }
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"); }