diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index ba7081f..3358492 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -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; diff --git a/src/MenuInfo.h b/src/MenuInfo.h index 32a85e5..610fa40 100644 --- a/src/MenuInfo.h +++ b/src/MenuInfo.h @@ -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 ")" \ No newline at end of file diff --git a/src/Updater.cpp b/src/Updater.cpp index fc5b5cd..4e51b73 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -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(); + latest_version = verinfo.data.items().begin().value()["name"].get(); 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; } \ No newline at end of file diff --git a/src/Updater.h b/src/Updater.h index 06b4110..6f5b5ae 100644 --- a/src/Updater.h +++ b/src/Updater.h @@ -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(); };