CheatMenuSA/src/updater.cpp

76 lines
1.6 KiB
C++
Raw Normal View History

2021-10-24 18:08:00 -04:00
#include "pch.h"
2021-10-25 10:03:27 -04:00
#include "updater.h"
2021-03-10 16:10:59 -05:00
2022-01-04 17:33:07 -05:00
bool Updater::IsUpdateAvailable()
2021-03-10 16:10:59 -05:00
{
2022-01-07 03:18:00 -05:00
return Updater::curState == States::FOUND;
2022-01-04 17:33:07 -05:00
}
void Updater::ResetUpdaterState()
{
2022-01-07 03:18:00 -05:00
Updater::curState = States::IDLE;
2022-01-04 17:33:07 -05:00
}
std::string Updater::GetUpdateVersion()
{
2022-01-07 03:18:00 -05:00
return Updater::latestVer;
2022-01-04 17:33:07 -05:00
}
void Updater::CheckUpdate()
{
2022-01-07 03:18:00 -05:00
if (Updater::curState == States::IDLE)
{
Updater::curState = States::CHECKING;
}
2022-01-04 17:33:07 -05:00
}
void Updater::Process()
{
2022-01-07 03:18:00 -05:00
if (Updater::curState != States::CHECKING)
{
return;
}
2021-06-18 12:49:11 -04:00
2022-01-07 03:18:00 -05:00
const char* link = "https://api.github.com/repos/user-grinch/Cheat-Menu/tags";
2022-06-16 14:44:33 -04:00
char* path = PLUGIN_PATH((char*)FILE_NAME "/data/versioninfo.json");
2022-01-07 03:18:00 -05:00
HRESULT res = URLDownloadToFile(NULL, link, path, 0, NULL);
2021-06-18 12:49:11 -04:00
2022-01-07 03:18:00 -05:00
if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE)
{
2022-03-18 03:23:43 -04:00
SetHelpMessage(TEXT("Updater.Failed"));
2022-01-07 03:18:00 -05:00
return;
}
2021-06-18 12:49:11 -04:00
// Extract the version number
FILE *pFile= fopen(path, "r");
if (pFile != NULL)
2022-01-07 03:18:00 -05:00
{
char buf[64];
float version = 0.0f;
while (fgets(buf, 64, pFile) != NULL)
{
sscanf(buf, "[{\"name\": \"%f\",", &version);
if (version != 0.0f)
{
std::stringstream ss;
ss << std::fixed << std::setprecision(2) << version;
latestVer = ss.str();
break;
}
}
fclose(pFile);
2022-01-07 03:18:00 -05:00
}
remove(path);
2022-01-07 03:18:00 -05:00
if (latestVer > MENU_VERSION_NUMBER)
{
2022-03-18 03:23:43 -04:00
SetHelpMessage(TEXT("Updater.Found"));
2022-01-07 03:18:00 -05:00
curState = States::FOUND;
}
else
{
2022-03-18 03:23:43 -04:00
SetHelpMessage(TEXT("Updater.NotFound"));
2022-01-07 03:18:00 -05:00
Updater::curState = States::IDLE;
}
2021-06-18 12:49:11 -04:00
}