File indexing completed on 2024-11-24 04:31:15
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTDNDFILE_H 0007 #define BTDNDFILE_H 0008 0009 #include <QSharedPointer> 0010 #include <QString> 0011 #include <util/constants.h> 0012 0013 namespace bt 0014 { 0015 class TorrentFile; 0016 0017 /** 0018 * @author Joris Guisson <joris.guisson@gmail.com> 0019 * 0020 * Special file where we keep the first and last chunk of a file which is marked as do not download. 0021 * THe first and last chunk of a file will most certainly be partial chunks. 0022 */ 0023 class DNDFile 0024 { 0025 public: 0026 DNDFile(const QString &path, const TorrentFile *tf, Uint32 chunk_size); 0027 virtual ~DNDFile(); 0028 0029 /// Change the path of the file 0030 void changePath(const QString &npath); 0031 0032 /** 0033 * CHeck integrity of the file, create it if it doesn't exist. 0034 */ 0035 void checkIntegrity(); 0036 0037 /** 0038 * Read the (partial)first chunk into a buffer. 0039 * @param buf The buffer 0040 * @param off Offset off chunk 0041 * @param size How many bytes to read of the first chunk 0042 */ 0043 Uint32 readFirstChunk(Uint8 *buf, Uint32 off, Uint32 size); 0044 0045 /** 0046 * Read the (partial)last chunk into a buffer. 0047 * @param buf The buffer 0048 * @param off Offset off chunk 0049 * @param size How many bytes to read of the last chunk 0050 */ 0051 Uint32 readLastChunk(Uint8 *buf, Uint32 off, Uint32 size); 0052 0053 /** 0054 * Write the partial first chunk. 0055 * @param buf The buffer 0056 * @param off Offset into partial chunk 0057 * @param size Size to write 0058 */ 0059 void writeFirstChunk(const Uint8 *buf, Uint32 off, Uint32 size); 0060 0061 /** 0062 * Write the partial last chunk. 0063 * @param buf The buffer 0064 * @param off Offset into partial chunk 0065 * @param size Size to write 0066 */ 0067 void writeLastChunk(const Uint8 *buf, Uint32 off, Uint32 size); 0068 0069 typedef QSharedPointer<DNDFile> Ptr; 0070 0071 private: 0072 void create(); 0073 0074 private: 0075 QString path; 0076 Uint32 first_size; 0077 Uint32 last_size; 0078 }; 0079 0080 } 0081 0082 #endif