00001 // 00002 // TransferFile.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_TRANSFERFILE_H__FF7BC368_5878_4BCF_A2AD_055B0355AC3A__INCLUDED_) 00023 #define AFX_TRANSFERFILE_H__FF7BC368_5878_4BCF_A2AD_055B0355AC3A__INCLUDED_ 00024 00025 #pragma once 00026 00027 class CTransferFile; 00028 00029 class CTransferFiles 00030 { 00031 // Construction 00032 public: 00033 CTransferFiles(); 00034 virtual ~CTransferFiles(); 00035 00036 // Attributes 00037 public: 00038 CCriticalSection m_pSection; 00039 CMapStringToPtr m_pMap; 00040 CPtrList m_pDeferred; 00041 00042 // Operations 00043 public: 00044 CTransferFile* Open(LPCTSTR pszFile, BOOL bWrite, BOOL bCreate); 00045 void Close(); 00046 void CommitDeferred(); 00047 protected: 00048 void QueueDeferred(CTransferFile* pFile); 00049 void Remove(CTransferFile* pFile); 00050 00051 friend class CTransferFile; 00052 }; 00053 00054 #define DEFERRED_MAX 8 00055 00056 class CTransferFile 00057 { 00058 // Construction 00059 public: 00060 CTransferFile(LPCTSTR pszPath); 00061 virtual ~CTransferFile(); 00062 00063 // Deferred Write Structure 00064 protected: 00065 class DefWrite 00066 { 00067 public: 00068 QWORD m_nOffset; 00069 DWORD m_nLength; 00070 BYTE* m_pBuffer; 00071 }; 00072 00073 // Attributes 00074 protected: 00075 CString m_sPath; 00076 HANDLE m_hFile; 00077 BOOL m_bWrite; 00078 DWORD m_nReference; 00079 protected: 00080 DefWrite m_pDeferred[DEFERRED_MAX]; 00081 int m_nDeferred; 00082 00083 // Operations 00084 public: 00085 void AddRef(); 00086 void Release(BOOL bWrite); 00087 HANDLE GetHandle(BOOL bWrite = FALSE); 00088 BOOL IsOpen(); 00089 BOOL Read(QWORD nOffset, LPVOID pBuffer, QWORD nBuffer, QWORD* pnRead); 00090 BOOL Write(QWORD nOffset, LPCVOID pBuffer, QWORD nBuffer, QWORD* pnWritten); 00091 protected: 00092 BOOL Open(BOOL bWrite, BOOL bCreate); 00093 BOOL EnsureWrite(); 00094 BOOL CloseWrite(); 00095 void DeferredWrite(BOOL bOffline = FALSE); 00096 00097 friend class CTransferFiles; 00098 00099 }; 00100 00101 00102 extern CTransferFiles TransferFiles; 00103 00104 #endif // !defined(AFX_TRANSFERFILE_H__FF7BC368_5878_4BCF_A2AD_055B0355AC3A__INCLUDED_)