#ifndef UPDATERDIALOG_H
#define UPDATERDIALOG_H

#include <QDialog>
#include <QProcess>
#include "downloader.h"

extern QString APPVERSION;
extern QString ORIGIN_URL;
extern QString APPNAME;
extern QString CHECK_URL;
extern QString APPDATE;
extern QString MODIFYCNT;

namespace Ui
{
class UpdaterDialog;
}

class UpdaterDialog : public QDialog
{
    Q_OBJECT

public:
    explicit UpdaterDialog(QWidget *parent = nullptr);
    ~UpdaterDialog();

    void showStatus(const QString &);

    void calculateSizes(qint64 received, qint64 total);

    void calculateTimeRemaining(qint64 received, qint64 total);
    bool checkVersion(const QString & _localVersion, const QString & _remoteVersion);

private slots:
    void on_btn_check_clicked();
    void onCheckReply(QNetworkReply *);

    void on_btn_update_clicked();

    void on_btn_cancel_clicked();

    void onDownloadFinished();

    void on_btn_update_patch_clicked();

private:
    Ui::UpdaterDialog *ui;

    Downloader * m_pDownloader = nullptr;

    QString m_version;

    QNetworkAccessManager *m_pManager{nullptr};

    QString m_platform;
    QString m_changelog;
    QString m_moduleName;
    QString m_patchUrl;
    QString m_patchVersion;
    QString m_moduleVersion;
    QString m_fullUrl;
    QString m_fullVersion;
    QString m_lastChangeTime;
    QString m_modifyCnt;

    QString m_fileName = "";

    bool m_bDownloadFullExe = false;

    uint m_startTime;

    quint64 m_totalSize;

    QProcess *m_UpdateProc{nullptr};
};

#endif // UPDATERDIALOG_H
