void HttpUpdater::downloadFinished()
{
    progressBar.hide();
    binFile.close();

    if (requestInstaller->error())
    {
        QMessageBox::warning(0, "HEXplorer::update", QString(requestInstaller->errorString()) +
                              "\n\n" +
                              "Please control your internet connection \n" +
                              "or set the proxy parameters properly into Edit/Settings",
                              QMessageBox::Ok, QMessageBox::Cancel);

        return; //exit
    }

    QMessageBox msgBox;
    msgBox.setIconPixmap(QPixmap(":/icones/updates.png").scaled(80,80));
    msgBox.setText("Download completed.");
    msgBox.setInformativeText("Would you like to install ?");
    msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    msgBox.setDefaultButton(QMessageBox::Yes);
    int ret = msgBox.exec();

    //update user_List
    if (ret == QMessageBox::Yes)
    {
        //execute the downloaded file
        launchInstaller();
    }
    else
        return;
}
示例#2
0
void Updater::httpFinishedInstaller()
{
    if (httpRequestAborted) {
        if (installer) {
            installer->close();
            installer->remove();
            delete installer;
            installer = 0;
        }
        instReply->deleteLater();
        return;
    }
    
    if(installer->isOpen()) {
        installer->flush();
        installer->close();
    }

    mProgDialog->hide();
    if (instReply->error()) {
        installer->remove();
        //TODO: prompt user that the download failed.
        qWarning() << "failed to download the file.";
    } else {
        launchInstaller();
    }

    instReply->deleteLater();
    instReply = 0;

    installer->deleteLater();
}
DownloadUpdateDialog::DownloadUpdateDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DownloadUpdateDialog)
{
    ui->setupUi(this);
    netManager = new QNetworkAccessManager();
    connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
    connect(netManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(handleSslErrors(QNetworkReply*,QList<QSslError>)));
    connect(ui->button_install, SIGNAL(pressed()), this, SLOT(launchInstaller()));
    setupUi();
}
示例#4
0
void HttpUpdater::managerRequestFinished(QNetworkReply *reply)
{
    if (reply == replyXml)
    {
        //if xml file could not be downloaded
        if (reply->error())
        {
            QMessageBox::warning(0, "HEXplorer::update", QString(reply->errorString()) +
                                  "\n\n" +
                                  "HEXplorer could not read update.xml file for available updates.\n\n" +
                                  "Please control or configure your internet connection \n" +
                                  "setting properly the proxy parameters if you are behind a proxy\n" +
                                  "or simply disabling the automatic updates into Edit/Settings.\n",
                                  QMessageBox::Ok, QMessageBox::Cancel);

            return; //exit download
        }

        if (!reply->open(QFile::ReadOnly | QFile::Text))
        {
            QMessageBox::warning(0, "HEXplorer::update", "Unable to open update.xml file",
                                  QMessageBox::Ok, QMessageBox::Cancel);

            return;
        }
        else
        {
            QJsonDocument jsonDocument = QJsonDocument::fromJson(reply->readAll());
            QJsonObject rootObject = jsonDocument.object();
            QByteArray data = QByteArray::fromBase64(rootObject.value("content").toVariant().toByteArray());

            QXmlStreamReader reader(data);

            while (!reader.atEnd())
            {
                reader.readNext();
                if (reader.isStartElement() && reader.attributes().hasAttribute("version"))
                {
                    newVersion = reader.attributes().value("version").toString();
                    QString old_Version = qApp->applicationVersion();
                    QStringList oldList = old_Version.split(".");
                    QStringList newList = newVersion.split(".");
                    if (newList.at(0).toDouble() > oldList.at(0).toDouble())
                    {
                        reader.readNext();
                        if(reader.isCharacters())
                        {
                            updateFilePath = reader.text().toString();
                        }
                    }
                    else if (newList.at(0).toDouble() == oldList.at(0).toDouble())
                    {
                        if (newList.at(1).toDouble() > oldList.at(1).toDouble())
                        {
                            reader.readNext();
                            if(reader.isCharacters())
                            {
                                updateFilePath = reader.text().toString();
                            }
                        }
                        else if (newList.at(1).toDouble() == oldList.at(1).toDouble())
                        {
                            if (newList.at(2).toDouble() > oldList.at(2).toDouble())
                            {
                                reader.readNext();
                                if(reader.isCharacters())
                                {
                                    updateFilePath = reader.text().toString();
                                }
                            }
                        }
                    }
                }
                else if (reader.isStartElement() && reader.qualifiedName() == "details")
                {
                    reader.readNext();
                    if(reader.isCharacters())
                    {
                        updateDetails = reader.text().toString();
                    }
                }
            }

            //display streamreader error
            if (reader.error())
            {
                QMessageBox::critical(0, "HEXplorer::update", reader.errorString(),
                                      QMessageBox::Ok, QMessageBox::Cancel);
                return;
            }

            //if update is or not available, do:
            if(updateFilePath.isEmpty())
            {
                if (displayUptoDate)
                {
                    QMessageBox::information(0, "HEXplorer::update", "You are up to date at version "
                                             + qApp->applicationVersion(),
                                             QMessageBox::Ok, QMessageBox::Cancel);
                }
            }
            else
            {
                QMessageBox msgBox;
                msgBox.setIconPixmap(QPixmap(":/icones/updates.png").scaled(80,80));
                msgBox.setText("A new update is available :\n - current version installed: " + qApp->applicationVersion() + "\n - new version available: " + newVersion);
                //msgBox.setInformativeText("would you like to download it?");
                msgBox.setInformativeText("Download at https://github.com/adhoc2/HEXplorer/releases/");
                //msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
                //msgBox.setDefaultButton(QMessageBox::Yes);
                msgBox.setDefaultButton(QMessageBox::Ok);
                msgBox.setDetailedText(updateDetails);
                int ret = msgBox.exec();

                if (ret == QMessageBox::Yes)
                {
                    //binUrl.setUrl(updateFilePath);
                    binUrl.setUrl("https://api.github.com/repos/adhoc2/HEXplorer/releases/assets/2328230");
                    //binUrl.setUrl("https://github.com/adhoc2/HEXplorer/releases/download/v0.7.12/setup_HEXplorer_0712.exe");
                    downloadInstaller(binUrl);
                }
                else
                    return;
            }

        }
    }
    else if (reply == replyDownloader)
    {
        progressBar.hide();
        binFile.close();

        if (reply->error())
        {
            QMessageBox::warning(0, "HEXplorer::update", QString(reply->errorString()) +
                                  "\n\n" +
                                  "Please control your internet connection \n" +
                                  "or set the proxy parameters properly into Edit/Settings",
                                  QMessageBox::Ok, QMessageBox::Cancel);

            return; //exit
        }

        QMessageBox msgBox;
        msgBox.setIconPixmap(QPixmap(":/icones/updates.png").scaled(80,80));
        msgBox.setText("Download completed.");
        msgBox.setInformativeText("Would you like to install ?");
        msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        msgBox.setDefaultButton(QMessageBox::Yes);
        int ret = msgBox.exec();

        //update user_List
        if (ret == QMessageBox::Yes)
        {
            //execute the downloaded file
            launchInstaller();
        }
        else
            return;
    }
}