Use duplicate handler for patches

This commit is contained in:
Sude 2014-03-18 18:43:53 +02:00
parent 8f5ef9a7a6
commit 8435fb2566
2 changed files with 42 additions and 0 deletions

View File

@ -391,6 +391,23 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
{ {
Json::Value patch = patchnode[index]; Json::Value patch = patchnode[index];
// Check for duplicate patches in different languages and add languageId of duplicate patch to the original patch
if (useDuplicateHandler)
{
bool bDuplicate = false;
for (unsigned int j = 0; j < game.patches.size(); ++j)
{
if (game.patches[j].path == patch["link"].asString())
{
game.patches[j].language |= GlobalConstants::LANGUAGES[i].languageId; // Add language code to patch
bDuplicate = true;
break;
}
}
if (bDuplicate)
continue;
}
game.patches.push_back( game.patches.push_back(
gameFile( false, /* patches don't have "updated" flag */ gameFile( false, /* patches don't have "updated" flag */
patch["id"].isInt() ? std::to_string(patch["id"].asInt()) : patch["id"].asString(), patch["id"].isInt() ? std::to_string(patch["id"].asInt()) : patch["id"].asString(),
@ -404,6 +421,23 @@ gameDetails API::getGameDetails(const std::string& game_name, const unsigned int
} }
else // Patch is a single file else // Patch is a single file
{ {
// Check for duplicate patches in different languages and add languageId of duplicate patch to the original patch
if (useDuplicateHandler)
{
bool bDuplicate = false;
for (unsigned int j = 0; j < game.patches.size(); ++j)
{
if (game.patches[j].path == patchnode["link"].asString())
{
game.patches[j].language |= GlobalConstants::LANGUAGES[i].languageId; // Add language code to patch
bDuplicate = true;
break;
}
}
if (bDuplicate)
continue;
}
game.patches.push_back( game.patches.push_back(
gameFile( false, /* patches don't have "updated" flag */ gameFile( false, /* patches don't have "updated" flag */
patchnode["id"].isInt() ? std::to_string(patchnode["id"].asInt()) : patchnode["id"].asString(), patchnode["id"].isInt() ? std::to_string(patchnode["id"].asInt()) : patchnode["id"].asString(),

View File

@ -312,10 +312,18 @@ void Downloader::listGames()
std::cout << "patches: " << std::endl; std::cout << "patches: " << std::endl;
for (unsigned int j = 0; j < games[i].patches.size(); ++j) for (unsigned int j = 0; j < games[i].patches.size(); ++j)
{ {
std::string languages;
for (unsigned int k = 0; k < GlobalConstants::LANGUAGES.size(); k++) // Check which languages the installer supports
{
if (games[i].installers[j].language & GlobalConstants::LANGUAGES[k].languageId)
languages += (languages.empty() ? "" : ", ")+GlobalConstants::LANGUAGES[k].languageString;
}
std::cout << "\tid: " << games[i].patches[j].id << std::endl std::cout << "\tid: " << games[i].patches[j].id << std::endl
<< "\tname: " << games[i].patches[j].name << std::endl << "\tname: " << games[i].patches[j].name << std::endl
<< "\tpath: " << games[i].patches[j].path << std::endl << "\tpath: " << games[i].patches[j].path << std::endl
<< "\tsize: " << games[i].patches[j].size << std::endl << "\tsize: " << games[i].patches[j].size << std::endl
<< "\tlanguage: " << languages << std::endl
<< std::endl; << std::endl;
} }
} }