feat: add version to update menu
This commit is contained in:
@@ -16,6 +16,7 @@ private:
|
||||
bool m_FileWrited;
|
||||
bool m_CancelDownload;
|
||||
DataBuffer m_FileBuffer;
|
||||
std::string m_LastVersion;
|
||||
public:
|
||||
Updater() : m_Progress(0), m_DownloadComplete(false), m_FileWrited(false), m_CancelDownload(false) {}
|
||||
|
||||
@@ -32,6 +33,11 @@ public:
|
||||
|
||||
static std::string getLocalFilePath();
|
||||
static void removeOldFile();
|
||||
|
||||
static std::string getCurrentVersion(){ return TD_VERSION; }
|
||||
std::string getLastVersion() { return m_LastVersion; }
|
||||
|
||||
bool canUpdate();
|
||||
private:
|
||||
std::string getDownloadFileURL();
|
||||
};
|
||||
|
||||
@@ -13,18 +13,20 @@ namespace td {
|
||||
namespace utils {
|
||||
|
||||
bool Updater::checkUpdate() {
|
||||
std::string newFileUrl = getDownloadFileURL();
|
||||
|
||||
if (newFileUrl.empty()) return false;
|
||||
|
||||
httplib::Client client("thesims.freeboxos.fr", 30000);
|
||||
|
||||
if (auto res = client.Get("/Tower%20Defense/version")) {
|
||||
|
||||
std::string currentVersion = TD_VERSION;
|
||||
std::string lastVersion = res.value().body;
|
||||
std::string currentVersion = getCurrentVersion();
|
||||
m_LastVersion = res.value().body;
|
||||
|
||||
if (currentVersion != lastVersion) {
|
||||
// we only look at the first line
|
||||
m_LastVersion = m_LastVersion.substr(0, m_LastVersion.find('\n'));
|
||||
|
||||
std::cout << "Current version : [" << getCurrentVersion() << "]\n";
|
||||
std::cout << "Last version : [" << m_LastVersion << "]\n";
|
||||
|
||||
if (currentVersion != m_LastVersion) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -36,6 +38,10 @@ bool Updater::checkUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Updater::canUpdate() {
|
||||
return !getDownloadFileURL().empty();
|
||||
}
|
||||
|
||||
std::string Updater::getDownloadFileURL() {
|
||||
Os systemOs = getSystemOs();
|
||||
Architecture systemArch = getSystemArchitecture();
|
||||
|
||||
@@ -44,9 +44,20 @@ void UpdateMenu::render() {
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("An update is available!");
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Current version : %s", m_Updater.getCurrentVersion().c_str());
|
||||
ImGui::Text("Last version : %s", m_Updater.getLastVersion().c_str());
|
||||
|
||||
bool canDownloadFile = m_Updater.canUpdate();
|
||||
|
||||
if(!canDownloadFile) ImGui::BeginDisabled();
|
||||
|
||||
if (ImGui::Button("Download")) {
|
||||
m_Updater.downloadUpdate();
|
||||
}
|
||||
|
||||
if(!canDownloadFile) ImGui::EndDisabled();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Cancel")) {
|
||||
m_Opened = false;
|
||||
@@ -55,6 +66,9 @@ void UpdateMenu::render() {
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("No update available!");
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Current version : %s", m_Updater.getCurrentVersion().c_str());
|
||||
ImGui::Text("Last version : %s", m_Updater.getLastVersion().c_str());
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("Checking updates ...");
|
||||
|
||||
Reference in New Issue
Block a user