📄 knownfile.h
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#include "BarShader.h"
#include <list>
#define PARTSIZE 9728000
class CTag;
class CxImage;
namespace Kademlia{
class CUInt128;
typedef std::list<CStringW> WordList;
};
class CUpDownClient;
class Packet;
class CFileDataIO;
class CAICHHashTree;
class CAICHHashSet;
typedef CTypedPtrList<CPtrList, CUpDownClient*> CUpDownClientPtrList;
class CFileStatistic
{
friend class CKnownFile;
friend class CPartFile;
public:
CFileStatistic()
{
requested = 0;
transferred = 0;
accepted = 0;
alltimerequested = 0;
alltimetransferred = 0;
alltimeaccepted = 0;
}
void MergeFileStats( CFileStatistic* toMerge );
void AddRequest();
void AddAccepted();
void AddTransferred(uint64 bytes);
UINT GetRequests() const {return requested;}
UINT GetAccepts() const {return accepted;}
uint64 GetTransferred() const {return transferred;}
UINT GetAllTimeRequests() const {return alltimerequested;}
UINT GetAllTimeAccepts() const {return alltimeaccepted;}
uint64 GetAllTimeTransferred() const {return alltimetransferred;}
CKnownFile* fileParent;
private:
uint32 requested;
uint32 accepted;
uint64 transferred;
uint32 alltimerequested;
uint64 alltimetransferred;
uint32 alltimeaccepted;
};
/*
CPartFile
/
CKnownFile
/
CAbstractFile
\
CSearchFile
*/
class CAbstractFile: public CObject
{
DECLARE_DYNAMIC(CAbstractFile)
public:
CAbstractFile();
virtual ~CAbstractFile() { }
const CString& GetFileName() const { return m_strFileName; }
virtual void SetFileName(LPCTSTR pszFileName, bool bReplaceInvalidFileSystemChars = false, bool bAutoSetFileType = true); // 'bReplaceInvalidFileSystemChars' is set to 'false' for backward compatibility!
// returns the ED2K file type (an ASCII string)
const CString& GetFileType() const { return m_strFileType; }
virtual void SetFileType(LPCTSTR pszFileType);
// returns the file type which is used to be shown in the GUI
CString GetFileTypeDisplayStr() const;
const uchar* GetFileHash() const { return m_abyFileHash; }
void SetFileHash(const uchar* pucFileHash);
bool HasNullHash() const;
uint32 GetFileSize() const { return m_nFileSize; }
virtual void SetFileSize(uint32 nFileSize) { m_nFileSize = nFileSize; }
uint32 GetIntTagValue(uint8 tagname) const;
uint32 GetIntTagValue(LPCSTR tagname) const;
bool GetIntTagValue(uint8 tagname, uint32& ruValue) const;
const CString& GetStrTagValue(uint8 tagname) const;
const CString& GetStrTagValue(LPCSTR tagname) const;
CTag* GetTag(uint8 tagname, uint8 tagtype) const;
CTag* GetTag(LPCSTR tagname, uint8 tagtype) const;
CTag* GetTag(uint8 tagname) const;
CTag* GetTag(LPCSTR tagname) const;
void AddTagUnique(CTag* pTag);
const CArray<CTag*,CTag*>& GetTags() const { return taglist; }
#ifdef _DEBUG
// Diagnostic Support
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
CString m_strFileName;
uchar m_abyFileHash[16];
uint32 m_nFileSize;
CString m_strComment;
uint8 m_uRating;
CString m_strFileType;
CArray<CTag*,CTag*> taglist;
};
class CKnownFile : public CAbstractFile
{
DECLARE_DYNAMIC(CKnownFile)
public:
CKnownFile();
~CKnownFile();
virtual void SetFileName(LPCTSTR pszFileName, bool bReplaceInvalidFileSystemChars = false); // 'bReplaceInvalidFileSystemChars' is set to 'false' for backward compatibility!
const CString& GetPath() const { return m_strDirectory; }
void SetPath(LPCTSTR path);
const CString& GetFilePath() const { return m_strFilePath; }
void SetFilePath(LPCTSTR pszFilePath);
virtual bool CreateFromFile(LPCTSTR directory, LPCTSTR filename, LPVOID pvProgressParam); // create date, hashset and tags from a file
virtual bool IsPartFile() const { return false; }
virtual bool LoadFromFile(CFileDataIO* file); //load date, hashset and tags from a .met file
bool WriteToFile(CFileDataIO* file);
bool CreateAICHHashSetOnly();
// last file modification time in (DST corrected, if NTFS) real UTC format
// NOTE: this value can *not* be compared with NT's version of the UTC time
CTime GetUtcCFileDate() const { return CTime(m_tUtcLastModified); }
uint32 GetUtcFileDate() const { return m_tUtcLastModified; }
virtual void SetFileSize(uint32 nFileSize);
// local available part hashs
uint16 GetHashCount() const { return hashlist.GetCount(); }
uchar* GetPartHash(uint16 part) const;
const CArray<uchar*, uchar*>& GetHashset() const { return hashlist; }
bool SetHashset(const CArray<uchar*, uchar*>& aHashset);
// nr. of part hashs according the file size wrt ED2K protocol
UINT GetED2KPartHashCount() const { return m_iED2KPartHashCount; }
// nr. of 9MB parts (file data)
__inline uint16 GetPartCount() const { return m_iPartCount; }
// nr. of 9MB parts according the file size wrt ED2K protocol (OP_FILESTATUS)
__inline uint16 GetED2KPartCount() const { return m_iED2KPartCount; }
// file upload priority
uint8 GetUpPriority(void) const { return m_iUpPriority; }
void SetUpPriority(uint8 iNewUpPriority, bool bSave = true);
bool IsAutoUpPriority(void) const { return m_bAutoUpPriority; }
void SetAutoUpPriority(bool NewAutoUpPriority) { m_bAutoUpPriority = NewAutoUpPriority; }
void UpdateAutoUpPriority();
// This has lost it's meaning here.. This is the total clients we know that want this file..
// Right now this number is used for auto priorities..
// This may be replaced with total complete source known in the network..
uint32 GetQueuedCount() { return m_ClientUploadList.GetCount();}
bool LoadHashsetFromFile(CFileDataIO* file, bool checkhash);
void AddUploadingClient(CUpDownClient* client);
void RemoveUploadingClient(CUpDownClient* client);
virtual void UpdatePartsInfo();
virtual void DrawShareStatusBar(CDC* dc, LPCRECT rect, bool onlygreyrect, bool bFlat) const;
// comment
const CString& GetFileComment() /*const*/;
void SetFileComment(LPCTSTR pszComment);
uint8 GetFileRating() /*const*/;
void SetFileRating(uint8 uRating);
bool GetPublishedED2K() const { return m_PublishedED2K; }
void SetPublishedED2K(bool val);
uint32 GetKadFileSearchID() const { return kadFileSearchID; }
void SetKadFileSearchID(uint32 id) { kadFileSearchID = id; } //Don't use this unless you know what your are DOING!! (Hopefully I do.. :)
uint32 GetPublishedKadSrc() const { return m_PublishedKadSrc; }
void SetPublishedKadSrc();
const Kademlia::WordList& GetKadKeywords() const { return wordlist; }
uint32 GetLastPublishTimeKadSrc() const { return m_lastPublishTimeKadSrc; }
void SetLastPublishTimeKadSrc(uint32 val) { m_lastPublishTimeKadSrc = val; }
bool PublishSrc();
// file sharing
virtual Packet* CreateSrcInfoPacket(CUpDownClient* forClient) const;
UINT GetMetaDataVer() const { return m_uMetaDataVer; }
void UpdateMetaDataTags();
void RemoveMetaDataTags();
// preview
bool IsMovie() const;
virtual bool GrabImage(uint8 nFramesToGrab, double dStartTime, bool bReduceColor, uint16 nMaxWidth, void* pSender);
virtual void GrabbingFinished(CxImage** imgResults, uint8 nFramesGrabbed, void* pSender);
// aich
CAICHHashSet* GetAICHHashset() const {return m_pAICHHashSet;}
void SetAICHHashset(CAICHHashSet* val) {m_pAICHHashSet = val;}
// last file modification time in (DST corrected, if NTFS) real UTC format
// NOTE: this value can *not* be compared with NT's version of the UTC time
uint32 m_tUtcLastModified;
CFileStatistic statistic;
time_t m_nCompleteSourcesTime;
uint16 m_nCompleteSourcesCount;
uint16 m_nCompleteSourcesCountLo;
uint16 m_nCompleteSourcesCountHi;
CUpDownClientPtrList m_ClientUploadList;
CArray<uint16, uint16> m_AvailPartFrequency;
#ifdef _DEBUG
// Diagnostic Support
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
//preview
bool GrabImage(CString strFileName, uint8 nFramesToGrab, double dStartTime, bool bReduceColor, uint16 nMaxWidth, void* pSender);
bool LoadTagsFromFile(CFileDataIO* file);
bool LoadDateFromFile(CFileDataIO* file);
void CreateHash(CFile* pFile, UINT uSize, uchar* pucHash, CAICHHashTree* pShaHashOut = NULL) const;
bool CreateHash(FILE* fp, UINT uSize, uchar* pucHash, CAICHHashTree* pShaHashOut = NULL) const;
bool CreateHash(const uchar* pucData, UINT uSize, uchar* pucHash, CAICHHashTree* pShaHashOut = NULL) const;
void LoadComment();
CArray<uchar*, uchar*> hashlist;
CString m_strDirectory;
CString m_strFilePath;
CAICHHashSet* m_pAICHHashSet;
private:
static CBarShader s_ShareStatusBar;
uint16 m_iPartCount;
uint16 m_iED2KPartCount;
uint16 m_iED2KPartHashCount;
uint8 m_iUpPriority;
bool m_bAutoUpPriority;
bool m_bCommentLoaded;
bool m_PublishedED2K;
uint32 kadFileSearchID;
uint32 m_lastPublishTimeKadSrc;
uint32 m_PublishedKadSrc;
Kademlia::WordList wordlist;
UINT m_uMetaDataVer;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -