Added preprocessor gates around curl code

This commit is contained in:
Vladyslav Baranovskyi
2024-10-28 12:12:26 +02:00
parent 994f43ac72
commit b6a1769765

View File

@@ -12,10 +12,16 @@
#include <fstream>
#include <sstream>
#include <curl/curl.h>
#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
namespace OpenVulkano
{
#ifdef HAS_CURL
namespace
{
size_t CurlDownloader(void* contents, size_t size, size_t memBlockCount, void* userData)
@@ -26,6 +32,7 @@ namespace OpenVulkano
return totalSize;
}
}
#endif
bool WebResourceLoader::IsUrl(const std::string& str)
{
@@ -36,12 +43,16 @@ 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)
@@ -55,6 +66,7 @@ namespace OpenVulkano
Array<char> WebResourceLoader::DownloadResource(const std::string& url)
{
std::vector<char> buffer;
#ifdef HAS_CURL
CURL* curl = curl_easy_init();
if (curl)
{
@@ -80,6 +92,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);
}