| 367 | } |
| 368 | |
| 369 | bool CConfigManager::Save() |
| 370 | { |
| 371 | if(!m_pStorage || !g_Config.m_ClSaveSettings) |
| 372 | return true; |
| 373 | |
| 374 | char aConfigFileTmp[IO_MAX_PATH_LENGTH]; |
| 375 | m_ConfigFile = m_pStorage->OpenFile(IStorage::FormatTmpPath(aConfigFileTmp, sizeof(aConfigFileTmp), CONFIG_FILE), IOFLAG_WRITE, IStorage::TYPE_SAVE); |
| 376 | |
| 377 | if(!m_ConfigFile) |
| 378 | { |
| 379 | log_error("config", "ERROR: opening %s failed", aConfigFileTmp); |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | m_Failed = false; |
| 384 | |
| 385 | char aLineBuf[2048]; |
| 386 | for(const SConfigVariable *pVariable : m_vpAllVariables) |
| 387 | { |
| 388 | if((pVariable->m_Flags & CFGFLAG_SAVE) != 0 && !pVariable->IsDefault()) |
| 389 | { |
| 390 | pVariable->Serialize(aLineBuf, sizeof(aLineBuf)); |
| 391 | WriteLine(aLineBuf); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | for(const auto &Callback : m_vCallbacks) |
| 396 | { |
| 397 | Callback.m_pfnFunc(this, Callback.m_pUserData); |
| 398 | } |
| 399 | |
| 400 | for(const char *pCommand : m_vpUnknownCommands) |
| 401 | { |
| 402 | WriteLine(pCommand); |
| 403 | } |
| 404 | |
| 405 | if(m_Failed) |
| 406 | { |
| 407 | log_error("config", "ERROR: writing to %s failed", aConfigFileTmp); |
| 408 | } |
| 409 | |
| 410 | if(io_sync(m_ConfigFile) != 0) |
| 411 | { |
| 412 | m_Failed = true; |
| 413 | log_error("config", "ERROR: synchronizing %s failed", aConfigFileTmp); |
| 414 | } |
| 415 | |
| 416 | if(io_close(m_ConfigFile) != 0) |
| 417 | { |
| 418 | m_Failed = true; |
| 419 | log_error("config", "ERROR: closing %s failed", aConfigFileTmp); |
| 420 | } |
| 421 | |
| 422 | m_ConfigFile = nullptr; |
| 423 | |
| 424 | if(m_Failed) |
| 425 | { |
| 426 | return false; |