00001 // 00002 // BTInfo.h 00003 // 00004 // Copyright (c) Shareaza Development Team, 2002-2005. 00005 // This file is part of SHAREAZA (www.shareaza.com) 00006 // 00007 // Shareaza is free software; you can redistribute it 00008 // and/or modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 of 00010 // the License, or (at your option) any later version. 00011 // 00012 // Shareaza is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with Shareaza; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 // 00021 00022 #if !defined(AFX_BTINFO_H__AA44CA36_464F_4FB8_9D79_884D8092ADA0__INCLUDED_) 00023 #define AFX_BTINFO_H__AA44CA36_464F_4FB8_9D79_884D8092ADA0__INCLUDED_ 00024 00025 #pragma once 00026 00027 #include "SHA.h" 00028 #include "ED2K.h" 00029 #include "Buffer.h" 00030 #include "TigerTree.h" 00031 00032 class CBuffer; 00033 class CBENode; 00034 00035 00036 class CBTInfo 00037 { 00038 // Construction 00039 public: 00040 CBTInfo(); 00041 ~CBTInfo(); 00042 00043 // Subclass 00044 public: 00045 class CBTFile 00046 { 00047 public: 00048 CBTFile(); 00049 void Copy(CBTFile* pSource); 00050 void Serialize(CArchive& ar, int nVersion); 00051 public: 00052 CString m_sPath; 00053 QWORD m_nSize; 00054 BOOL m_bSHA1; 00055 SHA1 m_pSHA1; 00056 BOOL m_bED2K; 00057 MD4 m_pED2K; 00058 BOOL m_bTiger; 00059 TIGEROOT m_pTiger; 00060 }; 00061 00062 // Subclass 00063 public: 00064 class CBTTracker 00065 { 00066 public: 00067 CBTTracker(); 00068 ~CBTTracker(); 00069 void Copy(CBTTracker* pSource); 00070 void Serialize(CArchive& ar, int nVersion); 00071 public: 00072 CString m_sAddress; 00073 DWORD m_tLastAccess; 00074 DWORD m_tLastSuccess; 00075 DWORD m_tLastFail; 00076 DWORD m_nFailures; 00077 int m_nTier; 00078 int m_nType; 00079 }; 00080 00081 // Attributes 00082 public: 00083 BOOL m_bValid; 00084 BOOL m_bEncodingError; 00085 SHA1 m_pInfoSHA1; 00086 BOOL m_bDataSHA1; 00087 SHA1 m_pDataSHA1; 00088 BOOL m_bDataED2K; 00089 MD4 m_pDataED2K; 00090 BOOL m_bDataTiger; 00091 TIGEROOT m_pDataTiger; 00092 public: 00093 QWORD m_nTotalSize; 00094 DWORD m_nBlockSize; 00095 DWORD m_nBlockCount; 00096 SHA1* m_pBlockSHA1; 00097 public: 00098 CString m_sName; // Name of the torrent 00099 int m_nFiles; // Number of files 00100 CBTFile* m_pFiles; // List of files 00101 public: 00102 CString m_sTracker; // Address of tracker we are using 00103 00104 CBTTracker* m_pAnnounceTracker; // Tracker in the announce key 00105 CPtrArray m_pTrackerList; // Multi-tracker list 00106 int m_nTrackerIndex; // The tracker we are currently using 00107 public: 00108 UINT m_nEncoding; 00109 CString m_sComment; 00110 DWORD m_tCreationDate; 00111 CString m_sCreatedBy; 00112 private: 00113 CSHA m_pTestSHA1; 00114 DWORD m_nTestByte; 00115 CBuffer m_pSource; 00116 00117 // Operations 00118 public: 00119 void Clear(); 00120 void Copy(CBTInfo* pSource); 00121 void Serialize(CArchive& ar); 00122 public: 00123 BOOL LoadTorrentFile(LPCTSTR pszFile); 00124 BOOL LoadTorrentBuffer(CBuffer* pBuffer); 00125 BOOL LoadTorrentTree(CBENode* pRoot); 00126 BOOL SaveTorrentFile(LPCTSTR pszPath); 00127 public: 00128 void BeginBlockTest(); 00129 void AddToTest(LPCVOID pInput, DWORD nLength); 00130 BOOL FinishBlockTest(DWORD nBlock); 00131 protected: 00132 BOOL CheckFiles(); 00133 00134 // Inlines 00135 public: 00136 inline BOOL IsAvailable() const { return m_bValid; } 00137 inline BOOL HasEncodingError() const { return m_bEncodingError; } 00138 00139 // Check if a string is a valid path/file name. 00140 inline BOOL IsValid(LPCTSTR psz) const 00141 { 00142 if ( _tcsclen( psz ) == 0 ) return FALSE; 00143 if ( _tcschr( psz, '?' ) != NULL ) return FALSE; 00144 if ( _tcsicmp( psz , _T("#ERROR#") ) == 0 ) return FALSE; 00145 00146 return TRUE; 00147 } 00148 00149 }; 00150 00151 00152 #endif // !defined(AFX_BTINFO_H__AA44CA36_464F_4FB8_9D79_884D8092ADA0__INCLUDED_)