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