feat: add updater

This commit is contained in:
2021-11-13 16:06:48 +01:00
parent 67a4ec511e
commit fc0cab54d2
7 changed files with 289 additions and 0 deletions

37
include/misc/Updater.h Normal file
View File

@@ -0,0 +1,37 @@
#pragma once
#include "misc/DataBuffer.h"
namespace td {
namespace utils {
class Updater {
private:
float m_Progress;
bool m_DownloadComplete;
bool m_FileWrited;
bool m_CancelDownload;
DataBuffer m_FileBuffer;
public:
Updater() : m_Progress(0), m_DownloadComplete(false), m_FileWrited(false), m_CancelDownload(false) {}
bool checkUpdate();
void downloadUpdate();
void cancelDownload() { m_CancelDownload = true; m_Progress = 0.0f; m_DownloadComplete = false; }
bool writeFile();
void clearCache() { m_FileBuffer.Clear(); }
float getDownloadProgress() { return m_Progress; }
bool isDownloadComplete() { return m_DownloadComplete; }
bool isFileWrited() { return m_FileWrited; }
static std::string getLocalFilePath();
static void removeOldFile();
private:
std::string getDownloadFileURL();
std::uint32_t getLocalFileSize();
};
} // namespace utils
} // namespace td

View File

@@ -41,6 +41,7 @@ private:
std::unique_ptr<td::gui::MainMenu> m_MainMenu;
std::unique_ptr<td::gui::GameMenu> m_GameMenu;
std::unique_ptr<td::gui::FrameMenu> m_FrameMenu;
std::unique_ptr<td::gui::UpdateMenu> m_UpdateMenu;
bool m_DemoOpened = false;
public:

View File

@@ -0,0 +1,29 @@
#pragma once
#include "GuiWidget.h"
#include "misc/Updater.h"
#include <future>
namespace td {
namespace gui {
class UpdateMenu : public GuiWidget {
private:
bool m_Opened;
std::string m_Error;
utils::Updater m_Updater;
std::shared_future<bool> m_UpdateAvailable;
public:
UpdateMenu(client::Client* client);
virtual void render();
private:
void checkUpdates();
bool isUpdateChecked();
void renderErrorPopup();
};
} // namespace gui
} // namespace td