#ifndef DOWNLOADER_H
#define DOWNLOADER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <memory>
#include <QUrl>
#include <QFile>
#include <QDir>

extern QString CHECK_URL;

class Downloader : public QObject
{
    Q_OBJECT
public:
    explicit Downloader(QObject *parent = nullptr);

    void setUrl(const QString &);

    void startDownload(const QString &_url = NULL);

    void checkVersion();

    const QFile &getFile() const;

    const QDir &getDir() const;

    const QString &fileName() const;

    void setFileName(const QString &newFileName);

public slots:

signals:
    void doProgress(qint64, qint64);
    void onError(QNetworkReply::NetworkError);
    void doFinished();

    void doShowInfo(const QString&);

private:
    QNetworkAccessManager *m_pNetWorkAccessManager{nullptr};
    QNetworkReply *m_pReply{nullptr};

    bool m_bIsDownloading = false;          //正在下载标识

    QUrl m_pUrl{};

    QString m_fileName = "";

    QFile file;

    QDir dir;

};

#endif // DOWNLOADER_H
