2006-09-30 16:02:39 +00:00
|
|
|
/*
|
2015-04-19 18:17:47 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
2018-04-14 22:53:45 +03:00
|
|
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
2006-09-30 16:02:39 +00:00
|
|
|
*
|
2007-07-14 14:31:59 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-09-30 16:02:39 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-14 14:31:59 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
2009-04-05 17:00:55 +00:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
2006-09-30 16:02:39 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-10 17:56:37 +00:00
|
|
|
#pragma once
|
2006-09-30 16:02:39 +00:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
#include <QStringList>
|
2016-04-28 19:02:38 +08:00
|
|
|
#include <QThread>
|
2006-09-30 16:02:39 +00:00
|
|
|
|
2022-02-08 06:03:48 +03:00
|
|
|
#include "base/path.h"
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
namespace BitTorrent
|
|
|
|
{
|
2021-08-08 13:27:22 +08:00
|
|
|
#ifdef QBT_USES_LIBTORRENT2
|
2020-09-09 15:08:14 +08:00
|
|
|
enum class TorrentFormat
|
|
|
|
{
|
|
|
|
V1,
|
|
|
|
V2,
|
|
|
|
Hybrid
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2017-12-05 23:17:29 +08:00
|
|
|
struct TorrentCreatorParams
|
|
|
|
{
|
|
|
|
bool isPrivate;
|
2021-08-08 13:27:22 +08:00
|
|
|
#ifdef QBT_USES_LIBTORRENT2
|
2020-09-09 15:08:14 +08:00
|
|
|
TorrentFormat torrentFormat;
|
|
|
|
#else
|
2018-04-14 03:24:08 +03:00
|
|
|
bool isAlignmentOptimized;
|
2019-09-10 00:59:43 +08:00
|
|
|
int paddedFileSizeLimit;
|
2020-09-09 15:08:14 +08:00
|
|
|
#endif
|
|
|
|
int pieceSize;
|
2022-02-08 06:03:48 +03:00
|
|
|
Path inputPath;
|
|
|
|
Path savePath;
|
2017-12-05 23:17:29 +08:00
|
|
|
QString comment;
|
2017-12-05 21:18:18 +08:00
|
|
|
QString source;
|
2017-12-05 23:17:29 +08:00
|
|
|
QStringList trackers;
|
|
|
|
QStringList urlSeeds;
|
|
|
|
};
|
|
|
|
|
2020-04-17 12:37:53 +08:00
|
|
|
class TorrentCreatorThread final : public QThread
|
2015-04-19 18:17:47 +03:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2021-06-17 20:28:07 +03:00
|
|
|
Q_DISABLE_COPY_MOVE(TorrentCreatorThread)
|
2007-12-31 16:57:35 +00:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
public:
|
2021-06-17 20:28:07 +03:00
|
|
|
explicit TorrentCreatorThread(QObject *parent = nullptr);
|
|
|
|
~TorrentCreatorThread() override;
|
2007-09-04 04:18:51 +00:00
|
|
|
|
2017-12-05 23:17:29 +08:00
|
|
|
void create(const TorrentCreatorParams ¶ms);
|
2006-09-30 16:02:39 +00:00
|
|
|
|
2021-08-08 13:27:22 +08:00
|
|
|
#ifdef QBT_USES_LIBTORRENT2
|
2022-02-08 06:03:48 +03:00
|
|
|
static int calculateTotalPieces(const Path &inputPath, const int pieceSize, const TorrentFormat torrentFormat);
|
2020-09-09 15:08:14 +08:00
|
|
|
#else
|
2022-02-08 06:03:48 +03:00
|
|
|
static int calculateTotalPieces(const Path &inputPath
|
2019-09-10 00:59:43 +08:00
|
|
|
, const int pieceSize, const bool isAlignmentOptimized, int paddedFileSizeLimit);
|
2020-09-09 15:08:14 +08:00
|
|
|
#endif
|
2017-05-25 22:48:10 +08:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
signals:
|
|
|
|
void creationFailure(const QString &msg);
|
2022-02-08 06:03:48 +03:00
|
|
|
void creationSuccess(const Path &path, const Path &branchPath);
|
2015-04-19 18:17:47 +03:00
|
|
|
void updateProgress(int progress);
|
2010-12-04 10:31:14 +00:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
private:
|
2021-06-17 20:28:07 +03:00
|
|
|
void run() override;
|
2017-12-05 23:17:29 +08:00
|
|
|
void sendProgressSignal(int currentPieceIdx, int totalPieces);
|
2021-06-17 20:28:07 +03:00
|
|
|
void checkInterruptionRequested() const;
|
2010-12-04 10:31:14 +00:00
|
|
|
|
2017-12-05 23:17:29 +08:00
|
|
|
TorrentCreatorParams m_params;
|
2015-04-19 18:17:47 +03:00
|
|
|
};
|
|
|
|
}
|