| 476 | } |
| 477 | |
| 478 | bool 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 | { |
no test coverage detected