Logo
~Apps~
~Projects~
~Contact~


FileManager.h

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2005  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4