21 lines
582 B
C++
21 lines
582 B
C++
#include "download.h"
|
|
#include <curl/curl.h>
|
|
#include <stdio.h>
|
|
|
|
bool download_file(const char *url, const char *dest) {
|
|
CURL *curl = curl_easy_init();
|
|
if (curl) {
|
|
FILE *fp = fopen(dest, "wb");
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, nullptr);
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
|
auto res = curl_easy_perform(curl);
|
|
curl_easy_cleanup(curl);
|
|
fclose(fp);
|
|
if (res == CURLE_OK) {
|
|
return true;
|
|
}
|
|
remove(dest);
|
|
}
|
|
return false;
|
|
} |