File 0004-don-t-wait-until-the-file-is-downloaded-fully-before.patch of Package unetbootin
From 9cc0841af5d129832d8e2df87355a53f45fca417 Mon Sep 17 00:00:00 2001
From: Valeriy Malov <jazzvoid@gmail.com>
Date: Fri, 28 Jul 2017 22:13:20 +0300
Subject: [PATCH 4/4] don't wait until the file is downloaded fully before
dumping it on disk fix some QNetworkReply/QFile resource freeing delete
dlprogressupdate64 because it's never used fix some slot warnings
---
unetbootin.cpp | 80 ++++++++++++++++-------------------
unetbootin.h | 7 ++-
2 files changed, 39 insertions(+), 48 deletions(-)
diff --git a/unetbootin.cpp b/unetbootin.cpp
index 6ffd6fc..5a6750e 100644
--- a/unetbootin.cpp
+++ b/unetbootin.cpp
@@ -699,17 +699,17 @@ QStringList unetbootin::listalldrives()
return fulldrivelist;
}
-void unetbootin::on_typeselect_currentIndexChanged(int typeselectIndex)
+void unetbootin::on_typeselect_currentIndexChanged(int)
{
refreshdriveslist();
}
-void unetbootin::on_dverselect_currentIndexChanged()
+void unetbootin::on_dverselect_currentIndexChanged(int)
{
radioDistro->setChecked(true);
}
-void unetbootin::on_diskimagetypeselect_currentIndexChanged()
+void unetbootin::on_diskimagetypeselect_currentIndexChanged(int)
{
radioFloppy->setChecked(true);
}
@@ -2640,35 +2640,41 @@ void unetbootin::downloadfile(QString fileurl, QString targetfile, int minsize=5
connect(networkReply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
[&](QNetworkReply::NetworkError code){ downloadFailed = true; errorCode = code; });
+ QFile dloutfile;
+ if (installType == tr("USB Drive"))
+ {
+ dloutfile.setFileName(randtmpfile::getrandfilename(ubntmpf, "tmp"));
+ }
+ else
+ {
+ dloutfile.setFileName(targetfile);
+ }
+ dloutfile.open(QIODevice::WriteOnly);
+
+ connect(networkReply, &QNetworkReply::downloadProgress, [&](qint64, qint64){
+ dloutfile.write(networkReply->readAll());
+ });
+
dlewait.exec();
if (!redirectUrl.isEmpty())
{
+ networkReply->deleteLater();
downloadfile(redirectUrl.toString(), targetfile, minsize);
return;
}
if (downloadFailed)
{
- qDebug() << networkReply->errorString();
+ qDebug() << "Failed to download URL: " << fileurl;
qDebug() << "Error code: " << errorCode;
+ qDebug() << "Error string: " << networkReply->errorString();
+ networkReply->deleteLater();
showDownloadFailedScreen(fileurl);
return;
}
- QFile dloutfile;
- if (installType == tr("USB Drive"))
- {
- dloutfile.setFileName(randtmpfile::getrandfilename(ubntmpf, "tmp"));
- }
- else
- {
- dloutfile.setFileName(targetfile);
- }
-
- dloutfile.open(QIODevice::WriteOnly);
dloutfile.write(networkReply->readAll());
- networkReply->close();
networkReply->deleteLater();
dloutfile.close();
if (installType == tr("USB Drive"))
@@ -2714,34 +2720,19 @@ void unetbootin::showDownloadFailedScreen(const QString &fileurl)
}
}
-void unetbootin::dlprogressupdate(int dlbytes, int maxbytes)
-{
- QTime time = QTime::currentTime();
- static int oldsec = 0;
- // refresh the progress bar every second
- if(oldsec != time.second())
- {
- oldsec = time.second();
- tprogress->setValue(dlbytes);
- tprogress->setMaximum(maxbytes);
- // display the downloaded size with suffix
- pdesc1->setText(tr("<b>Downloaded:</b> %1 of %2").arg(displayfisize(dlbytes)).arg(displayfisize(maxbytes)));
- }
-}
-
void unetbootin::dlprogressupdate64(qint64 dlbytes, qint64 maxbytes)
{
- QTime time = QTime::currentTime();
- static int oldsec = 0;
- // refresh the progress bar every second
- if(oldsec != time.second())
- {
- oldsec = time.second();
- tprogress->setValue(dlbytes);
- tprogress->setMaximum(maxbytes);
- // display the downloaded size with suffix
- pdesc1->setText(tr("<b>Downloaded:</b> %1 of %2").arg(displayfisize(dlbytes)).arg(displayfisize(maxbytes)));
- }
+ QTime time = QTime::currentTime();
+ static int oldsec = 0;
+ // refresh the progress bar every second
+ if(oldsec != time.second())
+ {
+ oldsec = time.second();
+ tprogress->setValue(dlbytes);
+ tprogress->setMaximum(maxbytes);
+ // display the downloaded size with suffix
+ pdesc1->setText(tr("<b>Downloaded:</b> %1 of %2").arg(displayfisize(dlbytes)).arg(displayfisize(maxbytes)));
+ }
}
void unetbootin::cpprogressupdate64(qint64 dlbytes, qint64 maxbytes)
@@ -2761,9 +2752,9 @@ void unetbootin::cpprogressupdate64(qint64 dlbytes, qint64 maxbytes)
QString unetbootin::downloadpagecontents(QUrl pageurl)
{
- QNetworkAccessManager _manager;
+ QNetworkAccessManager manager;
QNetworkRequest dlurl(pageurl);
- QNetworkReply * networkReply = _manager.get(dlurl);
+ QNetworkReply * networkReply = manager.get(dlurl);
QEventLoop pgwait;
QUrl redirectUrl;
connect(networkReply, &QNetworkReply::finished, &pgwait, &QEventLoop::quit);
@@ -2773,6 +2764,7 @@ QString unetbootin::downloadpagecontents(QUrl pageurl)
if (!redirectUrl.isEmpty())
{
+ networkReply->deleteLater();
return downloadpagecontents(redirectUrl);
}
diff --git a/unetbootin.h b/unetbootin.h
index 8cb45d8..99c93a2 100644
--- a/unetbootin.h
+++ b/unetbootin.h
@@ -336,9 +336,9 @@ public:
private slots:
void on_distroselect_currentIndexChanged(int distroselectIndex);
- void on_typeselect_currentIndexChanged(int typeselectIndex);
- void on_dverselect_currentIndexChanged();
- void on_diskimagetypeselect_currentIndexChanged();
+ void on_typeselect_currentIndexChanged(int);
+ void on_dverselect_currentIndexChanged(int);
+ void on_diskimagetypeselect_currentIndexChanged(int);
void on_FloppyFileSelector_clicked();
void on_KernelFileSelector_clicked();
void on_InitrdFileSelector_clicked();
@@ -347,7 +347,6 @@ private slots:
void on_fexitbutton_clicked();
public slots:
- void dlprogressupdate(int dlbytes, int maxbytes);
void dlprogressupdate64(qint64 dlbytes, qint64 maxbytes);
void cpprogressupdate64(qint64 dlbytes, qint64 maxbytes);
void on_okbutton_clicked();
--
2.21.0