diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 3b49123ce..927edc332 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4416,6 +4416,7 @@ void Session::startUpTorrents() const QVector torrents = startupStorage->registeredTorrents(); int resumedTorrentsCount = 0; QVector queue; + QSet recoveredCategories; #ifdef QBT_USES_LIBTORRENT2 const QSet indexedTorrents {torrents.cbegin(), torrents.cend()}; QSet skippedIDs; @@ -4513,6 +4514,43 @@ void Session::startUpTorrents() if (needStore) m_resumeDataStorage->store(torrentID, resumeData); + const QString category = resumeData.category; + bool isCategoryRecovered = recoveredCategories.contains(category); + if (!category.isEmpty() && (isCategoryRecovered || !m_categories.contains(category))) + { + if (!isCategoryRecovered) + { + if (addCategory(category)) + { + recoveredCategories.insert(category); + isCategoryRecovered = true; + LogMsg(tr("Inconsistent data is detected. Category '%1' is assigned to some torrent(s) but it doesn't exist in the configuration file." + " Its settings will be reset to default.").arg(category), Log::WARNING); + } + else + { + resumeData.category.clear(); + LogMsg(tr("Inconsistent data is detected. Invalid category '%1' is assigned to torrent '%2'.") + .arg(category, torrentID.toString()), Log::WARNING); + } + } + + // We should check isCategoryRecovered again since the category + // can be just recovered by the code above + if (isCategoryRecovered && resumeData.useAutoTMM) + { + const Path storageLocation {resumeData.ltAddTorrentParams.save_path}; + if ((storageLocation != categorySavePath(resumeData.category)) && (storageLocation != categoryDownloadPath(resumeData.category))) + { + resumeData.useAutoTMM = false; + resumeData.savePath = storageLocation; + resumeData.downloadPath = {}; + LogMsg(tr("Torrent '%1' is assigned the recovered category '%2' whose paths don't match the torrent's path." + " Torrent is switched to \"Manual\" mode.").arg(torrentID.toString(), category), Log::WARNING); + } + } + } + qDebug() << "Starting up torrent" << torrentID.toString() << "..."; if (!loadTorrent(resumeData)) {