---------------------------------------------- ON GAME END -----------------------------------------------
| 352 | {} |
| 353 | //---------------------------------------------- ON GAME END ----------------------------------------------- |
| 354 | void GameImpl::onGameEnd() |
| 355 | { |
| 356 | //this is called at the end of every match |
| 357 | if ( !this->onStartCalled ) |
| 358 | return; |
| 359 | |
| 360 | if ( autoMenuManager.autoMenuSaveReplay != "" && !this->isReplay() ) |
| 361 | { |
| 362 | // Set replay envvars |
| 363 | SetEnvironmentVariableA("BOTNAME", rn_BWAPIName.c_str()); |
| 364 | SetEnvironmentVariableA("BOTNAME6", rn_BWAPIName.substr(0,6).c_str()); |
| 365 | SetEnvironmentVariableA("BOTRACE", rn_BWAPIRace.c_str()); |
| 366 | SetEnvironmentVariableA("MAP", rn_MapName.c_str()); |
| 367 | SetEnvironmentVariableA("ALLYNAMES", rn_AlliesNames.c_str()); |
| 368 | SetEnvironmentVariableA("ALLYRACES", rn_AlliesRaces.c_str()); |
| 369 | SetEnvironmentVariableA("ENEMYNAMES", rn_EnemiesNames.c_str()); |
| 370 | SetEnvironmentVariableA("ENEMYRACES", rn_EnemiesRaces.c_str()); |
| 371 | SetEnvironmentVariableA("GAMERESULT", rn_GameResult.c_str ()); |
| 372 | |
| 373 | // Expand environment strings to szInterPath |
| 374 | char szTmpPath[MAX_PATH] = { 0 }; |
| 375 | ExpandEnvironmentStringsA(autoMenuManager.autoMenuSaveReplay.c_str(), szTmpPath, MAX_PATH); |
| 376 | |
| 377 | std::string pathStr(szTmpPath); |
| 378 | |
| 379 | // Double any %'s remaining in the string so that strftime executes correctly |
| 380 | { |
| 381 | size_t tmp = std::string::npos; |
| 382 | while (tmp = pathStr.find_last_of('%', tmp - 1), tmp != std::string::npos) |
| 383 | pathStr.insert(tmp, "%"); |
| 384 | } |
| 385 | |
| 386 | // Replace the placeholder $'s with %'s for the strftime call |
| 387 | std::replace(pathStr.begin(), pathStr.end(), '$', '%'); |
| 388 | |
| 389 | // Get time |
| 390 | time_t tmpTime = std::time(nullptr); |
| 391 | tm *timeInfo = std::localtime(&tmpTime); |
| 392 | |
| 393 | // Expand time strings, add a handler for this specific task to ignore errors in the format string |
| 394 | // TODO: Replace with boost time format |
| 395 | _invalid_parameter_handler old = _set_invalid_parameter_handler(&ignore_invalid_parameter); |
| 396 | std::strftime(szTmpPath, sizeof(szTmpPath), pathStr.c_str(), timeInfo); |
| 397 | _set_invalid_parameter_handler(old); |
| 398 | pathStr = szTmpPath; |
| 399 | |
| 400 | // Remove illegal characters |
| 401 | pathStr.erase(std::remove_if(pathStr.begin(), pathStr.end(), |
| 402 | [](char c) { |
| 403 | return iscntrl(reinterpret_cast<unsigned char&>(c)) || c == '?' || c == '*' || |
| 404 | c == '<' || c == '|' || c == '>' || c == '"'; |
| 405 | }), pathStr.end()); |
| 406 | |
| 407 | Util::Path parent_p = Util::Path(pathStr).parent_path(); |
| 408 | Util::create_directories(parent_p); |
| 409 | |
| 410 | // Copy to global desired replay name |
| 411 | gDesiredReplayName = pathStr; |
nothing calls this directly
no test coverage detected