Upstream tarball 9574
[amule.git] / src / SharedFileList.h
blob4abd5b23a8e3d9d09c1b98d128c3fdf0d72d78f9
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef SHAREDFILELIST_H
27 #define SHAREDFILELIST_H
29 #include <map>
30 #include <wx/thread.h> // Needed for wxMutex
32 #include "Types.h" // Needed for uint16 and uint64
34 struct UnknownFile_Struct;
36 class CKnownFileList;
37 class CKnownFile;
38 class CMemFile;
39 class CMD4Hash;
40 class CServer;
41 class CUpDownClient;
42 class CPublishKeywordList;
43 class CPath;
44 class CAICHHash;
47 typedef std::map<CMD4Hash,CKnownFile*> CKnownFileMap;
49 class CSharedFileList {
50 public:
51 CSharedFileList(CKnownFileList* in_filelist);
52 ~CSharedFileList();
53 void Reload();
54 void SafeAddKFile(CKnownFile* toadd, bool bOnlyAdd = false);
55 void RemoveFile(CKnownFile* toremove);
56 CKnownFile* GetFileByID(const CMD4Hash& filehash);
57 short GetFilePriorityByID(const CMD4Hash& filehash);
58 const CKnownFile* GetFileByIndex(unsigned int index) const;
59 void CreateOfferedFilePacket(CKnownFile* cur_file, CMemFile* files, CServer* pServer, CUpDownClient* pClient);
60 size_t GetCount() { wxMutexLocker lock(list_mut); return m_Files_map.size(); }
61 size_t GetFileCount() { wxMutexLocker lock(list_mut); return m_Files_map.size(); }
62 void CopyFileList(std::vector<CKnownFile*>& out_list);
63 void UpdateItem(CKnownFile* toupdate);
64 unsigned AddFilesFromDirectory(const CPath& directory);
65 void GetSharedFilesByDirectory(const wxString& directory, CKnownFilePtrList& list);
66 void ClearED2KPublishInfo();
67 void RepublishFile(CKnownFile* pFile);
68 void Process();
69 void PublishNextTurn() { m_lastPublishED2KFlag = true; }
70 bool RenameFile(CKnownFile* pFile, const CPath& newName);
72 /* Kad Stuff */
73 void Publish();
74 void AddKeywords(CKnownFile* pFile);
75 void RemoveKeywords(CKnownFile* pFile);
76 // This is actually unused, but keep it here - will be needed later.
77 void ClearKadSourcePublishInfo();
79 /**
80 * Checks for files which missing or wrong AICH hashes.
81 * Those that are found are scheduled for ACIH hashing.
83 void CheckAICHHashes(const std::list<CAICHHash>& hashes);
85 private:
86 bool AddFile(CKnownFile* pFile);
87 void FindSharedFiles();
88 bool reloading;
90 void SendListToServer();
91 uint32 m_lastPublishED2K;
92 bool m_lastPublishED2KFlag;
94 CKnownFileList* filelist;
96 CKnownFileMap m_Files_map;
97 mutable wxMutex list_mut;
100 /* Kad Stuff */
101 CPublishKeywordList* m_keywords;
102 unsigned int m_currFileSrc;
103 unsigned int m_currFileNotes;
104 unsigned int m_currFileKey;
105 uint32 m_lastPublishKadSrc;
106 uint32 m_lastPublishKadNotes;
109 #endif // SHAREDFILELIST_H
110 // File_checked_for_headers