CheatMenuSA/src/updater.cpp

68 lines
1.4 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"
#include "menuinfo.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";
char* path = PLUGIN_PATH((char*)"CheatMenu/json/versioninfo.json");
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)
{
SetHelpMessage("Failed to check for updates", false, false, false);
return;
}
2021-06-18 12:49:11 -04:00
2022-01-07 03:18:00 -05:00
CJson verinfo = CJson("versioninfo");
// fetch the version number
if (verinfo.m_Data.empty())
{
latestVer = MENU_VERSION_NUMBER;
}
else
{
latestVer = verinfo.m_Data.items().begin().value()["name"].get<std::string>();
}
if (latestVer > MENU_VERSION_NUMBER)
{
SetHelpMessage("Update found", false, false, false);
curState = States::FOUND;
}
else
{
SetHelpMessage("No update found.", false, false, false);
Updater::curState = States::IDLE;
}
2021-06-18 12:49:11 -04:00
}