Used more Qt file info stuff

Sat, 24 Mar 2018 13:28:03 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 13:28:03 +0200
changeset 1330
9155a6b153f3
parent 1329
025578d6e491
child 1331
f10b0c32a85d

Used more Qt file info stuff

src/partdownloader.cpp file | annotate | diff | comparison | revisions
src/partdownloadrequest.cpp file | annotate | diff | comparison | revisions
--- a/src/partdownloader.cpp	Sat Mar 24 13:11:17 2018 +0200
+++ b/src/partdownloader.cpp	Sat Mar 24 13:28:03 2018 +0200
@@ -116,6 +116,11 @@
 		destination.remove(0, 3);
 		destination.prepend("p/48/");
 	}
+	else if (isOneOf(destination.left(2), "8\\", "8/"))
+	{
+		destination.remove(0, 2);
+		destination.prepend("p/8/");
+	}
 
 	/* Try determine where to put this part. We have four directories:
 	 * parts/, parts/s/, p/, and p/48/. If we haven't already specified
--- a/src/partdownloadrequest.cpp	Sat Mar 24 13:11:17 2018 +0200
+++ b/src/partdownloadrequest.cpp	Sat Mar 24 13:28:03 2018 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <QDir>
+#include <QFileInfo>
 #include <QMessageBox>
 #include <QNetworkAccessManager>
 #include <QNetworkRequest>
@@ -36,22 +37,29 @@
 	m_prompt (parent),
 	m_url (url),
 	m_destination (dest),
-	m_filePath (parent->downloadPath() + DIRSLASH + dest),
+	m_filePath (parent->downloadPath() + "/" + dest),
 	m_networkManager (new QNetworkAccessManager),
 	m_isFirstUpdate (true),
 	m_isPrimary (primary),
 	m_filePointer (nullptr)
 {
 	// Make sure that we have a valid destination.
-	QString dirpath = Dirname (filePath());
-	QDir dir (dirpath);
+	QFileInfo destination {m_filePath};
+	QDir downloadDir {parent->downloadPath()};
+	QString relativePath = QFileInfo {dest}.path();
 
-	if (not dir.exists())
+	if (not downloadDir.exists(relativePath))
 	{
-		print ("Creating %1...\n", dirpath);
+		print("Creating %1...\n", relativePath);
 
-		if (not dir.mkpath (dirpath))
-			QMessageBox::critical(m_window, tr("Error"), format(tr("Couldn't create the directory %1!"), dirpath));
+		if (not downloadDir.mkpath(relativePath))
+		{
+			QMessageBox::critical(
+				m_window,
+				tr("Error"),
+				format(tr("Couldn't create the directory %1!"), relativePath)
+			);
+		}
 	}
 
 	m_networkReply = m_networkManager->get (QNetworkRequest (QUrl (url)));
@@ -179,11 +187,13 @@
 {
 	if (networkReply()->error() != QNetworkReply::NoError)
 	{
+		// The state must be set before popping a modal dialog or we may deal with
+		// signals with an invalid state.
+		m_state = State::Failed;
+		print("Unable to download %1: %2\n", destination(), networkReply()->errorString());
+
 		if (isPrimary() and not prompt()->isAborted())
 			QMessageBox::critical(m_window, tr("Error"), networkReply()->errorString());
-
-		print ("Unable to download %1: %2\n", destination(), networkReply()->errorString());
-		m_state = State::Failed;
 	}
 	else if (m_state != State::Failed)
 	{

mercurial