File indexing completed on 2024-05-19 05:01:59
0001 /* 0002 SPDX-FileCopyrightText: 2010 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef DUMMYTORRENTCREATOR_H 0008 #define DUMMYTORRENTCREATOR_H 0009 0010 #include <QMap> 0011 #include <QStringList> 0012 #include <QTemporaryDir> 0013 #include <util/constants.h> 0014 0015 /** 0016 Utility class for tests, to create dummy torrents (and their files) 0017 It will create the torrent and the data in a temporary dir with the following layout: 0018 0019 tmpdir 0020 |-> torrent // This is the torrent 0021 |-> data 0022 |-> filename.ext // for a single file torrent 0023 or 0024 |-> toplevel_dir // for a multifile torrent 0025 0026 The created files will be filled with random data 0027 */ 0028 class DummyTorrentCreator 0029 { 0030 public: 0031 DummyTorrentCreator(); 0032 virtual ~DummyTorrentCreator(); 0033 0034 /// Set the tracker URL's (by default http://localhost:5000/announce is used) 0035 void setTrackers(const QStringList &urls) 0036 { 0037 trackers = urls; 0038 } 0039 0040 /** 0041 Create a single file torrent 0042 @param size The size of the torrent 0043 @param filename The name of the file 0044 */ 0045 bool createSingleFileTorrent(bt::Uint64 size, const QString &filename); 0046 0047 /** 0048 Create a multi file torrent 0049 @param files Map of files in the torrent, and their respective sizes 0050 @param name The name of the torrent (will be used for the toplevel directory name) 0051 */ 0052 bool createMultiFileTorrent(const QMap<QString, bt::Uint64> &files, const QString &name); 0053 0054 /// Get the full path of the torrent file 0055 QString torrentPath() const; 0056 0057 /// Get the full path of the single data file or toplevel directory (in case of multifile torrents) 0058 QString dataPath() const; 0059 0060 /// Get the temp path used 0061 QString tempPath() const 0062 { 0063 return tmpdir.path(); 0064 } 0065 0066 private: 0067 bool createRandomFile(const QString &path, bt::Uint64 size); 0068 0069 private: 0070 QTemporaryDir tmpdir; 0071 QString dpath; 0072 0073 QStringList trackers; 0074 bt::Uint32 chunk_size; 0075 }; 0076 0077 #endif // DUMMYTORRENTCREATOR_H