libktorrent  2.1.1
multifilecache.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 BTMULTIFILECACHE_H
21 #define BTMULTIFILECACHE_H
22 
23 
24 #include <QMap>
25 #include "cache.h"
26 #include "cachefile.h"
27 #include "dndfile.h"
28 
29 namespace bt
30 {
31 
39  class KTORRENT_EXPORT MultiFileCache : public Cache
40  {
41  public:
42  MultiFileCache(Torrent& tor, const QString & tmpdir, const QString & datadir, bool custom_output_name);
43  ~MultiFileCache() override;
44 
45  void changeTmpDir(const QString& ndir) override;
46  void create() override;
47  PieceData::Ptr loadPiece(Chunk* c, Uint32 off, Uint32 length) override;
48  PieceData::Ptr preparePiece(Chunk* c, Uint32 off, Uint32 length) override;
49  void savePiece(PieceData::Ptr piece) override;
50  void close() override;
51  void open() override;
52  Job* moveDataFiles(const QString & ndir) override;
53  void moveDataFilesFinished(Job* job) override;
54  Job* moveDataFiles(const QMap<TorrentFileInterface*, QString> & files) override;
55  void moveDataFilesFinished(const QMap<TorrentFileInterface*, QString> & files, Job* job) override;
56  QString getOutputPath() const override;
57  void changeOutputPath(const QString & outputpath) override;
58  void preparePreallocation(PreallocationThread* prealloc) override;
59  bool hasMissingFiles(QStringList & sl) override;
60  Job* deleteDataFiles() override;
61  Uint64 diskUsage() override;
62  void loadFileMap() override;
63  void saveFileMap() override;
64  bool getMountPoints(QSet<QString>& mps) override;
65 
66  private:
67  void touch(TorrentFile & tf);
68  void downloadStatusChanged(TorrentFile*, bool) override;
69  void saveFirstAndLastChunk(TorrentFile* tf, const QString & src_file, const QString & dst_file);
70  void recreateFile(TorrentFile* tf, const QString & dnd_file, const QString & output_file);
71  PieceData::Ptr createPiece(Chunk* c, Uint32 off, Uint32 length, bool read_only);
72  void calculateOffsetAndLength(Uint32 piece_off, Uint32 piece_len, Uint64 file_off, Uint32 chunk_off, Uint32 chunk_len, Uint64 & off, Uint32 & len);
73 
74  private:
75  QString cache_dir, output_dir;
76  QMap<Uint32, CacheFile::Ptr> files;
77  QMap<Uint32, DNDFile::Ptr> dnd_files;
78  QString new_output_dir;
79  bool opened;
80  };
81 
82 }
83 
84 #endif
bt::Chunk
Keep track of a piece of the file.
Definition: chunk.h:64
bt::Job
Definition: job.h:38
bt::TorrentFile
Definition: torrentfile.h:61
bt::PreallocationThread
Definition: preallocationthread.h:60