autoupdaterdialog.h (2136B)
1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> 2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) 3 4 #pragma once 5 6 #include "common/types.h" 7 8 #include "ui_autoupdaterdialog.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 AutoUpdaterDialog final : public QDialog 25 { 26 Q_OBJECT 27 28 public: 29 explicit AutoUpdaterDialog(QWidget* parent = nullptr); 30 ~AutoUpdaterDialog(); 31 32 static bool isSupported(); 33 static QStringList getTagList(); 34 static std::string getDefaultTag(); 35 static void cleanupAfterUpdate(); 36 static bool isOfficialBuild(); 37 static bool warnAboutUnofficialBuild(); 38 39 Q_SIGNALS: 40 void updateCheckCompleted(); 41 42 public Q_SLOTS: 43 void queueUpdateCheck(bool display_message); 44 void queueGetLatestRelease(); 45 46 private Q_SLOTS: 47 void httpPollTimerPoll(); 48 49 void downloadUpdateClicked(); 50 void skipThisUpdateClicked(); 51 void remindMeLaterClicked(); 52 53 private: 54 void reportError(const std::string_view msg); 55 56 bool ensureHttpReady(); 57 58 bool updateNeeded() const; 59 std::string getCurrentUpdateTag() const; 60 61 void getLatestTagComplete(s32 status_code, std::vector<u8> response); 62 void getLatestReleaseComplete(s32 status_code, std::vector<u8> response); 63 64 void queueGetChanges(); 65 void getChangesComplete(s32 status_code, std::vector<u8> response); 66 67 bool processUpdate(const std::vector<u8>& update_data); 68 69 #ifdef _WIN32 70 bool doesUpdaterNeedElevation(const std::string& application_dir) const; 71 bool doUpdate(const std::string& application_dir, const std::string& zip_path, const std::string& updater_path); 72 bool extractUpdater(const std::string& zip_path, const std::string& destination_path, Error* error); 73 #endif 74 75 Ui::AutoUpdaterDialog m_ui; 76 77 std::unique_ptr<HTTPDownloader> m_http; 78 QTimer* m_http_poll_timer = nullptr; 79 QString m_latest_sha; 80 QString m_download_url; 81 int m_download_size = 0; 82 83 bool m_display_messages = false; 84 bool m_update_will_break_save_states = false; 85 };