File indexing completed on 2025-01-05 04:37:26
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 SPDX-FileCopyrightText: 2005 Ivan Vasic <ivasic@gmail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #ifndef BTTORRENTFILE_H 0008 #define BTTORRENTFILE_H 0009 0010 #include <interfaces/torrentfileinterface.h> 0011 #include <qstring.h> 0012 #include <util/constants.h> 0013 0014 namespace bt 0015 { 0016 class ChunkManager; 0017 class Torrent; 0018 0019 /** 0020 * @author Joris Guisson 0021 * 0022 * File in a multi file torrent. Keeps track of the path of the file, 0023 * it's size, offset into the cache and between which chunks it lies. 0024 */ 0025 class KTORRENT_EXPORT TorrentFile : public TorrentFileInterface 0026 { 0027 Q_OBJECT 0028 0029 Torrent *tor; 0030 Uint64 cache_offset; 0031 Priority priority; 0032 Priority old_priority; 0033 bool missing; 0034 0035 public: 0036 /** 0037 * Default constructor. Creates a null TorrentFile. 0038 */ 0039 TorrentFile(Torrent *tor = nullptr); 0040 0041 /** 0042 * Constructor. 0043 * @param index Index number of the file 0044 * @param path Path of the file 0045 * @param off Offset into the torrent 0046 * (i.e. how many bytes were all the previous files in the torrent combined) 0047 * @param size Size of the file 0048 * @param chunk_size Size of each chunk 0049 */ 0050 TorrentFile(Torrent *tor, Uint32 index, const QString &path, Uint64 off, Uint64 size, Uint64 chunk_size); 0051 0052 /** 0053 * Copy constructor. 0054 * @param tf The TorrentFile to copy 0055 */ 0056 TorrentFile(const TorrentFile &tf); 0057 ~TorrentFile() override; 0058 0059 /// Get the offset into the torrent 0060 Uint64 getCacheOffset() const 0061 { 0062 return cache_offset; 0063 } 0064 0065 /// Get the offset at which the file starts in the first chunk 0066 Uint64 getFirstChunkOffset() const 0067 { 0068 return first_chunk_off; 0069 } 0070 0071 /// Get how many bytes the files takes up of the last chunk 0072 Uint64 getLastChunkSize() const 0073 { 0074 return last_chunk_size; 0075 } 0076 0077 /// Check if this file doesn't have to be downloaded 0078 bool doNotDownload() const override 0079 { 0080 return (priority == EXCLUDED); 0081 } 0082 0083 /// Set whether we have to not download this file 0084 void setDoNotDownload(bool dnd) override; 0085 0086 /// Checks if this file is multimedial 0087 bool isMultimedia() const override; 0088 0089 /// Gets the priority of the file 0090 Priority getPriority() const override 0091 { 0092 return priority; 0093 } 0094 0095 /// Sets the priority of the file 0096 void setPriority(Priority newpriority = NORMAL_PRIORITY) override; 0097 0098 /// Get the previous priority value 0099 Priority getOldPriority() const 0100 { 0101 return old_priority; 0102 } 0103 0104 /// emits signal. 0105 void emitDownloadStatusChanged() override; 0106 0107 void setEmitDownloadStatusChanged(bool show) override 0108 { 0109 emit_status_changed = show; 0110 } 0111 0112 /** 0113 * Assignment operator 0114 * @param tf The file to copy 0115 * @return *this 0116 */ 0117 TorrentFile &operator=(const TorrentFile &tf); 0118 0119 /// See if the file is missing 0120 bool isMissing() const 0121 { 0122 return missing; 0123 } 0124 0125 /// Set the file to be missing or not 0126 void setMissing(bool m) 0127 { 0128 missing = m; 0129 } 0130 0131 /** 0132 * Calculate the offset of a chunk in the file 0133 * @param cindex Index of chunk 0134 * @param chunk_size Size of each chunk 0135 */ 0136 Uint64 fileOffset(Uint32 cindex, Uint64 chunk_size) const; 0137 0138 static TorrentFile null; 0139 0140 /** 0141 * Update the number of downloaded chunks for this file. 0142 * @param cman The ChunkManager 0143 */ 0144 void updateNumDownloadedChunks(ChunkManager &cman); 0145 }; 0146 0147 } 0148 0149 #endif