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