Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/autoupdaterdialog.h
7666 views
1
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
6
#include "ui_autoupdaterdialog.h"
7
8
#include "common/types.h"
9
10
#include <QtCore/QTimer>
11
#include <string>
12
#include <string_view>
13
#include <vector>
14
15
class Error;
16
class HTTPDownloader;
17
class QtProgressCallback;
18
19
class CoreThread;
20
21
class AutoUpdaterDialog final : public QDialog
22
{
23
Q_OBJECT
24
25
public:
26
~AutoUpdaterDialog();
27
28
static AutoUpdaterDialog* create(QWidget* const parent, Error* const error);
29
30
ALWAYS_INLINE bool areUpdatesAvailable() const { return m_updates_available; }
31
32
void queueUpdateCheck(bool display_errors, bool ignore_skipped_updates);
33
void queueGetLatestRelease();
34
35
void cancel();
36
37
// (channel name, channel display name)
38
static std::vector<std::pair<QString, QString>> getChannelList();
39
40
static std::string getDefaultTag();
41
static std::string getCurrentUpdateTag();
42
static void cleanupAfterUpdate();
43
static void warnAboutUnofficialBuild();
44
45
Q_SIGNALS:
46
/// Emitted just before the update check finishes, before any messages are displayed.
47
void updateCheckAboutToComplete();
48
49
/// Update check completed, might have an update available.
50
void updateCheckCompleted(bool update_available);
51
52
/// Update was available, but the window was closed.
53
void closed();
54
55
protected:
56
void closeEvent(QCloseEvent* event) override;
57
58
private:
59
AutoUpdaterDialog(QWidget* const parent, Error* const error);
60
61
void setDownloadSectionVisibility(bool visible);
62
63
void reportError(const std::string_view msg);
64
void ensureHttpPollingActive();
65
void httpPollTimerPoll();
66
bool handleCancelledRequest(s32 status_code);
67
68
void downloadUpdateClicked();
69
void skipThisUpdateClicked();
70
void remindMeLaterClicked();
71
72
bool updateNeeded() const;
73
74
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response, bool display_errors);
75
void getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response);
76
77
void queueGetChanges();
78
void getChangesComplete(s32 status_code, const Error& error, std::vector<u8> response);
79
80
bool processUpdate(const std::vector<u8>& update_data);
81
82
#ifdef _WIN32
83
bool doesUpdaterNeedElevation(const std::string& application_dir) const;
84
bool doUpdate(const std::string& application_dir, const std::string& zip_path, const std::string& updater_path,
85
const std::string& program_path);
86
bool extractUpdater(const std::string& zip_path, const std::string& destination_path,
87
const std::string_view check_for_file, Error* error);
88
#endif
89
90
Ui::AutoUpdaterDialog m_ui;
91
92
std::unique_ptr<HTTPDownloader> m_http;
93
QTimer* m_http_poll_timer = nullptr;
94
QtProgressCallback* m_download_progress_callback = nullptr;
95
QString m_latest_sha;
96
QString m_download_url;
97
int m_download_size = 0;
98
99
bool m_cancelled = true;
100
bool m_updates_available = false;
101
};
102
103