[Cache] Removed Constructor
- removed Constructor - changed all functions to static [ci skip]
This commit is contained in:
parent
d17f287bf2
commit
ddce60ee00
@ -492,14 +492,14 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Dvar::Register<bool>("isDlcInstalled_All", false, Game::DVAR_FLAG_USERCREATED | Game::DVAR_FLAG_WRITEPROTECTED, "");
|
Dvar::Register<bool>("isDlcInstalled_All", false, Game::DVAR_FLAG_USERCREATED | Game::DVAR_FLAG_WRITEPROTECTED, "");
|
||||||
|
|
||||||
Maps::AddDlc({ 1, Utils::Cache("/dlc/IW4.DLC.1.Stimulus.Package.zip").GetUrl(), { "mp_complex", "mp_compact", "mp_storm", "mp_overgrown", "mp_crash" } });
|
Maps::AddDlc({ 1, Utils::Cache::GetUrl("/dlc/IW4.DLC.1.Stimulus.Package.zip"), { "mp_complex", "mp_compact", "mp_storm", "mp_overgrown", "mp_crash" } });
|
||||||
Maps::AddDlc({ 2, Utils::Cache("/dlc/IW4.DLC.2.Resurgence.Pack.zip").GetUrl(), { "mp_abandon", "mp_vacant", "mp_trailerpark", "mp_strike", "mp_fuel2" } });
|
Maps::AddDlc({ 2, Utils::Cache::GetUrl("/dlc/IW4.DLC.2.Resurgence.Pack.zip"), { "mp_abandon", "mp_vacant", "mp_trailerpark", "mp_strike", "mp_fuel2" } });
|
||||||
Maps::AddDlc({ 3, Utils::Cache("/dlc/IW4.DLC.3.Nuketown.zip").GetUrl(), { "mp_nuked" } });
|
Maps::AddDlc({ 3, Utils::Cache::GetUrl("/dlc/IW4.DLC.3.Nuketown.zip"), { "mp_nuked" } });
|
||||||
Maps::AddDlc({ 4, Utils::Cache("/dlc/IW4.DLC.4.Classics.1.zip").GetUrl(), { "mp_cross_fire", "mp_cargoship", "mp_bloc" } });
|
Maps::AddDlc({ 4, Utils::Cache::GetUrl("/dlc/IW4.DLC.4.Classics.1.zip"), { "mp_cross_fire", "mp_cargoship", "mp_bloc" } });
|
||||||
Maps::AddDlc({ 5, Utils::Cache("/dlc/IW4.DLC.5.Classics.2.zip").GetUrl(), { "mp_killhouse", "mp_bog_sh" } });
|
Maps::AddDlc({ 5, Utils::Cache::GetUrl("/dlc/IW4.DLC.5.Classics.2.zip"), { "mp_killhouse", "mp_bog_sh" } });
|
||||||
Maps::AddDlc({ 6, Utils::Cache("/dlc/IW4.DLC.6.Cargoship.Winter.zip").GetUrl(), { "mp_cargoship_sh" } });
|
Maps::AddDlc({ 6, Utils::Cache::GetUrl("/dlc/IW4.DLC.6.Cargoship.Winter.zip"), { "mp_cargoship_sh" } });
|
||||||
Maps::AddDlc({ 7, Utils::Cache("/dlc/IW4.DLC.7.Resurrection.Pack.zip").GetUrl(), { "mp_shipment_long", "mp_rust_long", "mp_firingrange" } });
|
Maps::AddDlc({ 7, Utils::Cache::GetUrl("/dlc/IW4.DLC.7.Resurrection.Pack.zip"), { "mp_shipment_long", "mp_rust_long", "mp_firingrange" } });
|
||||||
Maps::AddDlc({ 8, ""/*Utils::Cache("/dlc/").GetUrl()*/,{ /*"mp_bloc_sh", "mp_crash_tropical", "mp_estate_tropical", "mp_fav_tropical", "mp_storm_spring"*/ } });
|
Maps::AddDlc({ 8, ""/*Utils::Cache::GetUrl("/dlc/")*/,{ /*"mp_bloc_sh", "mp_crash_tropical", "mp_estate_tropical", "mp_fav_tropical", "mp_storm_spring"*/ } });
|
||||||
|
|
||||||
Maps::UpdateDlcStatus();
|
Maps::UpdateDlcStatus();
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ namespace Components
|
|||||||
|
|
||||||
void News::CheckForUpdate()
|
void News::CheckForUpdate()
|
||||||
{
|
{
|
||||||
std::string caches = Utils::Cache("/iw4/caches.xml").GetFile();
|
std::string caches = Utils::Cache::GetFile("/iw4/caches.xml");
|
||||||
|
|
||||||
if (!caches.empty())
|
if (!caches.empty())
|
||||||
{
|
{
|
||||||
@ -134,7 +134,7 @@ namespace Components
|
|||||||
|
|
||||||
std::thread([] ()
|
std::thread([] ()
|
||||||
{
|
{
|
||||||
std::string data = Utils::Cache("/iw4/updater.exe").GetFile();
|
std::string data = Utils::Cache::GetFile("/iw4/updater.exe");
|
||||||
|
|
||||||
if (data.empty())
|
if (data.empty())
|
||||||
{
|
{
|
||||||
@ -156,9 +156,9 @@ namespace Components
|
|||||||
News::Terminate = false;
|
News::Terminate = false;
|
||||||
News::Thread = std::thread([] ()
|
News::Thread = std::thread([] ()
|
||||||
{
|
{
|
||||||
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::Cache("/iw4/changelog.txt").GetFile());
|
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::Cache::GetFile("/iw4/changelog.txt"));
|
||||||
|
|
||||||
std::string data = Utils::Cache("/iw4/motd.txt").GetFile();
|
std::string data = Utils::Cache::GetFile("/iw4/motd.txt");
|
||||||
|
|
||||||
if (!data.empty())
|
if (!data.empty())
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@ namespace Components
|
|||||||
|
|
||||||
void Node::LoadNodeRemotePreset()
|
void Node::LoadNodeRemotePreset()
|
||||||
{
|
{
|
||||||
std::string nodes = Utils::Cache("/iw4/nodes.txt").GetFile();
|
std::string nodes = Utils::Cache::GetFile("/iw4/nodes.txt");
|
||||||
if (nodes.empty()) return;
|
if (nodes.empty()) return;
|
||||||
|
|
||||||
auto nodeList = Utils::String::Explode(nodes, '\n');
|
auto nodeList = Utils::String::Explode(nodes, '\n');
|
||||||
|
@ -2,27 +2,24 @@
|
|||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
const char* Cache::urls[] =
|
const char* Cache::Urls[] =
|
||||||
{
|
{
|
||||||
"https://iw4xcachep26muba.onion.to"/*,
|
"https://iw4xcachep26muba.onion.to"/*,
|
||||||
"https://iw4xcachejnetuln.onion.to",
|
"https://iw4xcachejnetuln.onion.to",
|
||||||
"https://iw4xcachedjodc4y.onion.to",
|
"https://iw4xcachedjodc4y.onion.to",
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
std::string Cache::validUrl;
|
std::string Cache::ValidUrl;
|
||||||
std::mutex Cache::CacheMutex;
|
std::mutex Cache::CacheMutex;
|
||||||
|
|
||||||
Cache::Cache(std::string path)
|
std::string Cache::GetUrl(std::string path)
|
||||||
{
|
{
|
||||||
this->Path = path;
|
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
||||||
}
|
|
||||||
|
|
||||||
std::string Cache::GetUrl()
|
if (Cache::ValidUrl.empty())
|
||||||
{
|
return Cache::Urls[0] + path;
|
||||||
if (Cache::validUrl.empty())
|
|
||||||
return Cache::urls[0] + this->Path;
|
|
||||||
else
|
else
|
||||||
return Cache::validUrl + this->Path;
|
return Cache::ValidUrl + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Cache::GetUrl(std::string url, std::string path)
|
std::string Cache::GetUrl(std::string url, std::string path)
|
||||||
@ -30,25 +27,28 @@ namespace Utils
|
|||||||
return url + path;
|
return url + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Cache::GetFile(int timeout, std::string useragent)
|
std::string Cache::GetFile(std::string path, int timeout, std::string useragent)
|
||||||
{
|
{
|
||||||
if (Cache::validUrl.empty())
|
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
||||||
|
|
||||||
|
if (Cache::ValidUrl.empty())
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
for (int i = 0; i < ARRAY_SIZE(Cache::Urls); i++)
|
||||||
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();
|
std::string result = Utils::WebIO(useragent, Cache::GetUrl(Cache::Urls[i], path)).setTimeout(timeout)->get();
|
||||||
|
|
||||||
if (!result.empty())
|
if (!result.empty())
|
||||||
{
|
{
|
||||||
Cache::validUrl = Cache::urls[i];
|
Cache::ValidUrl = Cache::Urls[i];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Utils::WebIO(useragent, this->GetUrl(Cache::validUrl, this->Path)).setTimeout(timeout)->get();
|
return Utils::WebIO(useragent, Cache::GetUrl(Cache::ValidUrl, path)).setTimeout(timeout)->get();
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,13 @@ namespace Utils
|
|||||||
class Cache
|
class Cache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Cache(std::string path);
|
static std::string GetUrl(std::string path);
|
||||||
std::string GetUrl();
|
static std::string GetFile(std::string path, int timeout = 5000, std::string useragent = "IW4x");
|
||||||
std::string GetFile(int timeout = 5000, std::string useragent = "IW4x");
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::mutex CacheMutex;
|
static std::mutex CacheMutex;
|
||||||
static const char* urls[];
|
static const char* Urls[];
|
||||||
static std::string validUrl;
|
static std::string ValidUrl;
|
||||||
std::string Path;
|
static std::string GetUrl(std::string url, std::string path);
|
||||||
std::string GetUrl(std::string url, std::string path);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user