mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Add option to download files using file id
This commit is contained in:
parent
84c3385e87
commit
d97849818e
@ -65,10 +65,11 @@ class Config
|
||||
std::string sLanguagePackSubdir;
|
||||
std::string sDLCSubdir;
|
||||
std::string sGameSubdir;
|
||||
std::string sLanguagePriority;
|
||||
std::string sPlatformPriority;
|
||||
std::vector<unsigned int> vLanguagePriority;
|
||||
std::vector<unsigned int> vPlatformPriority;
|
||||
std::string sFileIdString;
|
||||
std::string sLanguagePriority;
|
||||
std::string sPlatformPriority;
|
||||
std::vector<unsigned int> vLanguagePriority;
|
||||
std::vector<unsigned int> vPlatformPriority;
|
||||
|
||||
unsigned int iInstallerType;
|
||||
unsigned int iInstallerLanguage;
|
||||
|
@ -67,6 +67,7 @@ class Downloader
|
||||
void checkOrphans();
|
||||
void checkStatus();
|
||||
void updateCache();
|
||||
void downloadFileWithId(const std::string& fileid_string);
|
||||
CURL* curlhandle;
|
||||
Timer timer;
|
||||
Config config;
|
||||
|
3
main.cpp
3
main.cpp
@ -150,6 +150,7 @@ int main(int argc, char *argv[])
|
||||
("no-cover", bpo::value<bool>(&bNoCover)->zero_tokens()->default_value(false), "Don't download cover images. Overrides --cover option.\nUseful for making exceptions when \"cover\" is set to true in config file.")
|
||||
("update-cache", bpo::value<bool>(&config.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>(&config.sFileIdString)->default_value(""), "Download a single file using fileid\nFormat: \"gamename/fileid\"\nThis option ignores all subdir options. The file is downloaded to directory specified with --directory option.")
|
||||
;
|
||||
// Commandline options (config file)
|
||||
options_cli_cfg.add_options()
|
||||
@ -512,6 +513,8 @@ int main(int argc, char *argv[])
|
||||
downloader.updateCache();
|
||||
else if (config.bUpdateCheck) // Update check has priority over download and list
|
||||
downloader.updateCheck();
|
||||
else if (!config.sFileIdString.empty())
|
||||
downloader.downloadFileWithId(config.sFileIdString);
|
||||
else if (config.bRepair) // Repair file
|
||||
downloader.repair();
|
||||
else if (config.bDownload) // Download games
|
||||
|
@ -90,7 +90,7 @@ int Downloader::init()
|
||||
|
||||
// updateCheck() calls getGameList() if needed
|
||||
// getGameList() is not needed when using cache unless we want to list games from account
|
||||
if ( !config.bUpdateCheck && (!config.bUseCache || (config.bUseCache && config.bList)) )
|
||||
if ( !config.bUpdateCheck && (!config.bUseCache || (config.bUseCache && config.bList)) && config.sFileIdString.empty() )
|
||||
this->getGameList();
|
||||
|
||||
if (config.bReport && (config.bDownload || config.bRepair))
|
||||
@ -3076,3 +3076,42 @@ void Downloader::saveSerials(const std::string& serials, const std::string& file
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void Downloader::downloadFileWithId(const std::string& fileid_string)
|
||||
{
|
||||
size_t pos = fileid_string.find("/");
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
std::cout << "Invalid file id " << fileid_string << ": could not find separator \"/\"" << std::endl;
|
||||
}
|
||||
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());
|
||||
|
||||
if (fileid.find("installer") != std::string::npos)
|
||||
url = gogAPI->getInstallerLink(gamename, fileid);
|
||||
else if (fileid.find("patch") != std::string::npos)
|
||||
url = gogAPI->getPatchLink(gamename, fileid);
|
||||
else
|
||||
url = gogAPI->getExtraLink(gamename, fileid);
|
||||
|
||||
if (!gogAPI->getError())
|
||||
{
|
||||
std::string filename, filepath;
|
||||
filename.assign(url.begin()+url.find_last_of("/")+1, url.begin()+url.find_first_of("?"));
|
||||
filepath = Util::makeFilepath(config.sDirectory, filename, gamename);
|
||||
std::cout << "Downloading: " << filepath << std::endl;
|
||||
this->downloadFile(url, filepath, std::string(), gamename);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << gogAPI->getErrorMessage() << std::endl;
|
||||
gogAPI->clearError();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user