| 767 | } |
| 768 | |
| 769 | void DownloadManager::removeFile(int index, bool deleteFile) |
| 770 | { |
| 771 | // Avoid triggering refreshes from DirWatcher |
| 772 | ScopedDisableDirWatcher scopedDirWatcher(this); |
| 773 | |
| 774 | if (index >= m_ActiveDownloads.size()) { |
| 775 | throw MyException(tr("remove: invalid download index %1").arg(index)); |
| 776 | } |
| 777 | |
| 778 | DownloadInfo* download = m_ActiveDownloads.at(index); |
| 779 | QString filePath = m_OutputDirectory + "/" + download->m_FileName; |
| 780 | if ((download->m_State == STATE_STARTED) || |
| 781 | (download->m_State == STATE_DOWNLOADING)) { |
| 782 | // shouldn't have been possible |
| 783 | log::error("tried to remove active download"); |
| 784 | return; |
| 785 | } |
| 786 | |
| 787 | if ((download->m_State == STATE_PAUSED) || (download->m_State == STATE_ERROR)) { |
| 788 | filePath = download->m_Output.fileName(); |
| 789 | } |
| 790 | |
| 791 | if (deleteFile) { |
| 792 | if (!shellDelete(QStringList(filePath), true)) { |
| 793 | reportError(tr("failed to delete %1").arg(filePath)); |
| 794 | return; |
| 795 | } |
| 796 | |
| 797 | QFile metaFile(filePath.append(".meta")); |
| 798 | if (metaFile.exists() && !shellDelete(QStringList(filePath), true)) { |
| 799 | reportError(tr("failed to delete meta file for %1").arg(filePath)); |
| 800 | } |
| 801 | } else { |
| 802 | QSettings metaSettings(filePath.append(".meta"), QSettings::IniFormat); |
| 803 | if (!download->m_Hidden) |
| 804 | metaSettings.setValue("removed", true); |
| 805 | } |
| 806 | m_DownloadRemoved(index); |
| 807 | } |
| 808 | |
| 809 | class LessThanWrapper |
| 810 | { |
no test coverage detected