* @brief Called when the download finishes. * * Renames the partial file, emits @c downloadFinished(), and triggers the * install flow. */
| 210 | * install flow. |
| 211 | */ |
| 212 | void Downloader::finished() |
| 213 | { |
| 214 | if (!m_reply || m_reply->error() != QNetworkReply::NoError) { |
| 215 | QFile::remove(m_downloadDir.filePath(m_fileName + PARTIAL_DOWN)); |
| 216 | if (m_reply) { |
| 217 | m_reply->deleteLater(); |
| 218 | m_reply = nullptr; |
| 219 | } |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | // Flush any data not yet delivered through downloadProgress |
| 224 | saveFile(0, 0); |
| 225 | |
| 226 | // Rename file |
| 227 | QFile::rename(m_downloadDir.filePath(m_fileName + PARTIAL_DOWN), |
| 228 | m_downloadDir.filePath(m_fileName)); |
| 229 | |
| 230 | // Notify application |
| 231 | emit downloadFinished(m_url, m_downloadDir.filePath(m_fileName)); |
| 232 | |
| 233 | // Install the update |
| 234 | m_reply->deleteLater(); |
| 235 | m_reply = nullptr; |
| 236 | installUpdate(); |
| 237 | setVisible(false); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @brief Opens the downloaded file using the system's default handler. |