Upstream tarball 20080721
[amule.git] / src / MuleCollection.h
blob48e14fd2d39fff57459415f8bf28474781e17e28
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2007-2008 Johannes Krampf ( wuischke@amule.org )
5 //
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
8 // respective authors.
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef __MULECOLLECTION_H__
27 #define __MULECOLLECTION_H__
29 #include <string>
30 #include <vector>
32 #ifndef __MINGW32__
33 #include "Types.h"
34 #endif
36 struct CollectionFile
38 std::string m_fileName;
39 uint64_t m_fileSize;
40 std::string m_fileHash;
42 CollectionFile(
43 const std::string &fileName = "",
44 uint64_t fileSize = 0,
45 const std::string &fileHash = "");
49 class CMuleCollection
51 private:
52 std::vector<CollectionFile> vCollection;
54 public:
55 CMuleCollection();
56 ~CMuleCollection();
58 bool Open(const std::string &File);
59 size_t GetFileCount() const { return vCollection.size(); }
61 std::string GetEd2kLink(size_t index) const;
62 std::string GetFileName(size_t index) const;
63 uint64_t GetFileSize(size_t index) const;
64 std::string GetFileHash(size_t index) const;
66 private:
67 bool OpenBinary(const std::string &File);
68 bool OpenText(const std::string &File);
70 bool AddLink(const std::string &Link);
71 bool AddFile(
72 const std::string &fileName,
73 uint64_t fileSize,
74 const std::string &fileHash);
76 static bool IsValidHash(const std::string &fileHash);
78 template <typename intType>
79 intType ReadInt(std::ifstream& infile);
81 std::string ReadString(std::ifstream& infile, int TagType);
84 #endif // __MULECOLLECTION_H__