# HG changeset patch # User Teemu Piippo # Date 1521890883 -7200 # Node ID 9155a6b153f3c5f09db6e77b42df8c554654db7e # Parent 025578d6e4911742f9274727e9225408cf5a3cbe Used more Qt file info stuff diff -r 025578d6e491 -r 9155a6b153f3 src/partdownloader.cpp --- 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 diff -r 025578d6e491 -r 9155a6b153f3 src/partdownloadrequest.cpp --- 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 +#include #include #include #include @@ -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) {