mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 06:28:03 -06:00
Allow to save downloaded metadata as torrent file
This commit is contained in:
@@ -3831,13 +3831,18 @@ void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent)
|
||||
torrent->saveResumeData();
|
||||
|
||||
// Save metadata
|
||||
const QDir resumeDataDir(m_resumeFolderPath);
|
||||
QString torrentFile = resumeDataDir.absoluteFilePath(QString("%1.torrent").arg(torrent->hash()));
|
||||
if (torrent->saveTorrentFile(torrentFile)) {
|
||||
const QDir resumeDataDir {m_resumeFolderPath};
|
||||
const QString torrentFileName {QString {"%1.torrent"}.arg(torrent->hash())};
|
||||
try {
|
||||
torrent->info().saveToFile(resumeDataDir.absoluteFilePath(torrentFileName));
|
||||
// Copy the torrent file to the export folder
|
||||
if (!torrentExportDirectory().isEmpty())
|
||||
exportTorrentFile(torrent);
|
||||
}
|
||||
catch (const RuntimeError &err) {
|
||||
LogMsg(tr("Couldn't save torrent metadata file '%1'. Reason: %2")
|
||||
.arg(torrentFileName, err.message()), Log::CRITICAL);
|
||||
}
|
||||
|
||||
emit torrentMetadataLoaded(torrent);
|
||||
}
|
||||
@@ -4352,15 +4357,17 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle)
|
||||
// The following is useless for newly added magnet
|
||||
if (!fromMagnetUri) {
|
||||
// Backup torrent file
|
||||
const QDir resumeDataDir(m_resumeFolderPath);
|
||||
const QString newFile = resumeDataDir.absoluteFilePath(QString("%1.torrent").arg(torrent->hash()));
|
||||
if (torrent->saveTorrentFile(newFile)) {
|
||||
const QDir resumeDataDir {m_resumeFolderPath};
|
||||
const QString torrentFileName {QString {"%1.torrent"}.arg(torrent->hash())};
|
||||
try {
|
||||
torrent->info().saveToFile(resumeDataDir.absoluteFilePath(torrentFileName));
|
||||
// Copy the torrent file to the export folder
|
||||
if (!torrentExportDirectory().isEmpty())
|
||||
exportTorrentFile(torrent);
|
||||
}
|
||||
else {
|
||||
LogMsg(tr("Couldn't save '%1.torrent'").arg(torrent->hash()), Log::CRITICAL);
|
||||
catch (const RuntimeError &err) {
|
||||
LogMsg(tr("Couldn't save torrent metadata file '%1'. Reason: %2")
|
||||
.arg(torrentFileName, err.message()), Log::CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user