MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / SM_GenerateConfigFile

Function SM_GenerateConfigFile

core/CoreConfig.cpp:478–597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478bool SM_GenerateConfigFile(
479 IPlugin *pl,
480 const char *file,
481 List<const ConVar *> &convars,
482 bool needs_regeneration = false,
483 ke::HashMap<std::string, std::string, StringPolicy> *existing_cvars = NULL)
484{
485 FILE *fp = NULL;
486 char tmp_file[PLATFORM_MAX_PATH];
487 if (!needs_regeneration)
488 {
489 fp = fopen(file, "wt");
490 if (!fp)
491 {
492 logger->LogError("Failed to auto generate config for %s, make sure the directory has write permission.", pl->GetFilename());
493 return false;
494 }
495 }
496 else
497 {
498 /* Create a .tmp file with the new contents of the new config file and then override it to the existing file */
499 ke::path::Format(tmp_file, sizeof(tmp_file), "%s.tmp", file);
500 fp = fopen(tmp_file, "wt");
501 if (!fp)
502 {
503 logger->LogError("Failed to create temp config file for %s, make sure the directory has write permission.", pl->GetFilename());
504 return false;
505 }
506 }
507
508 fprintf(fp, "// This file was auto-generated by SourceMod (v%s)\n", SOURCEMOD_VERSION);
509 fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename());
510 fprintf(fp, "\n\n");
511
512 float x;
513 for (List<const ConVar *>::iterator iter = convars.begin(); iter != convars.end(); iter++)
514 {
515 const ConVar *cvar = (*iter);
516#if SOURCE_ENGINE >= SE_ORANGEBOX
517 if (cvar->IsFlagSet(FCVAR_DONTRECORD))
518#else
519 if (cvar->IsBitSet(FCVAR_DONTRECORD))
520#endif
521 {
522 continue;
523 }
524
525 char descr[255];
526 char *dptr = descr;
527
528 /* Print comments until there is no more */
529 ke::SafeStrcpy(descr, sizeof(descr), cvar->GetHelpText());
530 while (*dptr != '\0')
531 {
532 /* Find the next line */
533 char *next_ptr = dptr;
534 while (*next_ptr != '\0')
535 {

Callers 1

SM_ExecuteConfigFunction · 0.85

Calls 7

LogErrorMethod · 0.45
GetFilenameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
GetNameMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected