debian: fix build-deps for focal
[amule.git] / src / SharedFileList.h
blob157c325b88c71f3f92643885dd930c7c2fb10289
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 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.
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 <list>
30 #include <map>
31 #include <wx/thread.h> // Needed for wxMutex
33 #include "Types.h" // Needed for uint16 and uint64
35 struct UnknownFile_Struct;
37 class CKnownFileList;
38 class CKnownFile;
39 class CMemFile;
40 class CMD4Hash;
41 class CServer;
42 class CPublishKeywordList;
43 class CPath;
44 class CAICHHash;
45 class CThreadTask;
48 typedef std::map<CMD4Hash,CKnownFile*> CKnownFileMap;
49 typedef std::map<wxString, CPath> StringPathMap;
50 typedef std::list<CPath> PathList;
52 class CSharedFileList {
53 public:
54 CSharedFileList(CKnownFileList* in_filelist);
55 ~CSharedFileList();
56 void Reload();
57 void SafeAddKFile(CKnownFile* toadd, bool bOnlyAdd = false);
58 void RemoveFile(CKnownFile* toremove);
59 CKnownFile* GetFileByID(const CMD4Hash& filehash);
60 short GetFilePriorityByID(const CMD4Hash& filehash);
61 const CKnownFile* GetFileByIndex(unsigned int index) const;
62 size_t GetCount() { wxMutexLocker lock(list_mut); return m_Files_map.size(); }
63 size_t GetFileCount() { wxMutexLocker lock(list_mut); return m_Files_map.size(); }
64 void CopyFileList(std::vector<CKnownFile*>& out_list) const;
65 void UpdateItem(CKnownFile* toupdate);
66 void GetSharedFilesByDirectory(const wxString& directory, CKnownFilePtrList& list);
67 void ClearED2KPublishInfo();
68 void RepublishFile(CKnownFile* pFile);
69 void Process();
70 void PublishNextTurn() { m_lastPublishED2KFlag = true; }
71 bool RenameFile(CKnownFile* pFile, const CPath& newName);
73 /**
74 * Returns the name of a folder visible to the public.
76 * @param dir The full path to a shared directory.
77 * @return The name of the shared directory that will be visible to the public.
79 * This function is used to hide sensitive data considering the directory structure of the client.
80 * The returned public name consists of only subdirectories that are shared.
81 * Example: /ed2k/shared/games/tetris -> "games/tetris" if /ed2k/shared are not marked as shared
83 wxString GetPublicSharedDirName(const CPath& dir);
84 const CPath* GetDirForPublicSharedDirName(const wxString& strSharedDir) const;
86 /**
87 * Returns true, if the specified path points to a shared directory or single shared file.
89 bool IsShared(const CPath& path) const;
91 /* Kad Stuff */
92 void Publish();
93 void AddKeywords(CKnownFile* pFile);
94 void RemoveKeywords(CKnownFile* pFile);
95 // This is actually unused, but keep it here - will be needed later.
96 void ClearKadSourcePublishInfo();
98 /**
99 * Checks for files which missing or wrong AICH hashes.
100 * Those that are found are scheduled for ACIH hashing.
102 void CheckAICHHashes(const std::list<CAICHHash>& hashes);
104 private:
105 typedef std::list<CThreadTask *> TaskList;
107 bool AddFile(CKnownFile* pFile);
108 unsigned AddFilesFromDirectory(const CPath& directory, TaskList & hashTasks);
109 void FindSharedFiles();
110 bool reloading;
112 void SendListToServer();
113 uint32 m_lastPublishED2K;
114 bool m_lastPublishED2KFlag;
116 CKnownFileList* filelist;
118 CKnownFileMap m_Files_map;
119 mutable wxMutex list_mut;
121 StringPathMap m_PublicSharedDirNames; //! used for mapping strings to shared directories
123 /* Kad Stuff */
124 CPublishKeywordList* m_keywords;
125 unsigned int m_currFileSrc;
126 unsigned int m_currFileNotes;
127 unsigned int m_currFileKey;
128 uint32 m_lastPublishKadSrc;
129 uint32 m_lastPublishKadNotes;
132 #endif // SHAREDFILELIST_H
133 // File_checked_for_headers