Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/autoupdaterdialog.h
6233 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 EmuThread;
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
void queueUpdateCheck(bool display_errors);
31
void queueGetLatestRelease();
32
33
// (channel name, channel display name)
34
static std::vector<std::pair<QString, QString>> getChannelList();
35
36
static std::string getDefaultTag();
37
static std::string getCurrentUpdateTag();
38
static void cleanupAfterUpdate();
39
static void warnAboutUnofficialBuild();
40
41
Q_SIGNALS:
42
/// Update check completed, might have an update available.
43
void updateCheckCompleted(bool update_available);
44
45
/// Update was available, but the window was closed.
46
void closed();
47
48
protected:
49
void closeEvent(QCloseEvent* event) override;
50
51
private:
52
AutoUpdaterDialog(QWidget* const parent, Error* const error);
53
54
void setDownloadSectionVisibility(bool visible);
55
56
void reportError(const std::string_view msg);
57
void ensureHttpPollingActive();
58
void httpPollTimerPoll();
59
60
void downloadUpdateClicked();
61
void skipThisUpdateClicked();
62
void remindMeLaterClicked();
63
64
bool updateNeeded() const;
65
66
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response, bool display_errors);
67
void getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response);
68
69
void queueGetChanges();
70
void getChangesComplete(s32 status_code, const Error& error, std::vector<u8> response);
71
72
bool processUpdate(const std::vector<u8>& update_data);
73
74
#ifdef _WIN32
75
bool doesUpdaterNeedElevation(const std::string& application_dir) const;
76
bool doUpdate(const std::string& application_dir, const std::string& zip_path, const std::string& updater_path,
77
const std::string& program_path);
78
bool extractUpdater(const std::string& zip_path, const std::string& destination_path,
79
const std::string_view check_for_file, Error* error);
80
#endif
81
82
Ui::AutoUpdaterDialog m_ui;
83
84
std::unique_ptr<HTTPDownloader> m_http;
85
QTimer* m_http_poll_timer = nullptr;
86
QtProgressCallback* m_download_progress_callback = nullptr;
87
QString m_latest_sha;
88
QString m_download_url;
89
int m_download_size = 0;
90
91
bool m_update_will_break_save_states = false;
92
};
93
94