| 467 | } |
| 468 | |
| 469 | bool CEditorMap::Load(const char *pFilename, int StorageType, const FErrorHandler &ErrorHandler) |
| 470 | { |
| 471 | std::unique_ptr<IMap> pMap = CreateMap(); |
| 472 | if(!pMap->Load(Editor()->Storage(), pFilename, StorageType)) |
| 473 | { |
| 474 | ErrorHandler("Error: Failed to open map file. See local console for details."); |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | Clean(); |
| 479 | |
| 480 | // load map info |
| 481 | { |
| 482 | int Start, Num; |
| 483 | pMap->GetType(MAPITEMTYPE_INFO, &Start, &Num); |
| 484 | for(int i = Start; i < Start + Num; i++) |
| 485 | { |
| 486 | int ItemSize = pMap->GetItemSize(Start); |
| 487 | int ItemId; |
| 488 | CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)pMap->GetItem(i, nullptr, &ItemId); |
| 489 | if(!pItem || ItemId != 0) |
| 490 | continue; |
| 491 | |
| 492 | const auto &&ReadStringInfo = [&](int Index, char *pBuffer, size_t BufferSize, const char *pErrorContext) { |
| 493 | const char *pStr = pMap->GetDataString(Index); |
| 494 | if(pStr == nullptr) |
| 495 | { |
| 496 | char aBuf[128]; |
| 497 | str_format(aBuf, sizeof(aBuf), "Error: Failed to read %s from map info.", pErrorContext); |
| 498 | ErrorHandler(aBuf); |
| 499 | pBuffer[0] = '\0'; |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | str_copy(pBuffer, pStr, BufferSize); |
| 504 | } |
| 505 | }; |
| 506 | |
| 507 | ReadStringInfo(pItem->m_Author, m_MapInfo.m_aAuthor, sizeof(m_MapInfo.m_aAuthor), "author"); |
| 508 | ReadStringInfo(pItem->m_MapVersion, m_MapInfo.m_aVersion, sizeof(m_MapInfo.m_aVersion), "version"); |
| 509 | ReadStringInfo(pItem->m_Credits, m_MapInfo.m_aCredits, sizeof(m_MapInfo.m_aCredits), "credits"); |
| 510 | ReadStringInfo(pItem->m_License, m_MapInfo.m_aLicense, sizeof(m_MapInfo.m_aLicense), "license"); |
| 511 | |
| 512 | if(pItem->m_Version != 1 || ItemSize < (int)sizeof(CMapItemInfoSettings)) |
| 513 | break; |
| 514 | |
| 515 | if(!(pItem->m_Settings > -1)) |
| 516 | break; |
| 517 | |
| 518 | const unsigned Size = pMap->GetDataSize(pItem->m_Settings); |
| 519 | char *pSettings = (char *)pMap->GetData(pItem->m_Settings); |
| 520 | char *pNext = pSettings; |
| 521 | while(pNext < pSettings + Size) |
| 522 | { |
| 523 | int StrSize = str_length(pNext) + 1; |
| 524 | m_vSettings.emplace_back(pNext); |
| 525 | pNext += StrSize; |
| 526 | } |
no test coverage detected