iw4x-client/src/Utils/Cache.cpp

46 lines
893 B
C++
Raw Normal View History

2016-11-21 04:50:55 -05:00
#include "STDInclude.hpp"
namespace Utils
{
const char* Cache::urls[] =
{
"https://iw4xcachep26muba.onion.to"/*,
"https://iw4xcachejnetuln.onion.to",
"https://iw4xcachedjodc4y.onion.to",
*/
};
std::string Cache::validUrl;
Cache::Cache(std::string path)
{
this->Path = path;
}
std::string Cache::GetUrl()
{
if (Cache::validUrl.empty())
return Cache::urls[0] + this->Path;
else
return Cache::validUrl + this->Path;
}
std::string Cache::GetUrl(std::string url, std::string path)
{
return url + path;
}
std::string Cache::GetFile(int timeout, std::string useragent)
{
for (int i = 0; i < ARRAY_SIZE(Cache::urls); i++)
{
std::string result = Utils::WebIO(useragent, this->GetUrl(Cache::urls[i], this->Path)).setTimeout(timeout)->get();
if (!result.empty())
{
Cache::validUrl = Cache::urls[i];
return result;
}
}
return "";
}
}