Improvements to --download-file option

Allows downloading DLC files by extending file selection.
Files can be selected by using the name of dlc
--download-file "gamename/dlc_gamename/fileid"
This commit is contained in:
Sude 2024-05-13 19:05:15 +03:00
parent 81fdfea8e7
commit 761c3f14c5
2 changed files with 23 additions and 5 deletions

View File

@ -226,7 +226,7 @@ int main(int argc, char *argv[])
("report", bpo::value<std::string>(&Globals::globalConfig.sReportFilePath)->implicit_value("lgogdownloader-report.log"), "Save report of downloaded/repaired files to specified file\nDefault filename: lgogdownloader-report.log")
("update-cache", bpo::value<bool>(&Globals::globalConfig.bUpdateCache)->zero_tokens()->default_value(false), "Update game details cache")
("no-platform-detection", bpo::value<bool>(&bNoPlatformDetection)->zero_tokens()->default_value(false), "Don't try to detect supported platforms from game shelf.\nSkips the initial fast platform detection and detects the supported platforms from game details which is slower but more accurate.\nUseful in case platform identifier is missing for some games in the game shelf.\nUsing --platform with --list doesn't work with this option.")
("download-file", bpo::value<std::string>(&Globals::globalConfig.sFileIdString)->default_value(""), "Download files using fileid\n\nFormat:\n\"gamename/fileid\"\nor: \"gogdownloader://gamename/fileid\"\n\nMultiple files:\n\"gamename1/fileid1,gamename2/fileid2\"\nor: \"gogdownloader://gamename1/fileid1,gamename2/fileid2\"\n\nThis option ignores all subdir options. The files are downloaded to directory specified with --directory option.")
("download-file", bpo::value<std::string>(&Globals::globalConfig.sFileIdString)->default_value(""), "Download files using fileid\n\nFormat:\n\"gamename/fileid\"\n\"gamename/dlc_gamename/fileid\"\n\"gogdownloader://gamename/fileid\"\n\"gogdownloader://gamename/dlc_name/fileid\"\n\nMultiple files:\n\"gamename1/fileid1,gamename2/fileid2,gamename2/dlcname/fileid1\"\n\nThis option ignores all subdir options. The files are downloaded to directory specified with --directory option.")
("output-file,o", bpo::value<std::string>(&Globals::globalConfig.sOutputFilename)->default_value(""), "Set filename of file downloaded with --download-file.")
("wishlist", bpo::value<bool>(&Globals::globalConfig.bShowWishlist)->zero_tokens()->default_value(false), "Show wishlist")
("cacert", bpo::value<std::string>(&Globals::globalConfig.curlConf.sCACertPath)->default_value(""), "Path to CA certificate bundle in PEM format")

View File

@ -2405,12 +2405,24 @@ int Downloader::downloadFileWithId(const std::string& fileid_string, const std::
}
else
{
std::string gamename, fileid, url;
gamename.assign(fileid_string.begin(), fileid_string.begin()+pos);
fileid.assign(fileid_string.begin()+pos+1, fileid_string.end());
bool bIsDLC = false;
std::string gamename, dlc_gamename, fileid, url;
std::vector<std::string> fileid_vector = Util::tokenize(fileid_string, "/");
if (fileid_vector.size() == 3)
bIsDLC = true;
gamename = fileid_vector[0];
if (bIsDLC)
{
dlc_gamename = fileid_vector[1];
fileid = fileid_vector[2];
}
else
fileid = fileid_vector[1];
std::string product_id;
bool bSelectOK = this->galaxySelectProductIdHelper(gamename, product_id);
std::string gamename_select = "^" + gamename + "$";
bool bSelectOK = this->galaxySelectProductIdHelper(gamename_select, product_id);
if (!bSelectOK || product_id.empty())
{
@ -2432,6 +2444,12 @@ int Downloader::downloadFileWithId(const std::string& fileid_string, const std::
bool bFoundMatchingFile = false;
for (auto f : vFiles)
{
if (bIsDLC)
{
if (f.gamename != dlc_gamename)
continue;
}
if (f.id == fileid)
{
gf = f;