Removed ifdefs around curl in WebResourceLoader
This commit is contained in:
@@ -12,16 +12,10 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#if __has_include("curl/curl.h")
|
||||
#include <curl/curl.h>
|
||||
#else
|
||||
#pragma message ("Missing curl.h even though HAS_CURL is set")
|
||||
#undef HAS_CURL
|
||||
#endif
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
#ifdef HAS_CURL
|
||||
namespace
|
||||
{
|
||||
size_t CurlDownloader(void* contents, size_t size, size_t memBlockCount, void* userData)
|
||||
@@ -32,7 +26,6 @@ namespace OpenVulkano
|
||||
return totalSize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool WebResourceLoader::IsUrl(const std::string& str)
|
||||
{
|
||||
@@ -43,16 +36,12 @@ namespace OpenVulkano
|
||||
{
|
||||
m_cacheDirectory = AppFolders::GetAppCacheDir() / "resources";
|
||||
std::filesystem::create_directories(m_cacheDirectory);
|
||||
#ifdef HAS_CURL
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
#endif
|
||||
}
|
||||
|
||||
WebResourceLoader::~WebResourceLoader()
|
||||
{
|
||||
#ifdef HAS_CURL
|
||||
curl_global_cleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::filesystem::path WebResourceLoader::GetCacheFilePath(const std::string& url)
|
||||
@@ -66,7 +55,6 @@ namespace OpenVulkano
|
||||
Array<char> WebResourceLoader::DownloadResource(const std::string& url)
|
||||
{
|
||||
std::vector<char> buffer;
|
||||
#ifdef HAS_CURL
|
||||
CURL* curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
@@ -81,8 +69,9 @@ namespace OpenVulkano
|
||||
CURLcode result = curl_easy_perform(curl);
|
||||
if (result != CURLE_OK)
|
||||
{
|
||||
std::string error = curl_easy_strerror(result);
|
||||
Logger::APP->error("Failed to download resource: '" + url + "' - " + error);
|
||||
curl_easy_cleanup(curl);
|
||||
Logger::APP->error("Failed to download resource: '" + url + "' - " + curl_easy_strerror(result));
|
||||
return Array<char>();
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
@@ -91,7 +80,7 @@ namespace OpenVulkano
|
||||
std::filesystem::path cacheFilePath = GetCacheFilePath(url);
|
||||
std::ofstream file(cacheFilePath, std::ios::binary);
|
||||
file.write(buffer.data(), buffer.size());
|
||||
#endif
|
||||
|
||||
return Array<char>(buffer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user