Last active
December 17, 2022 21:39
-
-
Save FlynnOConnell/f4ba947d7ad3f4b8231c1f5bd85c876f to your computer and use it in GitHub Desktop.
Gets workshop maps from the given directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary>Gets workshop maps from the given directory.</summary> | |
/// <param name="workshopPath">Path to the workshop directory to get the maps from</param> | |
/// <param name="extensions">List of map extensions to filter by</param> | |
/// <param name="preferredExtension">Map extension to prefer when multiple files are found</param> | |
/// <returns>The workshop maps from the given directory</returns> | |
std::vector<std::filesystem::path> PremierSuite::getWorkshopMaps(const std::filesystem::path& workshopPath, | |
const std::vector<std::string>& extensions, | |
const std::string& preferredExtension) { | |
if (!exists(workshopPath)) { | |
return std::vector<std::filesystem::path>(); | |
} | |
// Make sure we don't request workshop map names every clock tick. | |
const bool shouldRequestWorkshopMapNames = publishedFileID.empty(); | |
std::vector<std::filesystem::path> files = IterateDirectory(workshopPath, extensions, 0, 1); | |
std::filesystem::path bestPath; | |
std::vector<std::filesystem::path> workshopMaps; | |
for (const std::filesystem::path& file : files) { | |
if (file.parent_path() != bestPath.parent_path()) { | |
if (!bestPath.empty()) { | |
const uint64_t workshopMapId = std::strtoull(bestPath.parent_path().stem().string().c_str(), nullptr, | |
10); | |
if (shouldRequestWorkshopMapNames && subscribedWorkshopMaps.find(workshopMapId) == subscribedWorkshopMaps.end()) { | |
publishedFileID.push_back(workshopMapId); | |
} | |
workshopMaps.push_back(bestPath); | |
} | |
bestPath = file; | |
} | |
else if (bestPath.extension() != preferredExtension && file.extension() == preferredExtension) { | |
bestPath = file; | |
} | |
if (!bestPath.empty()) { | |
const uint64_t workshopMapId = std::strtoull(bestPath.parent_path().stem().string().c_str(), nullptr, 10); | |
if (shouldRequestWorkshopMapNames && subscribedWorkshopMaps.find(workshopMapId) == subscribedWorkshopMaps.end()) { | |
publishedFileID.push_back(workshopMapId); | |
} | |
workshopMaps.push_back(bestPath); | |
} | |
return workshopMaps; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment