|
|
|
@ -58,14 +58,13 @@ TorrentCreatorThread::TorrentCreatorThread(QObject *parent)
@@ -58,14 +58,13 @@ TorrentCreatorThread::TorrentCreatorThread(QObject *parent)
|
|
|
|
|
: QThread(parent) |
|
|
|
|
, m_private(false) |
|
|
|
|
, m_pieceSize(0) |
|
|
|
|
, m_abort(false) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TorrentCreatorThread::~TorrentCreatorThread() |
|
|
|
|
{ |
|
|
|
|
m_abort = true; |
|
|
|
|
wait(); |
|
|
|
|
requestInterruption(); |
|
|
|
|
wait(1000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TorrentCreatorThread::create(const QString &inputPath, const QString &savePath, const QStringList &trackers, |
|
|
|
@ -80,7 +79,6 @@ void TorrentCreatorThread::create(const QString &inputPath, const QString &saveP
@@ -80,7 +79,6 @@ void TorrentCreatorThread::create(const QString &inputPath, const QString &saveP
|
|
|
|
|
m_comment = comment; |
|
|
|
|
m_private = isPrivate; |
|
|
|
|
m_pieceSize = pieceSize; |
|
|
|
|
m_abort = false; |
|
|
|
|
|
|
|
|
|
start(); |
|
|
|
|
} |
|
|
|
@ -90,11 +88,6 @@ void TorrentCreatorThread::sendProgressSignal(int numHashes, int numPieces)
@@ -90,11 +88,6 @@ void TorrentCreatorThread::sendProgressSignal(int numHashes, int numPieces)
|
|
|
|
|
emit updateProgress(static_cast<int>((numHashes * 100.) / numPieces)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TorrentCreatorThread::abortCreation() |
|
|
|
|
{ |
|
|
|
|
m_abort = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TorrentCreatorThread::run() |
|
|
|
|
{ |
|
|
|
|
emit updateProgress(0); |
|
|
|
@ -104,7 +97,8 @@ void TorrentCreatorThread::run()
@@ -104,7 +97,8 @@ void TorrentCreatorThread::run()
|
|
|
|
|
libt::file_storage fs; |
|
|
|
|
// Adding files to the torrent
|
|
|
|
|
libt::add_files(fs, Utils::Fs::toNativePath(m_inputPath).toStdString(), fileFilter); |
|
|
|
|
if (m_abort) return; |
|
|
|
|
|
|
|
|
|
if (isInterruptionRequested()) return; |
|
|
|
|
|
|
|
|
|
libt::create_torrent t(fs, m_pieceSize); |
|
|
|
|
|
|
|
|
@ -125,7 +119,8 @@ void TorrentCreatorThread::run()
@@ -125,7 +119,8 @@ void TorrentCreatorThread::run()
|
|
|
|
|
t.add_tracker(tracker.trimmed().toStdString(), tier); |
|
|
|
|
newline = false; |
|
|
|
|
} |
|
|
|
|
if (m_abort) return; |
|
|
|
|
|
|
|
|
|
if (isInterruptionRequested()) return; |
|
|
|
|
|
|
|
|
|
// calculate the hash for all pieces
|
|
|
|
|
const QString parentPath = Utils::Fs::branchPath(m_inputPath) + "/"; |
|
|
|
@ -136,7 +131,8 @@ void TorrentCreatorThread::run()
@@ -136,7 +131,8 @@ void TorrentCreatorThread::run()
|
|
|
|
|
t.set_comment(m_comment.toUtf8().constData()); |
|
|
|
|
// Is private ?
|
|
|
|
|
t.set_priv(m_private); |
|
|
|
|
if (m_abort) return; |
|
|
|
|
|
|
|
|
|
if (isInterruptionRequested()) return; |
|
|
|
|
|
|
|
|
|
// create the torrent and print it to out
|
|
|
|
|
qDebug("Saving to %s", qPrintable(m_savePath)); |
|
|
|
@ -152,6 +148,8 @@ void TorrentCreatorThread::run()
@@ -152,6 +148,8 @@ void TorrentCreatorThread::run()
|
|
|
|
|
if (outfile.fail()) |
|
|
|
|
throw std::exception(); |
|
|
|
|
|
|
|
|
|
if (isInterruptionRequested()) return; |
|
|
|
|
|
|
|
|
|
libt::bencode(std::ostream_iterator<char>(outfile), t.generate()); |
|
|
|
|
outfile.close(); |
|
|
|
|
|
|
|
|
|