qBittorrent
BitTorrent::BencodeResumeDataStorage::Worker Class Referencefinal
Inheritance diagram for BitTorrent::BencodeResumeDataStorage::Worker:
Collaboration diagram for BitTorrent::BencodeResumeDataStorage::Worker:

Public Member Functions

 Worker (const QDir &resumeDataDir)
 
void store (const TorrentID &id, const LoadTorrentParams &resumeData) const
 
void remove (const TorrentID &id) const
 
void storeQueue (const QVector< TorrentID > &queue) const
 

Private Attributes

const QDir m_resumeDataDir
 

Detailed Description

Definition at line 56 of file bencoderesumedatastorage.cpp.

Constructor & Destructor Documentation

◆ Worker()

BitTorrent::BencodeResumeDataStorage::Worker::Worker ( const QDir &  resumeDataDir)
explicit

Definition at line 309 of file bencoderesumedatastorage.cpp.

310  : m_resumeDataDir {resumeDataDir}
311 {
312 }

Member Function Documentation

◆ remove()

void BitTorrent::BencodeResumeDataStorage::Worker::remove ( const TorrentID id) const

Definition at line 386 of file bencoderesumedatastorage.cpp.

387 {
388  const QString resumeFilename = QString::fromLatin1("%1.fastresume").arg(id.toString());
389  Utils::Fs::forceRemove(m_resumeDataDir.absoluteFilePath(resumeFilename));
390 
391  const QString torrentFilename = QString::fromLatin1("%1.torrent").arg(id.toString());
392  Utils::Fs::forceRemove(m_resumeDataDir.absoluteFilePath(torrentFilename));
393 }
bool forceRemove(const QString &filePath)
Definition: fs.cpp:173
QString toString(const lt::socket_type_t socketType)
Definition: session.cpp:183

References Utils::Fs::forceRemove(), BitTorrent::BencodeResumeDataStorage::m_resumeDataDir, and anonymous_namespace{session.cpp}::toString().

Here is the call graph for this function:

◆ store()

void BitTorrent::BencodeResumeDataStorage::Worker::store ( const TorrentID id,
const LoadTorrentParams resumeData 
) const

Definition at line 314 of file bencoderesumedatastorage.cpp.

315 {
316  // We need to adjust native libtorrent resume data
317  lt::add_torrent_params p = resumeData.ltAddTorrentParams;
318  p.save_path = Profile::instance()->toPortablePath(QString::fromStdString(p.save_path)).toStdString();
319  if (resumeData.stopped)
320  {
321  p.flags |= lt::torrent_flags::paused;
322  p.flags &= ~lt::torrent_flags::auto_managed;
323  }
324  else
325  {
326  // Torrent can be actually "running" but temporarily "paused" to perform some
327  // service jobs behind the scenes so we need to restore it as "running"
328  if (resumeData.operatingMode == BitTorrent::TorrentOperatingMode::AutoManaged)
329  {
330  p.flags |= lt::torrent_flags::auto_managed;
331  }
332  else
333  {
334  p.flags &= ~lt::torrent_flags::paused;
335  p.flags &= ~lt::torrent_flags::auto_managed;
336  }
337  }
338 
339  lt::entry data = lt::write_resume_data(p);
340 
341  // metadata is stored in separate .torrent file
342  if (p.ti)
343  {
344  lt::entry::dictionary_type &dataDict = data.dict();
345  lt::entry metadata {lt::entry::dictionary_t};
346  lt::entry::dictionary_type &metadataDict = metadata.dict();
347  metadataDict.insert(dataDict.extract("info"));
348  metadataDict.insert(dataDict.extract("creation date"));
349  metadataDict.insert(dataDict.extract("created by"));
350  metadataDict.insert(dataDict.extract("comment"));
351 
352  const QString torrentFilepath = m_resumeDataDir.absoluteFilePath(QString::fromLatin1("%1.torrent").arg(id.toString()));
353  const nonstd::expected<void, QString> result = Utils::IO::saveToFile(torrentFilepath, metadata);
354  if (!result)
355  {
356  LogMsg(tr("Couldn't save torrent metadata to '%1'. Error: %2.")
357  .arg(torrentFilepath, result.error()), Log::CRITICAL);
358  return;
359  }
360  }
361 
362  data["qBt-ratioLimit"] = static_cast<int>(resumeData.ratioLimit * 1000);
363  data["qBt-seedingTimeLimit"] = resumeData.seedingTimeLimit;
364  data["qBt-category"] = resumeData.category.toStdString();
365  data["qBt-tags"] = setToEntryList(resumeData.tags);
366  data["qBt-name"] = resumeData.name.toStdString();
367  data["qBt-seedStatus"] = resumeData.hasSeedStatus;
368  data["qBt-contentLayout"] = Utils::String::fromEnum(resumeData.contentLayout).toStdString();
369  data["qBt-firstLastPiecePriority"] = resumeData.firstLastPiecePriority;
370 
371  if (!resumeData.useAutoTMM)
372  {
373  data["qBt-savePath"] = Profile::instance()->toPortablePath(resumeData.savePath).toStdString();
374  data["qBt-downloadPath"] = Profile::instance()->toPortablePath(resumeData.downloadPath).toStdString();
375  }
376 
377  const QString resumeFilepath = m_resumeDataDir.absoluteFilePath(QString::fromLatin1("%1.fastresume").arg(id.toString()));
378  const nonstd::expected<void, QString> result = Utils::IO::saveToFile(resumeFilepath, data);
379  if (!result)
380  {
381  LogMsg(tr("Couldn't save torrent resume data to '%1'. Error: %2.")
382  .arg(resumeFilepath, result.error()), Log::CRITICAL);
383  }
384 }
QString toPortablePath(const QString &absolutePath) const
Definition: profile.cpp:121
static const Profile * instance()
Definition: profile.cpp:67
void LogMsg(const QString &message, const Log::MsgType &type)
Definition: logger.cpp:125
@ CRITICAL
Definition: logger.h:48
nonstd::expected< void, QString > saveToFile(const QString &path, const QByteArray &data)
Definition: io.cpp:69
QString fromEnum(const T &value)
Definition: string.h:67

References BitTorrent::LoadTorrentParams::category, BitTorrent::LoadTorrentParams::contentLayout, Log::CRITICAL, BitTorrent::LoadTorrentParams::downloadPath, BitTorrent::LoadTorrentParams::firstLastPiecePriority, Utils::String::fromEnum(), BitTorrent::LoadTorrentParams::hasSeedStatus, Profile::instance(), LogMsg(), BitTorrent::LoadTorrentParams::ltAddTorrentParams, BitTorrent::BencodeResumeDataStorage::m_resumeDataDir, BitTorrent::LoadTorrentParams::name, BitTorrent::LoadTorrentParams::operatingMode, BitTorrent::LoadTorrentParams::ratioLimit, BitTorrent::LoadTorrentParams::savePath, Utils::IO::saveToFile(), BitTorrent::LoadTorrentParams::seedingTimeLimit, anonymous_namespace{bencoderesumedatastorage.cpp}::setToEntryList(), BitTorrent::LoadTorrentParams::stopped, BitTorrent::LoadTorrentParams::tags, Profile::toPortablePath(), anonymous_namespace{session.cpp}::toString(), and BitTorrent::LoadTorrentParams::useAutoTMM.

Here is the call graph for this function:

◆ storeQueue()

void BitTorrent::BencodeResumeDataStorage::Worker::storeQueue ( const QVector< TorrentID > &  queue) const

Definition at line 395 of file bencoderesumedatastorage.cpp.

396 {
397  QByteArray data;
398  data.reserve(((BitTorrent::TorrentID::length() * 2) + 1) * queue.size());
399  for (const BitTorrent::TorrentID &torrentID : queue)
400  data += (torrentID.toString().toLatin1() + '\n');
401 
402  const QString filepath = m_resumeDataDir.absoluteFilePath(QLatin1String("queue"));
403  const nonstd::expected<void, QString> result = Utils::IO::saveToFile(filepath, data);
404  if (!result)
405  {
406  LogMsg(tr("Couldn't save data to '%1'. Error: %2")
407  .arg(filepath, result.error()), Log::CRITICAL);
408  }
409 }
static constexpr int length()
Definition: digest32.h:53

References Log::CRITICAL, Digest32< 160 >::length(), LogMsg(), BitTorrent::BencodeResumeDataStorage::m_resumeDataDir, and Utils::IO::saveToFile().

Here is the call graph for this function:

Member Data Documentation

◆ m_resumeDataDir

const QDir BitTorrent::BencodeResumeDataStorage::Worker::m_resumeDataDir
private

Definition at line 68 of file bencoderesumedatastorage.cpp.


The documentation for this class was generated from the following file: