Polyphase Game Engine
Loading...
Searching...
No Matches
AutoUpdater.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include "ReleaseInfo.h"
6#include <thread>
7#include <mutex>
8#include <atomic>
9#include <string>
10
14enum class UpdateCheckState
15{
16 Idle, // No check in progress
17 Checking, // Currently checking for updates
18 UpdateAvailable, // A new version is available
19 UpToDate, // Current version is up to date
20 Error, // An error occurred during check
21 Downloading, // Currently downloading the update
22 DownloadComplete // Download finished, ready to install
23};
24
28class AutoUpdater
29{
30public:
31 static void Create();
32 static void Destroy();
33 static AutoUpdater* Get();
34
39 void CheckForUpdates(bool showUIOnNoUpdate = false);
40
44 void Cancel();
45
49 void StartDownload();
50
54 void LaunchInstaller();
55
59 void Update();
60
64 UpdateCheckState GetState() const { return mState.load(); }
65
69 const ReleaseInfo& GetLatestRelease() const { return mLatestRelease; }
70
74 const std::string& GetErrorMessage() const { return mErrorMessage; }
75
79 float GetDownloadProgress() const;
80
84 size_t GetDownloadedBytes() const { return mDownloadedBytes.load(); }
85
89 size_t GetTotalBytes() const { return mTotalBytes.load(); }
90
94 void DismissUpdate();
95
99 void SkipThisVersion();
100
104 bool ShouldShowWindow() const { return mShowWindow; }
105
109 void SetShowWindow(bool show) { mShowWindow = show; }
110
111private:
112 AutoUpdater();
113 ~AutoUpdater();
114
115 void CheckThreadFunc();
116 void DownloadThreadFunc();
117 bool ParseReleaseJson(const std::string& json);
118 void JoinThreads();
119
120 static AutoUpdater* sInstance;
121
122 // Background threads
123 std::thread mCheckThread;
124 std::thread mDownloadThread;
125
126 // Thread control
127 std::atomic<bool> mRunning{false};
128 std::atomic<bool> mCancelRequested{false};
129 std::atomic<UpdateCheckState> mState{UpdateCheckState::Idle};
130
131 // Download progress
132 std::atomic<size_t> mDownloadedBytes{0};
133 std::atomic<size_t> mTotalBytes{0};
134
135 // Results (protected by mutex)
136 std::mutex mResultMutex;
137 ReleaseInfo mLatestRelease;
138 std::string mErrorMessage;
139 std::string mDownloadedInstallerPath;
140
141 // UI state
142 bool mShowUIOnNoUpdate = false;
143 bool mShowWindow = false;
144 bool mCheckCompleteThisFrame = false;
145 bool mDownloadCompleteThisFrame = false;
146
147 // GitHub API config
148 static constexpr const char* kGitHubApiUrl = "https://api.github.com/repos/polyphase-labs/polyphase-engine/releases/latest";
149 static constexpr const char* kGitHubApiAllReleasesUrl = "https://api.github.com/repos/polyphase-labs/polyphase-engine/releases";
150};
151
152#endif // EDITOR
bool Update()
Definition Engine.cpp:710