mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 03:39:17 +01:00
Add more checks to galaxyAPI::getPathFromDownlinkUrl
This commit is contained in:
parent
b30515bfea
commit
6556dc6a82
@ -547,40 +547,51 @@ std::string galaxyAPI::getPathFromDownlinkUrl(const std::string& downlink_url, c
|
|||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string downlink_url_unescaped = (std::string)curl_easy_unescape(curlhandle, downlink_url.c_str(), downlink_url.size(), NULL);
|
std::string downlink_url_unescaped = (std::string)curl_easy_unescape(curlhandle, downlink_url.c_str(), downlink_url.size(), NULL);
|
||||||
|
size_t filename_start_pos = 0;
|
||||||
|
|
||||||
// GOG has changed the url formatting few times between 2 different formats.
|
// If url ends in "/" then remove it
|
||||||
// Try to get proper file name in both cases.
|
if (downlink_url_unescaped.back() == '/')
|
||||||
size_t filename_end_pos;
|
downlink_url_unescaped.assign(downlink_url_unescaped.begin(), downlink_url_unescaped.end()-1);
|
||||||
if (downlink_url_unescaped.find("?path=") != std::string::npos)
|
|
||||||
|
// Assume that filename starts after last "/" in url
|
||||||
|
if (downlink_url_unescaped.find_last_of("/") != std::string::npos)
|
||||||
|
filename_start_pos = downlink_url_unescaped.find_last_of("/") + 1;
|
||||||
|
|
||||||
|
// Url contains "/gamename/"
|
||||||
|
if (downlink_url_unescaped.find("/" + gamename + "/") != std::string::npos)
|
||||||
|
filename_start_pos = downlink_url_unescaped.find("/" + gamename + "/");
|
||||||
|
|
||||||
|
// Assume that filename ends at the end of url
|
||||||
|
size_t filename_end_pos = downlink_url_unescaped.length();
|
||||||
|
|
||||||
|
// Check to see if url has any query strings
|
||||||
|
if (downlink_url_unescaped.find("?") != std::string::npos)
|
||||||
{
|
{
|
||||||
size_t token_pos = downlink_url_unescaped.find("&token=");
|
// Assume that filename ends at first "?"
|
||||||
size_t access_token_pos = downlink_url_unescaped.find("&access_token=");
|
|
||||||
if ((token_pos != std::string::npos) && (access_token_pos != std::string::npos))
|
|
||||||
{
|
|
||||||
filename_end_pos = std::min(token_pos, access_token_pos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
filename_end_pos = downlink_url_unescaped.find_first_of("&");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
filename_end_pos = downlink_url_unescaped.find_first_of("?");
|
filename_end_pos = downlink_url_unescaped.find_first_of("?");
|
||||||
|
|
||||||
// Downlink doesn't contain "?path=" or "?"
|
// Check for "?path="
|
||||||
// Set end pos to length
|
if (downlink_url_unescaped.find("?path=") != std::string::npos)
|
||||||
if (filename_end_pos == std::string::npos)
|
{
|
||||||
filename_end_pos = downlink_url_unescaped.length();
|
size_t token_pos = downlink_url_unescaped.find("&token=");
|
||||||
|
size_t access_token_pos = downlink_url_unescaped.find("&access_token=");
|
||||||
|
if ((token_pos != std::string::npos) && (access_token_pos != std::string::npos))
|
||||||
|
{
|
||||||
|
filename_end_pos = std::min(token_pos, access_token_pos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (downlink_url_unescaped.find_first_of("&") != std::string::npos)
|
||||||
|
filename_end_pos = downlink_url_unescaped.find_first_of("&");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (downlink_url_unescaped.find("/" + gamename + "/") != std::string::npos)
|
path.assign(downlink_url_unescaped.begin()+filename_start_pos, downlink_url_unescaped.begin()+filename_end_pos);
|
||||||
{
|
|
||||||
path.assign(downlink_url_unescaped.begin()+downlink_url_unescaped.find("/" + gamename + "/"), downlink_url_unescaped.begin()+filename_end_pos);
|
// Make sure that path contains "/gamename/"
|
||||||
}
|
if (path.find("/" + gamename + "/") == std::string::npos)
|
||||||
else
|
|
||||||
{
|
|
||||||
path.assign(downlink_url_unescaped.begin()+downlink_url_unescaped.find_last_of("/")+1, downlink_url_unescaped.begin()+filename_end_pos);
|
|
||||||
path = "/" + gamename + "/" + path;
|
path = "/" + gamename + "/" + path;
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround for filename issue caused by different (currently unknown) url formatting scheme
|
// Workaround for filename issue caused by different (currently unknown) url formatting scheme
|
||||||
// https://github.com/Sude-/lgogdownloader/issues/126
|
// https://github.com/Sude-/lgogdownloader/issues/126
|
||||||
|
Loading…
Reference in New Issue
Block a user