Fix getting DLC names

This commit is contained in:
Sude 2023-03-27 22:09:13 +03:00
parent b1d54e70f7
commit 3f6b2315eb
2 changed files with 7 additions and 8 deletions

View File

@ -70,7 +70,7 @@ namespace Util
void filepathReplaceReservedStrings(std::string& str, const std::string& gamename, const unsigned int& platformId = 0, const std::string& dlcname = "");
void setFilePermissions(const boost::filesystem::path& path, const boost::filesystem::perms& permissions);
int getTerminalWidth();
void getDownloaderUrlsFromJSON(const Json::Value &root, std::vector<std::string> &urls);
void getManualUrlsFromJSON(const Json::Value &root, std::vector<std::string> &urls);
std::vector<std::string> getDLCNamesFromJSON(const Json::Value &root);
std::string getHomeDir();
std::string getConfigHome();

View File

@ -480,18 +480,18 @@ int Util::getTerminalWidth()
}
void Util::getDownloaderUrlsFromJSON(const Json::Value &root, std::vector<std::string> &urls)
void Util::getManualUrlsFromJSON(const Json::Value &root, std::vector<std::string> &urls)
{
if(root.size() > 0) {
for(Json::ValueConstIterator it = root.begin() ; it != root.end() ; ++it)
{
if (it.key() == "downloaderUrl")
if (it.key() == "manualUrl")
{
Json::Value url = *it;
urls.push_back(url.asString());
}
else
getDownloaderUrlsFromJSON(*it, urls);
getManualUrlsFromJSON(*it, urls);
}
}
return;
@ -500,15 +500,14 @@ void Util::getDownloaderUrlsFromJSON(const Json::Value &root, std::vector<std::s
std::vector<std::string> Util::getDLCNamesFromJSON(const Json::Value &root)
{
std::vector<std::string> urls, dlcnames;
getDownloaderUrlsFromJSON(root, urls);
getManualUrlsFromJSON(root, urls);
for (unsigned int i = 0; i < urls.size(); ++i)
{
std::string gamename;
if (urls[i].find(GlobalConstants::PROTOCOL_PREFIX) == std::string::npos)
continue;
std::string url_prefix = "/downloads/";
gamename.assign(urls[i].begin()+urls[i].find(GlobalConstants::PROTOCOL_PREFIX)+GlobalConstants::PROTOCOL_PREFIX.length(), urls[i].begin()+urls[i].find_last_of("/"));
gamename.assign(urls[i].begin()+urls[i].find(url_prefix)+url_prefix.length(), urls[i].begin()+urls[i].find_last_of("/"));
bool bDuplicate = false;
for (unsigned int j = 0; j < dlcnames.size(); ++j)
{