libktorrent  2.1.1
singlefilecache.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTSINGLEFILECACHE_H
21 #define BTSINGLEFILECACHE_H
22 
23 #include "cache.h"
24 
25 namespace bt
26 {
27  class CacheFile;
28 
29 
36  class KTORRENT_EXPORT SingleFileCache : public Cache
37  {
38  public:
39  SingleFileCache(Torrent& tor,const QString & tmpdir,const QString & datadir);
40  ~SingleFileCache() override;
41 
42  PieceData::Ptr loadPiece(Chunk* c,Uint32 off,Uint32 length) override;
43  PieceData::Ptr preparePiece(Chunk* c,Uint32 off,Uint32 length) override;
44  void savePiece(PieceData::Ptr piece) override;
45  void create() override;
46  void close() override;
47  void open() override;
48  void changeTmpDir(const QString & ndir) override;
50  Job* moveDataFiles(const QString & ndir) override;
52  void moveDataFilesFinished(Job* job) override;
53  void changeOutputPath(const QString& outputpath) override;
54  QString getOutputPath() const override {return output_file;}
55  void preparePreallocation(PreallocationThread* prealloc) override;
56  bool hasMissingFiles(QStringList & sl) override;
57  Job* deleteDataFiles() override;
58  Uint64 diskUsage() override;
59  void loadFileMap() override;
60  void saveFileMap() override;
61  bool getMountPoints(QSet<QString>& mps) override;
62 
63  private:
64  PieceData::Ptr createPiece(Chunk* c,Uint64 off,Uint32 length,bool read_only);
65 
66  private:
67  QString cache_file;
68  QString output_file;
69  QString move_data_files_dst;
70  CacheFile::Ptr fd;
71  };
72 
73 }
74 
75 #endif
bt::Chunk
Keep track of a piece of the file.
Definition: chunk.h:64
bt::Job
Definition: job.h:38
bt::PreallocationThread
Definition: preallocationthread.h:60
bt::Cache::moveDataFiles
virtual Job * moveDataFiles(const QString &ndir)=0
bt::Cache::moveDataFilesFinished
virtual void moveDataFilesFinished(Job *job)=0