Edit updater_service.h

This commit is contained in:
collecting
2025-10-25 02:13:00 +00:00
parent 8050dc0cd2
commit 1175bf35b7

View File

@@ -10,88 +10,91 @@
#include <memory>
#include <vector>
// Forward declare to keep headers clean
class QNetworkAccessManager;
#include <QString>
#include <QNetworkAccessManager>
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<DownloadOption> 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<DownloadOption> 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<QNetworkAccessManager> network_manager;
QNetworkReply* current_reply = nullptr;
std::atomic<bool> update_in_progress{false};
std::atomic<bool> 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<QNetworkAccessManager> network_manager;
QNetworkReply* current_reply = nullptr;
std::atomic<bool> update_in_progress{false};
std::atomic<bool> 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