From 761c3f14c5049fe80c0e4d1c807e6a17499881e9 Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 13 May 2024 19:05:15 +0300 Subject: [PATCH] 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" --- main.cpp | 2 +- src/downloader.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index d743af1..e40fbc1 100644 --- a/main.cpp +++ b/main.cpp @@ -226,7 +226,7 @@ int main(int argc, char *argv[]) ("report", bpo::value(&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(&Globals::globalConfig.bUpdateCache)->zero_tokens()->default_value(false), "Update game details cache") ("no-platform-detection", bpo::value(&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(&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(&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(&Globals::globalConfig.sOutputFilename)->default_value(""), "Set filename of file downloaded with --download-file.") ("wishlist", bpo::value(&Globals::globalConfig.bShowWishlist)->zero_tokens()->default_value(false), "Show wishlist") ("cacert", bpo::value(&Globals::globalConfig.curlConf.sCACertPath)->default_value(""), "Path to CA certificate bundle in PEM format") diff --git a/src/downloader.cpp b/src/downloader.cpp index 7f5fedf..248017d 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -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 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;