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

DownloadBase.cpp

Go to the documentation of this file.
00001 //
00002 // DownloadBase.cpp
00003 //
00004 //      Date:                   "$Date: 2005/06/15 22:00:06 $"
00005 //      Revision:               "$Revision: 1.10 $"
00006 //  Last change by:     "$Author: rolandas $"
00007 //
00008 // Copyright (c) Shareaza Development Team, 2002-2005.
00009 // This file is part of SHAREAZA (www.shareaza.com)
00010 //
00011 // Shareaza is free software; you can redistribute it
00012 // and/or modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Shareaza is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with Shareaza; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //
00025 
00026 #include "StdAfx.h"
00027 #include "Shareaza.h"
00028 #include "Settings.h"
00029 #include "Downloads.h"
00030 #include "DownloadBase.h"
00031 #include "DownloadTask.h"
00032 
00033 #include "SHA.h"
00034 #include "ED2K.h"
00035 #include "TigerTree.h"
00036 
00037 #ifdef _DEBUG
00038 #undef THIS_FILE
00039 static char THIS_FILE[]=__FILE__;
00040 #define new DEBUG_NEW
00041 #endif
00042 
00043 
00045 // CDownloadBase construction
00046 
00047 CDownloadBase::CDownloadBase()
00048 {
00049         m_nCookie               = 1;
00050         m_nSize                 = SIZE_UNKNOWN;
00051         m_bSHA1                 = FALSE;
00052         m_bSHA1Trusted  = FALSE;
00053         m_bTiger                = FALSE;
00054         m_bTigerTrusted = FALSE;
00055         m_bMD5                  = FALSE;
00056         m_bMD5Trusted   = FALSE;
00057         m_bED2K                 = FALSE;
00058         m_bED2KTrusted  = FALSE;
00059         m_bBTH                  = FALSE;
00060         m_bBTHTrusted   = FALSE;
00061         m_pTask                 = NULL;
00062 }
00063 
00064 CDownloadBase::~CDownloadBase()
00065 {
00066 }
00067 
00069 // CDownloadBase modified
00070 
00071 void CDownloadBase::SetModified()
00072 {
00073         m_nCookie ++;
00074 }
00075 
00077 // CDownloadBase local name
00078 
00079 void CDownloadBase::GenerateLocalName()
00080 {
00081         if ( m_sLocalName.GetLength() > 0 ) return;
00082 
00083         if ( m_bSHA1 ) m_sLocalName += CSHA::HashToString( &m_pSHA1 );
00084         else if ( m_bTiger ) m_sLocalName += CTigerNode::HashToString( &m_pTiger );
00085         else if ( m_bED2K ) m_sLocalName += CED2K::HashToString( &m_pED2K );
00086         else if ( m_bBTH ) m_sLocalName += CSHA::HashToString( &m_pBTH );
00087 
00088         if ( m_sRemoteName.GetLength() > 0 )
00089         {
00090                 if ( m_sLocalName.GetLength() > 0 ) m_sLocalName += _T(" ");
00091                 m_sLocalName += CDownloadTask::SafeFilename( m_sRemoteName );
00092         }
00093 
00094         if ( m_sLocalName.GetLength() > 0 )
00095         {
00096                 CreateDirectory( Settings.Downloads.IncompletePath, NULL );
00097                 m_sLocalName = Settings.Downloads.IncompletePath + _T("\\") + m_sLocalName;
00098         }
00099 
00100         ASSERT( m_sLocalName.GetLength() < MAX_PATH - 1 );
00101 }
00102 
00104 // CDownloadBase serialize
00105 
00106 void CDownloadBase::Serialize(CArchive& ar, int nVersion)
00107 {
00108         if ( ar.IsStoring() )
00109         {
00110                 ar << m_sRemoteName;
00111                 ar << m_nSize;
00112 
00113                 ar << m_bSHA1;
00114                 if ( m_bSHA1 ) ar.Write( &m_pSHA1, sizeof(SHA1) );
00115                 ar << m_bSHA1Trusted;
00116 
00117                 ar << m_bTiger;
00118                 if ( m_bTiger ) ar.Write( &m_pTiger, sizeof(TIGEROOT) );
00119                 ar << m_bTigerTrusted;
00120 
00121                 ar << m_bMD5;
00122                 if ( m_bMD5 ) ar.Write( &m_pMD5, sizeof(MD5) );
00123                 ar << m_bMD5Trusted;
00124 
00125                 ar << m_bED2K;
00126                 if ( m_bED2K ) ar.Write( &m_pED2K, sizeof(MD4) );
00127                 ar << m_bED2KTrusted;
00128         }
00129         else
00130         {
00131                 ar >> m_sRemoteName;
00132 
00133                 if ( nVersion >= 29 )
00134                 {
00135                         ar >> m_nSize;
00136                 }
00137                 else
00138                 {
00139                         DWORD nSize;
00140                         ar >> nSize;
00141                         m_nSize = nSize;
00142                 }
00143 
00144                 ar >> m_bSHA1;
00145                 if ( m_bSHA1 ) ar.Read( &m_pSHA1, sizeof(SHA1) );
00146                 if ( nVersion >= 31 ) ar >> m_bSHA1Trusted;
00147                 else m_bSHA1Trusted = m_bSHA1;
00148                 if ( ( m_bSHA1 ) && ( CSHA::IsNull( &m_pSHA1 ) ) ) m_bSHA1Trusted = m_bSHA1 = FALSE;
00149 
00150                 ar >> m_bTiger;
00151                 if ( m_bTiger ) ar.Read( &m_pTiger, sizeof(TIGEROOT) );
00152                 if ( nVersion >= 31 ) ar >> m_bTigerTrusted;
00153                 else m_bTigerTrusted = m_bTiger;
00154                 if ( ( m_bTiger ) && ( CTigerNode::IsNull( &m_pTiger ) ) ) m_bTigerTrusted = m_bTiger = FALSE;
00155 
00156                 if ( nVersion >= 22 ) ar >> m_bMD5;
00157                 if ( m_bMD5 ) ar.Read( &m_pMD5, sizeof(MD5) );
00158                 if ( nVersion >= 31 ) ar >> m_bMD5Trusted;
00159                 else m_bMD5Trusted = m_bMD5;
00160 
00161                 if ( nVersion >= 13 ) ar >> m_bED2K;
00162                 if ( m_bED2K ) ar.Read( &m_pED2K, sizeof(MD4) );
00163                 if ( nVersion >= 31 ) ar >> m_bED2KTrusted;
00164                 else m_bED2KTrusted = m_bED2K;
00165 
00166         }
00167 }

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