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