Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

UploadFile.cpp

Go to the documentation of this file.
00001 //
00002 // UploadFile.cpp
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 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "UploadFile.h"
00025 #include "UploadTransfer.h"
00026 #include "FragmentedFile.h"
00027 #include "Statistics.h"
00028 
00029 #ifdef _DEBUG
00030 #undef THIS_FILE
00031 static char THIS_FILE[]=__FILE__;
00032 #define new DEBUG_NEW
00033 #endif
00034 
00035 
00037 // CUploadFile construction
00038 
00039 CUploadFile::CUploadFile(CUploadTransfer* pUpload, SHA1* pSHA1, LPCTSTR pszName, LPCTSTR pszPath, QWORD nSize)
00040 : m_oFragments( nSize )
00041 {
00042         m_pAddress      = pUpload->m_pHost.sin_addr;
00043         m_sName         = pszName;
00044         m_sPath         = pszPath;
00045         m_nSize         = nSize;
00046 
00047         if ( m_bSHA1 = ( pSHA1 != NULL ) ) m_pSHA1 = *pSHA1;
00048 
00049         m_nRequests             = 0;
00050 
00051         m_bSelected             = FALSE;
00052 
00053         m_pTransfers.AddTail( pUpload );
00054 }
00055 
00056 CUploadFile::~CUploadFile()
00057 {
00058 }
00059 
00061 // CUploadFile transfer operations
00062 
00063 void CUploadFile::Add(CUploadTransfer* pUpload)
00064 {
00065         if ( m_pTransfers.Find( pUpload ) == NULL ) m_pTransfers.AddTail( pUpload );
00066 }
00067 
00068 BOOL CUploadFile::Remove(CUploadTransfer* pUpload)
00069 {
00070         POSITION pos = m_pTransfers.Find( pUpload );
00071         if ( pos == NULL ) return FALSE;
00072 
00073         m_pTransfers.RemoveAt( pos );
00074 
00075         return IsEmpty();
00076 }
00077 
00078 CUploadTransfer* CUploadFile::GetActive() const
00079 {
00080         if ( IsEmpty() ) return NULL;
00081 
00082         for ( POSITION pos = m_pTransfers.GetHeadPosition() ; pos ; )
00083         {
00084                 CUploadTransfer* pUpload = (CUploadTransfer*)m_pTransfers.GetNext( pos );
00085                 if ( pUpload->m_nState != upsNull ) return pUpload;
00086         }
00087 
00088         return (CUploadTransfer*)m_pTransfers.GetTail();
00089 }
00090 
00091 void CUploadFile::Remove()
00092 {
00093         for ( POSITION pos = m_pTransfers.GetHeadPosition() ; pos ; )
00094         {
00095                 CUploadTransfer* pUpload = (CUploadTransfer*)m_pTransfers.GetNext( pos );
00096                 pUpload->Remove();
00097         }
00098 }
00099 
00101 // CUploadFile fragments
00102 
00103 void CUploadFile::AddFragment(QWORD nOffset, QWORD nLength)
00104 {
00105         if ( m_oFragments.empty() )
00106         {
00107                 Statistics.Current.Uploads.Files++;
00108         }
00109 
00110     m_oFragments.insert( FF::SimpleFragment( nOffset, nOffset + nLength ) );
00111 }
00112 

Generated on Thu Dec 15 10:39:50 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2