From c4625f50a8e34fede444ab27dd8987101c3bba43 Mon Sep 17 00:00:00 2001 From: toster Date: Sat, 14 Apr 2018 20:00:08 +0300 Subject: [PATCH] Pass isAlignmentOptimized flag to piece size calculation --- src/base/bittorrent/torrentcreatorthread.cpp | 5 +++-- src/base/bittorrent/torrentcreatorthread.h | 2 +- src/gui/torrentcreatordlg.cpp | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/torrentcreatorthread.cpp b/src/base/bittorrent/torrentcreatorthread.cpp index e5f92a7c2..d59feefd7 100644 --- a/src/base/bittorrent/torrentcreatorthread.cpp +++ b/src/base/bittorrent/torrentcreatorthread.cpp @@ -157,12 +157,13 @@ void TorrentCreatorThread::run() } } -int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const int pieceSize) +int TorrentCreatorThread::calculateTotalPieces(const QString &inputPath, const int pieceSize, const bool isAlignmentOptimized) { if (inputPath.isEmpty()) return 0; libt::file_storage fs; libt::add_files(fs, Utils::Fs::toNativePath(inputPath).toStdString(), fileFilter); - return libt::create_torrent(fs, pieceSize).num_pieces(); + return libt::create_torrent(fs, pieceSize, -1 + , (isAlignmentOptimized ? libt::create_torrent::optimize_alignment : 0)).num_pieces(); } diff --git a/src/base/bittorrent/torrentcreatorthread.h b/src/base/bittorrent/torrentcreatorthread.h index 2f32db4d4..5704315be 100644 --- a/src/base/bittorrent/torrentcreatorthread.h +++ b/src/base/bittorrent/torrentcreatorthread.h @@ -59,7 +59,7 @@ namespace BitTorrent void create(const TorrentCreatorParams ¶ms); - static int calculateTotalPieces(const QString &inputPath, const int pieceSize); + static int calculateTotalPieces(const QString &inputPath, const int pieceSize, const bool isAlignmentOptimized); protected: void run(); diff --git a/src/gui/torrentcreatordlg.cpp b/src/gui/torrentcreatordlg.cpp index 3c3b5bd1c..fa1e8b2e2 100644 --- a/src/gui/torrentcreatordlg.cpp +++ b/src/gui/torrentcreatordlg.cpp @@ -215,8 +215,9 @@ void TorrentCreatorDlg::updateProgressBar(int progress) void TorrentCreatorDlg::updatePiecesCount() { const QString path = m_ui->textInputPath->text().trimmed(); + const bool isAlignmentOptimized = m_ui->checkOptimizeAlignment->isChecked(); - const int count = BitTorrent::TorrentCreatorThread::calculateTotalPieces(path, getPieceSize()); + const int count = BitTorrent::TorrentCreatorThread::calculateTotalPieces(path, getPieceSize(), isAlignmentOptimized); m_ui->labelTotalPieces->setText(QString::number(count)); }