feat: add updater
This commit is contained in:
37
include/misc/Updater.h
Normal file
37
include/misc/Updater.h
Normal 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
|
||||
@@ -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:
|
||||
|
||||
29
include/render/gui/UpdateMenu.h
Normal file
29
include/render/gui/UpdateMenu.h
Normal 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
|
||||
Reference in New Issue
Block a user