1 /*
2     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 #ifndef BTSINGLEFILECACHE_H
7 #define BTSINGLEFILECACHE_H
8 
9 #include "cache.h"
10 
11 namespace bt
12 {
13 class CacheFile;
14 
15 /**
16  * @author Joris Guisson
17  * @brief Cache for single file torrents
18  *
19  * This class implements Cache for a single file torrent
20  */
21 class KTORRENT_EXPORT SingleFileCache : public Cache
22 {
23 public:
24     SingleFileCache(Torrent &tor, const QString &tmpdir, const QString &datadir);
25     ~SingleFileCache() override;
26 
27     PieceData::Ptr loadPiece(Chunk *c, Uint32 off, Uint32 length) override;
28     PieceData::Ptr preparePiece(Chunk *c, Uint32 off, Uint32 length) override;
29     void savePiece(PieceData::Ptr piece) override;
30     void create() override;
31     void close() override;
32     void open() override;
33     void changeTmpDir(const QString &ndir) override;
34     using Cache::moveDataFiles;
35     Job *moveDataFiles(const QString &ndir) override;
36     using Cache::moveDataFilesFinished;
37     void moveDataFilesFinished(Job *job) override;
38     void changeOutputPath(const QString &outputpath) override;
getOutputPath()39     QString getOutputPath() const override
40     {
41         return output_file;
42     }
43     void preparePreallocation(PreallocationThread *prealloc) override;
44     bool hasMissingFiles(QStringList &sl) override;
45     Job *deleteDataFiles() override;
46     Uint64 diskUsage() override;
47     void loadFileMap() override;
48     void saveFileMap() override;
49     bool getMountPoints(QSet<QString> &mps) override;
50 
51 private:
52     PieceData::Ptr createPiece(Chunk *c, Uint64 off, Uint32 length, bool read_only);
53 
54 private:
55     QString cache_file;
56     QString output_file;
57     QString move_data_files_dst;
58     CacheFile::Ptr fd;
59 };
60 
61 }
62 
63 #endif
64