FileDownloader::Download& FileDownloader::DownloadFile(std::string url) { Download* download = new FileDownloader::Download(); download->container = this; download->url = url; activeDownloads.push_back(download); MemoryStruct mem; mem.memory = 0; mem.size = 0; CURL* curl = (CURL*)this->curl; curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &mem); CURLcode res = curl_easy_perform(curl); DownloadedFile downloadedFile; downloadedFile.url = download->url; downloadedFile.data = mem.memory; downloadedFile.size = (int)mem.size; download->Completed(downloadedFile); download->container->activeDownloads.erase(std::find(download->container->activeDownloads.begin(), download->container->activeDownloads.end(), download)); delete download; DownloadComplete(downloadedFile); return *download; }