MCPcopy Create free account
hub / github.com/comaps/comaps / GetForceDownloadWorlds

Method GetForceDownloadWorlds

libs/storage/storage.cpp:517–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517Storage::WorldStatus Storage::GetForceDownloadWorlds(std::vector<platform::CountryFile> & res) const
518{
519 CHECK_THREAD_CHECKER(m_threadChecker, ());
520
521 bool hasWorld[] = {false, false};
522 string const worldName[] = {WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME};
523
524 {
525 // Check if Worlds already present.
526 std::vector<platform::LocalCountryFile> localFiles;
527 FindAllLocalMapsAndCleanup(m_currentVersion, m_dataDir, localFiles);
528 for (auto const & f : localFiles)
529 {
530 for (int i = 0; i < 2; ++i)
531 if (f.GetCountryName() == worldName[i])
532 hasWorld[i] = true;
533 }
534
535 if (hasWorld[0] && hasWorld[1])
536 return WorldStatus::READY;
537 }
538
539 Platform & pl = GetPlatform();
540
541 // Parse root data folder (we stored Worlds here in older versions).
542 // Note that m_dataDir maybe empty and we take Platform::WritableDir.
543 std::vector<platform::LocalCountryFile> rootFiles;
544 (void)FindAllLocalMapsInDirectoryAndCleanup(m_dataDir.empty() ? pl.WritableDir() : m_dataDir, 0 /* version */,
545 -1 /* latestVersion */, rootFiles);
546
547 bool anyWorldWasMoved = false;
548 for (auto const & f : rootFiles)
549 {
550 for (int i = 0; i < 2; ++i)
551 {
552 if (f.GetCountryName() != worldName[i])
553 continue;
554
555 if (!hasWorld[i])
556 {
557 try
558 {
559 auto const filePath = f.GetPath(MapFileType::Map);
560 uint32_t const version = version::ReadVersionDate(pl.GetReader(filePath, "f"));
561 ASSERT(version > 0, ());
562
563 auto const dirPath = base::JoinPath(f.GetDirectory(), std::to_string(version));
564 if (pl.MkDirChecked(dirPath) &&
565 base::RenameFileX(filePath, base::JoinPath(dirPath, worldName[i] + DATA_FILE_EXTENSION)))
566 {
567 anyWorldWasMoved = hasWorld[i] = true;
568 break;
569 }
570 else
571 {
572 LOG(LERROR, ("Can't move", filePath, "into", dirPath));
573 return WorldStatus::ERROR_MOVE_FILE;
574 }

Calls 15

ReadVersionDateFunction · 0.85
ASSERTFunction · 0.85
JoinPathFunction · 0.85
to_stringFunction · 0.85
RenameFileXFunction · 0.85
MkDirCheckedMethod · 0.80
GetCountryNameMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected