[win-linux] updatesvc: debug cdownloader

This commit is contained in:
SimplestStudio
2025-04-03 13:58:26 +03:00
parent d7940fd7c4
commit 4c117cd6c4
2 changed files with 16 additions and 5 deletions

View File

@ -93,14 +93,18 @@ void CDownloader::queryContentLenght(const string &url)
pimpl->m_lock = true;
pimpl->m_future = std::async(std::launch::async, [=]() {
double fileSize = 0;
curl_off_t fileSize = 0;
CURLcode res = CURLE_FAILED_INIT;
if (CURL *curl = curl_easy_init()) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
res = curl_easy_perform(curl);
if (res == CURLE_OK)
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fileSize);
if (res == CURLE_OK) {
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &fileSize);
if (fileSize < 0) fileSize = 0;
}
curl_easy_cleanup(curl);
}
int error = (res == CURLE_OK) ? 0 :
@ -137,6 +141,7 @@ void CDownloader::start()
if (CURL *curl = curl_easy_init()) {
pimpl->m_prev_percent = -1;
curl_easy_setopt(curl, CURLOPT_URL, pimpl->m_url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);

View File

@ -87,10 +87,16 @@ static int initConnection(const wstring &url, DWORD &dwFileSize, Connection &con
if (!WinHttpReceiveResponse(conn.hRequest, NULL))
return DNL_CONN_ERR;
DWORD dwSize = sizeof(DWORD);
if (!WinHttpQueryHeaders(conn.hRequest, WINHTTP_QUERY_CONTENT_LENGTH | WINHTTP_QUERY_FLAG_NUMBER, NULL, &dwFileSize, &dwSize, WINHTTP_NO_HEADER_INDEX))
DWORD dwStatusCode = 0, dwSize = sizeof(DWORD);
if (!WinHttpQueryHeaders(conn.hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &dwStatusCode, &dwSize, WINHTTP_NO_HEADER_INDEX))
return DNL_CONN_ERR;
if (dwStatusCode >= HTTP_STATUS_BAD_REQUEST)
return DNL_CONN_ERR;
if (!WinHttpQueryHeaders(conn.hRequest, WINHTTP_QUERY_CONTENT_LENGTH | WINHTTP_QUERY_FLAG_NUMBER, NULL, &dwFileSize, &dwSize, WINHTTP_NO_HEADER_INDEX))
dwFileSize = 0;
return DNL_OK;
}