00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _FILEMANAGER_H
00025 #define _FILEMANAGER_H
00026
00027 #ifdef _WIN32
00028 typedef __int64 int64_t;
00029 typedef unsigned __int64 uint64_t;
00030 #else
00031 #include <stdint.h>
00032 #endif
00033 #include <vector>
00034 #include <string>
00035
00036
00037 class PeerHandler;
00038 class Session;
00039
00041
00042 class FileManager
00043 {
00044 public:
00046 struct FIL {
00047 FIL(int64_t l,const std::string& p) : length(l),path(p),fil(NULL) {}
00048 int64_t length;
00049 std::string path;
00050 FILE *fil;
00051 };
00052 typedef std::vector<FIL *> fil_v;
00053 public:
00054 FileManager(PeerHandler&,const std::string& hash);
00055 ~FileManager();
00056
00057 size_t ReadPiece(size_t index,unsigned char *buf,size_t length);
00058 size_t ReadNextPiece(unsigned char *buf,size_t length);
00059 void Write(size_t index,unsigned char *buf,size_t length,size_t begin);
00060 PeerHandler& Handler() { return m_handler; }
00061 void OpenFiles();
00062
00063 size_t GetFilesize(const std::string& );
00064 uint64_t GetTotalLength();
00065 bool Verify(size_t piece,size_t length);
00066 bool CompareHash(unsigned char *h1,unsigned char *h2);
00067
00068 private:
00069 void GetFiles(fil_v& files);
00070
00071 std::string m_hash;
00072 PeerHandler& m_handler;
00073 std::string m_basename;
00074 fil_v m_files;
00075 int64_t m_length;
00076 FILE *m_single_file;
00077 };
00078
00079
00080
00081
00082 #endif // _FILEMANAGER_H