Shallow copy of curl repo, WebResourceLoader::IsUrl is now static, returning empty array instead of throwing an exception

This commit is contained in:
Vladyslav Baranovskyi
2024-06-17 12:53:58 +03:00
parent 48607813a5
commit 200ca7237a
3 changed files with 11 additions and 9 deletions

View File

@@ -16,7 +16,7 @@ namespace OpenVulkano
{
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)
{
size_t totalSize = size * memBlockCount;
std::vector<char>* buffer = static_cast<std::vector<char>*>(userData);
@@ -25,6 +25,11 @@ namespace OpenVulkano
}
}
bool WebResourceLoader::IsUrl(const std::string& str)
{
return str.find("http://") == 0 || str.find("https://") == 0 || str.find("ftp://") == 0;
}
WebResourceLoader::WebResourceLoader()
{
m_cacheDirectory = AppFolders::GetAppCacheDir() / "resources";
@@ -50,7 +55,7 @@ namespace OpenVulkano
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curlDownloader);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CurlDownloader);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
#ifdef __APPLE__
@@ -72,11 +77,6 @@ namespace OpenVulkano
return Array<char>(buffer);
}
bool WebResourceLoader::IsUrl(const std::string& str)
{
return str.find("http://") == 0 || str.find("https://") == 0 || str.find("ftp://") == 0;
}
Array<char> WebResourceLoader::GetResource(const std::string& resourceName)
{
if (IsUrl(resourceName))
@@ -85,6 +85,6 @@ namespace OpenVulkano
if (std::filesystem::exists(cacheFilePath)) { return Utils::ReadFile(cacheFilePath.string()); }
else { return DownloadResource(resourceName); }
}
throw std::runtime_error("Resource name is not a valid URL");
return Array<char>();
}
}