Remove cover download support

This commit is contained in:
Sude 2018-05-14 11:12:10 +03:00
parent d0177031e6
commit ef1a344610
4 changed files with 2 additions and 114 deletions

View File

@ -39,7 +39,6 @@ struct DownloadConfig
unsigned int iGalaxyArch;
bool bRemoteXML;
bool bCover;
bool bSaveChangelogs;
bool bSaveSerials;
bool bAutomaticXMLCreation;
@ -278,7 +277,6 @@ class Config
Blacklist blacklist;
Blacklist ignorelist;
Blacklist gamehasdlc;
std::string sCoverList;
std::string sGameHasDLCList;
// Integers

View File

@ -96,7 +96,6 @@ class Downloader
private:
CURLcode downloadFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string());
int repairFile(const std::string& url, const std::string& filepath, const std::string& xml_data = std::string(), const std::string& gamename = std::string());
int downloadCovers(const std::string& gamename, const std::string& directory, const std::string& cover_xml_data);
int getGameDetails();
void getGameList();
uintmax_t getResumePosition();
@ -130,7 +129,6 @@ class Downloader
galaxyAPI *gogGalaxy;
std::vector<gameItem> gameItems;
std::vector<gameDetails> games;
std::string coverXML;
off_t resume_position;
int retries;

View File

@ -34,8 +34,7 @@ int main(int argc, char *argv[])
const unsigned int OPTION_EXTRAS = 1 << 1;
const unsigned int OPTION_PATCHES = 1 << 2;
const unsigned int OPTION_LANGPACKS = 1 << 3;
const unsigned int OPTION_COVERS = 1 << 4;
const unsigned int OPTION_DLCS = 1 << 5;
const unsigned int OPTION_DLCS = 1 << 4;
const std::vector<GlobalConstants::optionsStruct> INCLUDE_OPTIONS =
{
@ -43,7 +42,6 @@ int main(int argc, char *argv[])
{ OPTION_EXTRAS, "e", "Extras", "e|extras" },
{ OPTION_PATCHES, "p", "Patches", "p|patches" },
{ OPTION_LANGPACKS, "l", "Language packs", "l|languagepacks|langpacks" },
{ OPTION_COVERS, "c", "Covers", "c|cover|covers" },
{ OPTION_DLCS, "d", "DLCs", "d|dlc|dlcs" }
};
@ -201,7 +199,6 @@ int main(int argc, char *argv[])
("timeout", bpo::value<long int>(&Globals::globalConfig.curlConf.iTimeout)->default_value(10), "Set timeout for connection\nMaximum time in seconds that connection phase is allowed to take")
("retries", bpo::value<int>(&Globals::globalConfig.iRetries)->default_value(3), "Set maximum number of retries on failed download")
("wait", bpo::value<int>(&Globals::globalConfig.iWait)->default_value(0), "Time to wait between requests (milliseconds)")
("cover-list", bpo::value<std::string>(&Globals::globalConfig.sCoverList)->default_value("https://raw.githubusercontent.com/Sude-/lgogdownloader-lists/master/covers.xml"), "Set URL for cover list")
("subdir-installers", bpo::value<std::string>(&Globals::globalConfig.dirConf.sInstallersSubdir)->default_value(""), ("Set subdirectory for installers" + subdir_help_text).c_str())
("subdir-extras", bpo::value<std::string>(&Globals::globalConfig.dirConf.sExtrasSubdir)->default_value("extras"), ("Set subdirectory for extras" + subdir_help_text).c_str())
("subdir-patches", bpo::value<std::string>(&Globals::globalConfig.dirConf.sPatchesSubdir)->default_value("patches"), ("Set subdirectory for patches" + subdir_help_text).c_str())
@ -213,7 +210,7 @@ int main(int argc, char *argv[])
("save-serials", bpo::value<bool>(&Globals::globalConfig.dlConf.bSaveSerials)->zero_tokens()->default_value(false), "Save serial numbers when downloading")
("ignore-dlc-count", bpo::value<std::string>(&Globals::globalConfig.sIgnoreDLCCountRegex)->implicit_value(".*"), "Set regular expression filter for games to ignore DLC count information\nIgnoring DLC count information helps in situations where the account page doesn't provide accurate information about DLCs")
("include", bpo::value<std::string>(&sIncludeOptions)->default_value("all"), ("Select what to download/list/repair\n" + include_options_text).c_str())
("exclude", bpo::value<std::string>(&sExcludeOptions)->default_value("covers"), ("Select what not to download/list/repair\n" + include_options_text).c_str())
("exclude", bpo::value<std::string>(&sExcludeOptions)->default_value(""), ("Select what not to download/list/repair\n" + include_options_text).c_str())
("automatic-xml-creation", bpo::value<bool>(&Globals::globalConfig.dlConf.bAutomaticXMLCreation)->zero_tokens()->default_value(false), "Automatically create XML data after download has completed")
("save-changelogs", bpo::value<bool>(&Globals::globalConfig.dlConf.bSaveChangelogs)->zero_tokens()->default_value(false), "Save changelogs when downloading")
("threads", bpo::value<unsigned int>(&Globals::globalConfig.iThreads)->default_value(4), "Number of download threads")
@ -493,7 +490,6 @@ int main(int argc, char *argv[])
// Assign values
// TODO: Use config.iInclude in Downloader class directly and get rid of this value assignment
Globals::globalConfig.dlConf.bCover = (Globals::globalConfig.dlConf.iInclude & OPTION_COVERS);
Globals::globalConfig.dlConf.bInstallers = (Globals::globalConfig.dlConf.iInclude & OPTION_INSTALLERS);
Globals::globalConfig.dlConf.bExtras = (Globals::globalConfig.dlConf.iInclude & OPTION_EXTRAS);
Globals::globalConfig.dlConf.bPatches = (Globals::globalConfig.dlConf.iInclude & OPTION_PATCHES);

View File

@ -835,9 +835,6 @@ void Downloader::download()
if (this->games.empty())
this->getGameDetails();
if (Globals::globalConfig.dlConf.bCover && !Globals::globalConfig.bUpdateCheck)
coverXML = this->getResponse(Globals::globalConfig.sCoverList);
for (unsigned int i = 0; i < games.size(); ++i)
{
gameSpecificConfig conf;
@ -856,21 +853,6 @@ void Downloader::download()
this->saveChangelog(games[i].changelog, filepath);
}
// Download covers
if (conf.dlConf.bCover && !Globals::globalConfig.bUpdateCheck)
{
if (!games[i].installers.empty())
{
// Take path from installer path because for some games the base directory for installer/extra path is not "gamename"
boost::filesystem::path filepath = boost::filesystem::absolute(games[i].installers[0].getFilepath(), boost::filesystem::current_path());
// Get base directory from filepath
std::string directory = filepath.parent_path().string();
this->downloadCovers(games[i].gamename, directory, coverXML);
}
}
if (conf.dlConf.bInstallers)
{
for (unsigned int j = 0; j < games[i].installers.size(); ++j)
@ -1501,92 +1483,6 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
return res;
}
// Download cover images
int Downloader::downloadCovers(const std::string& gamename, const std::string& directory, const std::string& cover_xml_data)
{
int res = 0;
tinyxml2::XMLDocument xml;
// Check that directory exists and create subdirectories
boost::filesystem::path path = directory;
if (boost::filesystem::exists(path))
{
if (!boost::filesystem::is_directory(path))
{
std::cout << path << " is not directory" << std::endl;
return res;
}
}
else
{
if (!boost::filesystem::create_directories(path))
{
std::cout << "Failed to create directory: " << path << std::endl;
return res;
}
}
xml.Parse(cover_xml_data.c_str());
tinyxml2::XMLElement *rootNode = xml.RootElement();
if (!rootNode)
{
std::cout << "Not valid XML" << std::endl;
return res;
}
else
{
tinyxml2::XMLNode *gameNode = rootNode->FirstChild();
while (gameNode)
{
tinyxml2::XMLElement *gameElem = gameNode->ToElement();
std::string game_name = gameElem->Attribute("name");
if (game_name == gamename)
{
boost::match_results<std::string::const_iterator> what;
tinyxml2::XMLNode *coverNode = gameNode->FirstChild();
while (coverNode)
{
tinyxml2::XMLElement *coverElem = coverNode->ToElement();
std::string cover_url = coverElem->GetText();
// Get file extension for the image
boost::regex e1(".*(\\.\\w+)$", boost::regex::perl | boost::regex::icase);
boost::regex_search(cover_url, what, e1);
std::string file_extension = what[1];
std::string cover_name = std::string("cover_") + coverElem->Attribute("id") + file_extension;
std::string filepath = directory + "/" + cover_name;
std::cout << "Downloading cover " << filepath << std::endl;
CURLcode result = this->downloadFile(cover_url, filepath);
std::cout << std::endl;
if (result == CURLE_OK)
res = 1;
else
res = 0;
if (result == CURLE_HTTP_RETURNED_ERROR)
{
long int response_code = 0;
result = curl_easy_getinfo(curlhandle, CURLINFO_RESPONSE_CODE, &response_code);
std::cout << "HTTP ERROR: ";
if (result == CURLE_OK)
std::cout << response_code << " (" << cover_url << ")" << std::endl;
else
std::cout << "failed to get error code: " << curl_easy_strerror(result) << " (" << cover_url << ")" << std::endl;
}
coverNode = coverNode->NextSibling();
}
break; // Found cover for game, no need to go through rest of the game nodes
}
gameNode = gameNode->NextSibling();
}
}
return res;
}
CURLcode Downloader::beginDownload()
{
this->TimeAndSize.clear();