mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Make --download-file option use Galaxy API
This commit is contained in:
parent
04b63d4c76
commit
a884e8c0a3
@ -2451,22 +2451,34 @@ void Downloader::saveChangelog(const std::string& changelog, const std::string&
|
|||||||
|
|
||||||
int Downloader::downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath)
|
int Downloader::downloadFileWithId(const std::string& fileid_string, const std::string& output_filepath)
|
||||||
{
|
{
|
||||||
if (!gogAPI->isLoggedIn())
|
if (gogGalaxy->isTokenExpired())
|
||||||
{
|
{
|
||||||
std::cout << "API not logged in. This feature doesn't work without valid API login." << std::endl;
|
if (!gogGalaxy->refreshLogin())
|
||||||
std::cout << "Try to login with --login-api" << std::endl;
|
{
|
||||||
exit(1);
|
std::cerr << "Galaxy API failed to refresh login" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = 1;
|
DownloadConfig dlConf = Globals::globalConfig.dlConf;
|
||||||
|
dlConf.bInstallers = true;
|
||||||
|
dlConf.bExtras = true;
|
||||||
|
dlConf.bPatches = true;
|
||||||
|
dlConf.bLanguagePacks = true;
|
||||||
|
dlConf.bDLC = true;
|
||||||
|
dlConf.bDuplicateHandler = false; // Disable duplicate handler
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
CURLcode result = CURLE_RECV_ERROR; // assume network error
|
||||||
|
|
||||||
size_t pos = fileid_string.find("/");
|
size_t pos = fileid_string.find("/");
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
{
|
{
|
||||||
std::cout << "Invalid file id " << fileid_string << ": could not find separator \"/\"" << std::endl;
|
std::cerr << "Invalid file id " << fileid_string << ": could not find separator \"/\"" << std::endl;
|
||||||
}
|
}
|
||||||
else if (!output_filepath.empty() && boost::filesystem::is_directory(output_filepath))
|
else if (!output_filepath.empty() && boost::filesystem::is_directory(output_filepath))
|
||||||
{
|
{
|
||||||
std::cout << "Failed to create the file " << output_filepath << ": Is a directory" << std::endl;
|
std::cerr << "Failed to create the file " << output_filepath << ": Is a directory" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2474,34 +2486,96 @@ int Downloader::downloadFileWithId(const std::string& fileid_string, const std::
|
|||||||
gamename.assign(fileid_string.begin(), fileid_string.begin()+pos);
|
gamename.assign(fileid_string.begin(), fileid_string.begin()+pos);
|
||||||
fileid.assign(fileid_string.begin()+pos+1, fileid_string.end());
|
fileid.assign(fileid_string.begin()+pos+1, fileid_string.end());
|
||||||
|
|
||||||
if (fileid.find("installer") != std::string::npos)
|
std::string product_id;
|
||||||
url = gogAPI->getInstallerLink(gamename, fileid);
|
if(this->galaxySelectProductIdHelper(gamename, product_id))
|
||||||
else if (fileid.find("patch") != std::string::npos)
|
{
|
||||||
url = gogAPI->getPatchLink(gamename, fileid);
|
if (product_id.empty())
|
||||||
else if (fileid.find("langpack") != std::string::npos)
|
{
|
||||||
url = gogAPI->getLanguagePackLink(gamename, fileid);
|
std::cerr << "Failed to get numerical product id" << std::endl;
|
||||||
else
|
return 0;
|
||||||
url = gogAPI->getExtraLink(gamename, fileid);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!gogAPI->getError())
|
Json::Value productInfo = gogGalaxy->getProductInfo(product_id);
|
||||||
|
if (productInfo.empty())
|
||||||
{
|
{
|
||||||
std::string filename, filepath;
|
std::cerr << "Failed to get product info" << std::endl;
|
||||||
filename.assign(url.begin()+url.find_last_of("/")+1, url.begin()+url.find_first_of("?"));
|
return 0;
|
||||||
if (output_filepath.empty())
|
}
|
||||||
filepath = Util::makeFilepath(Globals::globalConfig.dirConf.sDirectory, filename, gamename);
|
|
||||||
else
|
gameDetails gd = gogGalaxy->productInfoJsonToGameDetails(productInfo, dlConf);
|
||||||
filepath = output_filepath;
|
|
||||||
std::cout << "Downloading: " << filepath << std::endl;
|
|
||||||
res = this->downloadFile(url, filepath, std::string(), gamename);
|
auto vFiles = gd.getGameFileVector();
|
||||||
std::cout << std::endl;
|
gameFile gf;
|
||||||
|
bool bFoundMatchingFile = false;
|
||||||
|
for (auto f : vFiles)
|
||||||
|
{
|
||||||
|
if (f.id == fileid)
|
||||||
|
{
|
||||||
|
gf = f;
|
||||||
|
bFoundMatchingFile = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bFoundMatchingFile)
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to find file info (product id: " << product_id << " / file id: " << fileid << ")" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value downlinkJson = gogGalaxy->getResponseJson(gf.galaxy_downlink_json_url);
|
||||||
|
|
||||||
|
if (downlinkJson.empty())
|
||||||
|
{
|
||||||
|
std::cerr << "Empty JSON response" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (downlinkJson.isMember("downlink"))
|
||||||
|
{
|
||||||
|
url = downlinkJson["downlink"].asString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << gogAPI->getErrorMessage() << std::endl;
|
std::cerr << "Invalid JSON response" << std::endl;
|
||||||
gogAPI->clearError();
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string xml_url;
|
||||||
|
if (downlinkJson.isMember("checksum"))
|
||||||
|
{
|
||||||
|
if (!downlinkJson["checksum"].empty())
|
||||||
|
xml_url = downlinkJson["checksum"].asString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get XML data
|
||||||
|
std::string xml_data;
|
||||||
|
if (!xml_url.empty())
|
||||||
|
{
|
||||||
|
xml_data = gogGalaxy->getResponse(xml_url);
|
||||||
|
if (xml_data.empty())
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to get XML data" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string filename, filepath;
|
||||||
|
filename.assign(url.begin()+url.find_last_of("/")+1, url.begin()+url.find_first_of("?"));
|
||||||
|
if (output_filepath.empty())
|
||||||
|
filepath = Util::makeFilepath(Globals::globalConfig.dirConf.sDirectory, filename, gamename);
|
||||||
|
else
|
||||||
|
filepath = output_filepath;
|
||||||
|
std::cout << "Downloading: " << filepath << std::endl;
|
||||||
|
result = this->downloadFile(url, filepath, xml_data, gamename);
|
||||||
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result == CURLE_OK)
|
||||||
|
res = 1;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user