Finished update handler

This commit is contained in:
Grinch_ 2021-03-11 10:55:23 +06:00
parent 54e9d8e9dd
commit 8a1f984d5c
4 changed files with 59 additions and 8 deletions

View File

@ -21,6 +21,33 @@ void CheatMenu::DrawWindow()
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(250, 350));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200));
if (Updater::state == UPDATER_UPDATE_FOUND)
{
ImGui::Button("New version is available",Ui::GetSize());
if (ImGui::Button("Changelog",Ui::GetSize(3)))
ShellExecute(NULL, "open",
std::string("https://github.com/user-grinch/Cheat-Menu/releases/tag/" +
Updater::latest_version).c_str(), NULL, NULL, SW_SHOWNORMAL);
ImGui::SameLine();
if (ImGui::Button("Download",Ui::GetSize(3)))
Updater::state = UPDATER_DOWNLOADING;
ImGui::SameLine();
if (ImGui::Button("Hide",Ui::GetSize(3)))
Updater::state = UPDATER_IDLE;
}
if (Updater::state == UPDATER_DOWNLOADING)
ImGui::Button("Downloading update...",Ui::GetSize());
if (Updater::state == UPDATER_DOWNLOADED)
{
if (ImGui::Button("Update downloaded. Click to install.",Ui::GetSize()))
Updater::state = UPDATER_IDLE;
}
Ui::DrawHeaders(header);
Globals::menu_size = ImGui::GetWindowSize();
@ -197,10 +224,10 @@ void MenuThread(void* param)
break;
if (Updater::state == UPDATER_CHECKING)
{
Updater::CheckForUpdates();
Updater::state = UPDATER_IDLE;
}
if (Updater::state == UPDATER_DOWNLOADING)
Updater::DownloadUpdate();
}
delete menu;

View File

@ -1,6 +1,6 @@
#pragma once
#define MENU_NAME "Cheat Menu"
#define MENU_VERSION_NUMBER "2.3"
#define MENU_VERSION_NUMBER "2.4"
#define MENU_VERSION MENU_VERSION_NUMBER"-beta"
#define BUILD_NUMBER "20210308"
#define BUILD_NUMBER "20210311"
#define MENU_TITLE MENU_NAME " v" MENU_VERSION "(" BUILD_NUMBER ")"

View File

@ -5,7 +5,7 @@
void Updater::CheckForUpdates()
{
LPCSTR link = "https://api.github.com/repos/user-grinch/Cheat-Menu/tags";
LPCSTR path = PLUGIN_PATH((char*)"CheatMenu\\json\\versioninfo.json");
LPCSTR path = PLUGIN_PATH((char*)"CheatMenu/json/versioninfo.json");
HRESULT res = URLDownloadToFile(NULL, link, path, 0, NULL);
if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE)
@ -16,10 +16,32 @@ void Updater::CheckForUpdates()
CJson verinfo = CJson("versioninfo");
// fetch the version number
std::string latest_version = verinfo.data.items().begin().value()["name"].get<std::string>();
latest_version = verinfo.data.items().begin().value()["name"].get<std::string>();
if (latest_version > MENU_VERSION_NUMBER)
{
CHud::SetHelpMessage("Update found",false,false,false);
state = UPDATER_UPDATE_FOUND;
}
else
{
CHud::SetHelpMessage("No update found.",false,false,false);
Updater::state = UPDATER_IDLE;
}
}
void Updater::DownloadUpdate()
{
std::string link = "https://github.com/user-grinch/Cheat-Menu/releases/download/" + latest_version + "/CheatMenu.7z";
LPCSTR path = PLUGIN_PATH((char*)"update.7z");
HRESULT res = URLDownloadToFile(NULL, link.c_str(), path, 0, NULL);
if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE)
{
CHud::SetHelpMessage("Failed download update",false,false,false);
state = UPDATER_IDLE;
return;
}
CHud::SetHelpMessage("Update downloaded successfully.",false,false,false);
state = UPDATER_DOWNLOADED;
}

View File

@ -7,7 +7,6 @@ enum UPDATER_STATE
UPDATER_DOWNLOADING,
UPDATER_DOWNLOADED,
UPDATER_INSTALLING,
UPDATER_NO_UPDATE,
UPDATER_UPDATE_FOUND
};
@ -15,5 +14,8 @@ class Updater
{
public:
inline static UPDATER_STATE state = UPDATER_IDLE;
inline static std::string latest_version = "";
static void CheckForUpdates();
static void DownloadUpdate();
};