Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/autoupdaterwindow.h
4246 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
6
#include "common/types.h"
7
8
#include "ui_autoupdaterwindow.h"
9
10
#include <memory>
11
#include <string>
12
#include <string_view>
13
14
#include <QtCore/QDateTime>
15
#include <QtCore/QStringList>
16
#include <QtCore/QTimer>
17
#include <QtWidgets/QDialog>
18
19
class Error;
20
class HTTPDownloader;
21
22
class EmuThread;
23
24
class AutoUpdaterWindow final : public QWidget
25
{
26
Q_OBJECT
27
28
public:
29
explicit AutoUpdaterWindow(QWidget* parent = nullptr);
30
~AutoUpdaterWindow();
31
32
static bool isSupported();
33
static QStringList getTagList();
34
static std::string getDefaultTag();
35
static void cleanupAfterUpdate();
36
static bool isOfficialBuild();
37
static void warnAboutUnofficialBuild();
38
39
Q_SIGNALS:
40
void updateCheckCompleted();
41
42
public Q_SLOTS:
43
void queueUpdateCheck(bool display_errors);
44
void queueGetLatestRelease();
45
46
private Q_SLOTS:
47
void httpPollTimerPoll();
48
49
void downloadUpdateClicked();
50
void skipThisUpdateClicked();
51
void remindMeLaterClicked();
52
53
protected:
54
void closeEvent(QCloseEvent* event) override;
55
56
private:
57
void reportError(const std::string_view msg);
58
59
bool ensureHttpReady();
60
61
bool updateNeeded() const;
62
std::string getCurrentUpdateTag() const;
63
64
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response, bool display_errors);
65
void getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response);
66
67
void queueGetChanges();
68
void getChangesComplete(s32 status_code, const Error& error, std::vector<u8> response);
69
70
bool processUpdate(const std::vector<u8>& update_data);
71
72
#ifdef _WIN32
73
bool doesUpdaterNeedElevation(const std::string& application_dir) const;
74
bool doUpdate(const std::string& application_dir, const std::string& zip_path, const std::string& updater_path);
75
bool extractUpdater(const std::string& zip_path, const std::string& destination_path, Error* error);
76
#endif
77
78
Ui::AutoUpdaterWindow m_ui;
79
80
std::unique_ptr<HTTPDownloader> m_http;
81
QTimer* m_http_poll_timer = nullptr;
82
QString m_latest_sha;
83
QString m_download_url;
84
int m_download_size = 0;
85
86
bool m_update_will_break_save_states = false;
87
};
88
89