From 1175bf35b7ec44514930a42b588a25bdf0a1f887 Mon Sep 17 00:00:00 2001 From: collecting Date: Sat, 25 Oct 2025 02:13:00 +0000 Subject: [PATCH] Edit updater_service.h --- src/citron/updater/updater_service.h | 137 ++++++++++++++------------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/src/citron/updater/updater_service.h b/src/citron/updater/updater_service.h index 0638718bf..d60c3ad2b 100644 --- a/src/citron/updater/updater_service.h +++ b/src/citron/updater/updater_service.h @@ -10,88 +10,91 @@ #include #include -// Forward declare to keep headers clean -class QNetworkAccessManager; +#include + +#include namespace Updater { - std::string ExtractCommitHash(const std::string& version_string); +// Declaration for the helper function. +QString FormatDateTimeString(const std::string& iso_string); +std::string ExtractCommitHash(const std::string& version_string); - struct DownloadOption { - std::string name; - std::string url; - }; +struct DownloadOption { + std::string name; + std::string url; +}; - struct UpdateInfo { - std::string version; - std::vector download_options; // Used for both Windows .zip and Linux .AppImage - std::string changelog; - std::string release_date; - bool is_newer_version = false; - }; +struct UpdateInfo { + std::string version; + std::vector download_options; + std::string changelog; + std::string release_date; + bool is_newer_version = false; +}; - class UpdaterService : public QObject { - Q_OBJECT +class UpdaterService : public QObject { + Q_OBJECT - public: - enum class UpdateResult { Success, Failed, Cancelled, NetworkError, ExtractionError, PermissionError, InvalidArchive, NoUpdateAvailable }; +public: + enum class UpdateResult { Success, Failed, Cancelled, NetworkError, ExtractionError, PermissionError, InvalidArchive, NoUpdateAvailable }; - explicit UpdaterService(QObject* parent = nullptr); - ~UpdaterService() override; + explicit UpdaterService(QObject* parent = nullptr); + ~UpdaterService() override; - void CheckForUpdates(const std::string& update_url); - void DownloadAndInstallUpdate(const std::string& download_url); - void CancelUpdate(); - std::string GetCurrentVersion() const; - bool IsUpdateInProgress() const; + void CheckForUpdates(const std::string& update_url); + void DownloadAndInstallUpdate(const std::string& download_url); + void CancelUpdate(); + std::string GetCurrentVersion() const; + bool IsUpdateInProgress() const; - static bool HasStagedUpdate(const std::filesystem::path& app_directory); - static bool ApplyStagedUpdate(const std::filesystem::path& app_directory); + static bool HasStagedUpdate(const std::filesystem::path& app_directory); + static bool ApplyStagedUpdate(const std::filesystem::path& app_directory); - signals: - void UpdateCheckCompleted(bool has_update, const UpdateInfo& update_info); - void UpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total); - void UpdateInstallProgress(int percentage, const QString& current_file); - void UpdateCompleted(UpdateResult result, const QString& message); - void UpdateError(const QString& error_message); +signals: + void UpdateCheckCompleted(bool has_update, const UpdateInfo& update_info); + void UpdateDownloadProgress(int percentage, qint64 bytes_received, qint64 bytes_total); + void UpdateInstallProgress(int percentage, const QString& current_file); + void UpdateCompleted(UpdateResult result, const QString& message); + void UpdateError(const QString& error_message); - private slots: - void OnDownloadFinished(); - void OnDownloadProgress(qint64 bytes_received, qint64 bytes_total); - void OnDownloadError(QNetworkReply::NetworkError error); +private slots: + void OnDownloadFinished(); + void OnDownloadProgress(qint64 bytes_received, qint64 bytes_total); + void OnDownloadError(QNetworkReply::NetworkError error); - private: - void InitializeSSL(); - void ConfigureSSLForRequest(QNetworkRequest& request); - void ParseUpdateResponse(const QByteArray& response); - bool CompareVersions(const std::string& current, const std::string& latest) const; +private: + void InitializeSSL(); + void ConfigureSSLForRequest(QNetworkRequest& request); + void ParseUpdateResponse(const QByteArray& response); + bool CompareVersions(const std::string& current, const std::string& latest) const; - #ifdef _WIN32 - bool ExtractArchive(const std::filesystem::path& archive_path, const std::filesystem::path& extract_path); - #ifndef CITRON_ENABLE_LIBARCHIVE - bool ExtractArchiveWindows(const std::filesystem::path& archive_path, const std::filesystem::path& extract_path); - #endif - bool InstallUpdate(const std::filesystem::path& update_path); - bool CreateBackup(); - bool RestoreBackup(); - #endif - bool CleanupFiles(); - std::filesystem::path GetTempDirectory() const; - std::filesystem::path GetApplicationDirectory() const; - std::filesystem::path GetBackupDirectory() const; - bool EnsureDirectoryExists(const std::filesystem::path& path) const; + #ifdef _WIN32 + bool ExtractArchive(const std::filesystem::path& archive_path, const std::filesystem::path& extract_path); + #ifndef CITRON_ENABLE_LIBARCHIVE + bool ExtractArchiveWindows(const std::filesystem::path& archive_path, const std::filesystem::path& extract_path); + #endif + bool InstallUpdate(const std::filesystem::path& update_path); + bool CreateBackup(); + bool RestoreBackup(); + #endif + bool CleanupFiles(); + std::filesystem::path GetTempDirectory() const; + std::filesystem::path GetApplicationDirectory() const; + std::filesystem::path GetBackupDirectory() const; + bool EnsureDirectoryExists(const std::filesystem::path& path) const; - std::unique_ptr network_manager; - QNetworkReply* current_reply = nullptr; - std::atomic update_in_progress{false}; - std::atomic cancel_requested{false}; - UpdateInfo current_update_info; - std::filesystem::path app_directory; - std::filesystem::path temp_download_path; - std::filesystem::path backup_path; + std::unique_ptr network_manager; + QNetworkReply* current_reply = nullptr; + std::atomic update_in_progress{false}; + std::atomic cancel_requested{false}; + UpdateInfo current_update_info; + std::filesystem::path app_directory; + std::filesystem::path temp_download_path; + std::filesystem::path backup_path; - static constexpr const char* CITRON_VERSION_FILE = "version.txt"; - static constexpr const char* BACKUP_DIRECTORY = "backup"; - }; + static constexpr const char* CITRON_VERSION_FILE = "version.txt"; + static constexpr const char* BACKUP_DIRECTORY = "backup"; +}; } // namespace Updater