Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/autoupdaterwindow.h
4802 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
void queueUpdateCheck(bool display_errors);
33
void queueGetLatestRelease();
34
35
static bool isSupported();
36
static bool canInstallUpdate();
37
static QStringList getTagList();
38
static std::string getDefaultTag();
39
static void cleanupAfterUpdate();
40
static bool isOfficialBuild();
41
static void warnAboutUnofficialBuild();
42
43
Q_SIGNALS:
44
void updateCheckCompleted();
45
46
protected:
47
void closeEvent(QCloseEvent* event) override;
48
49
private:
50
void httpPollTimerPoll();
51
52
void downloadUpdateClicked();
53
void skipThisUpdateClicked();
54
void remindMeLaterClicked();
55
56
void reportError(const std::string_view msg);
57
58
bool ensureHttpReady();
59
60
bool updateNeeded() const;
61
std::string getCurrentUpdateTag() const;
62
63
void getLatestTagComplete(s32 status_code, const Error& error, std::vector<u8> response, bool display_errors);
64
void getLatestReleaseComplete(s32 status_code, const Error& error, std::vector<u8> response);
65
66
void queueGetChanges();
67
void getChangesComplete(s32 status_code, const Error& error, std::vector<u8> response);
68
69
bool processUpdate(const std::vector<u8>& update_data);
70
71
#ifdef _WIN32
72
bool doesUpdaterNeedElevation(const std::string& application_dir) const;
73
bool doUpdate(const std::string& application_dir, const std::string& zip_path, const std::string& updater_path);
74
bool extractUpdater(const std::string& zip_path, const std::string& destination_path, Error* error);
75
#endif
76
77
Ui::AutoUpdaterWindow m_ui;
78
79
std::unique_ptr<HTTPDownloader> m_http;
80
QTimer* m_http_poll_timer = nullptr;
81
QString m_latest_sha;
82
QString m_download_url;
83
int m_download_size = 0;
84
85
bool m_update_will_break_save_states = false;
86
};
87
88