DownloadPub.cpp
上传用户:oadesign
上传日期:2013-12-25
资源大小:265k
文件大小:18k
- // DownloadPub.cpp: implementation of the CDownloadPub class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "NetDownMTR.h"
- #include "DownloadPub.h"
- // for PathFindExtension () / PathFindFileName ()
- #include "Shlwapi.h"
- #pragma comment ( lib, "shlwapi.lib" )
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- // 下载数据保存的临时缓冲大小
- #define TEMP_SAVE_BUFFER_SIZE (10*NET_BUFFER_SIZE)
- // 当下载的数据达到这个数的时候才保存到文件中
- #define WRITE_TEMP_SAVE_MIN_BYTES (TEMP_SAVE_BUFFER_SIZE / 2)
- void DownloadNotify ( int nIndex, UINT nNotityType, LPVOID lpNotifyData, LPVOID pDownloadMTR );
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CDownloadPub::CDownloadPub()
- {
- m_hThread = NULL;
- m_TimeLastModified = -1;
- m_csDownloadUrl = _T("");
- m_csSaveFileName = _T("");
- m_Proc_SaveDownloadInfo = NULL;
- m_wSaveDownloadInfo_Param = NULL;
- m_bSupportResume = FALSE;
- m_nFileTotalSize = -1;
- m_csReferer = _T("");
- m_csUserAgent = _T("XieHongWei-HttpDown/2.0");
- m_csUsername = _T("");
- m_csPassword = _T("");
- m_csProtocolType = "http";
- m_csServer = _T("");
- m_csObject = _T("");
- m_csFileName = _T("");
- m_nPort = DEFAULT_HTTP_PORT ;
- m_nIndex = -1;
- ResetVar ();
- m_hEvtEndModule = ::CreateEvent ( NULL, TRUE, FALSE, NULL );
- m_pDownloadMTR = NULL;
- }
- void CDownloadPub::ResetVar()
- {
- Clear_Thread_Handle ();
- m_nWillDownloadStartPos = 0;
- m_nWillDownloadSize = -1;
- m_nDownloadedSize = 0;
- m_nTempSaveBytes = 0;
- m_bDownloadSuccess = FALSE;
- }
- CDownloadPub::~CDownloadPub()
- {
- StopDownload ();
- Clear_Thread_Handle ();
- }
- void CDownloadPub::StopDownload ()
- {
- if ( HANDLE_IS_VALID(m_hEvtEndModule) )
- {
- ::SetEvent ( m_hEvtEndModule );
- WaitForThreadEnd ( m_hThread,30*1000 );
- CLOSE_HANDLE ( m_hEvtEndModule );
- m_hEvtEndModule = NULL;
- Clear_Thread_Handle ();
- }
- }
- //
- // 设置认证信息
- //
- void CDownloadPub::SetAuthorization ( LPCTSTR lpszUsername, LPCTSTR lpszPassword )
- {
- if( lpszUsername != NULL )
- {
- m_csUsername = GET_SAFE_STRING(lpszUsername);
- m_csPassword = GET_SAFE_STRING(lpszPassword);
- }
- else
- {
- m_csUsername = _T("");
- m_csPassword = _T("");
- }
- }
- // 设置Referer
- void CDownloadPub::SetReferer(LPCTSTR lpszReferer)
- {
- if( lpszReferer != NULL )
- m_csReferer = lpszReferer;
- else
- m_csReferer = _T("");
- }
- // 设置UserAgent
- void CDownloadPub::SetUserAgent(LPCTSTR lpszUserAgent)
- {
- m_csUserAgent = lpszUserAgent;
- if( m_csUserAgent.IsEmpty())
- m_csUserAgent = _T("XieHongWei-HttpDown/2.0");
- }
- //
- // 设置保存下载信息回调函数
- //
- void CDownloadPub::Set_SaveDownloadInfo_Callback ( FUNC_SaveDownloadInfo Proc_SaveDownloadInfo, WPARAM wParam )
- {
- m_Proc_SaveDownloadInfo = Proc_SaveDownloadInfo;
- m_wSaveDownloadInfo_Param = wParam;
- }
- //
- // 下载任务的线程函数
- //
- DWORD WINAPI ThreadProc_Download(
- LPVOID lpParameter // thread data
- )
- {
- CDownloadPub *pDownloadPub = (CDownloadPub*)lpParameter;
- ASSERT ( pDownloadPub );
- return pDownloadPub->ThreadProc_Download ();
- }
- BOOL CDownloadPub::ThreadProc_Download()
- {
- for ( int i=0; i<RETRY_TIMES; i++ )
- {
- if ( DownloadOnce () )
- return DownloadEnd(TRUE);
- SLEEP_RETURN_Down ( 5*1000 );
- }
- return DownloadEnd(FALSE);
- }
- BOOL CDownloadPub::DownloadOnce()
- {
- // 打开文件
- if ( !OpenFileForSave () )
- return FALSE;
- // 连接到服务器
- if ( !m_SocketClient.Is_Connected () )
- {
- if ( !Connect () )
- return FALSE;
- }
- return TRUE;
- }
- //
- // 创建线程下载文件
- //
- BOOL CDownloadPub::Download (
- int nWillDownloadStartPos, // 要下载文件的开始位置
- int nWillDownloadSize, // 本次需要下载的大小,-1表示一直下载到文件尾
- int nDownloadedSize // 已下载的字节数,指完全写到文件中的字节数
- )
- {
- // 设置下载参数
- m_nWillDownloadStartPos = nWillDownloadStartPos;
- Set_WillDownloadSize ( nWillDownloadSize );
- if ( m_nFileTotalSize > 0 && Get_WillDownloadSize() > m_nFileTotalSize )
- {
- Set_WillDownloadSize ( m_nFileTotalSize );
- }
- Set_DownloadedSize ( nDownloadedSize );
- // 创建一个下载线程
- DWORD dwThreadId = 0;
- m_hThread = CreateThread ( NULL, 0, ::ThreadProc_Download, LPVOID(this), 0, &dwThreadId );
- if ( !HANDLE_IS_VALID(m_hThread) )
- {
- Log ( L_WARNING, "Create download thread failed" );
- return FALSE;
- }
- return TRUE;
- }
- //
- // 下载结束
- //
- BOOL CDownloadPub::DownloadEnd(BOOL bRes)
- {
- m_bDownloadSuccess = bRes;
- m_SocketClient.Disconnect ();
- if ( HANDLE_IS_VALID ( m_file.m_hFile ) )
- {
- m_file.Close ();
- }
- TRACE ( "=============== 线程。%d 下载 %s 结束n", m_nIndex, bRes?"成功":"!!! 失败 !!!" );
- return bRes;
- }
- BOOL CDownloadPub::Connect()
- {
- if ( !HANDLE_IS_VALID(m_hEvtEndModule) )
- return FALSE;
- if ( m_csServer.IsEmpty() )
- {
- Log ( L_WARNING, "Please set download URL" );
- return FALSE;
- }
- m_SocketClient.SetEventOfEndModule ( m_hEvtEndModule );
- // 连接到服务器
- if ( !m_SocketClient.Connect ( m_csServer, m_nPort ) )
- return FALSE;
- TRACE ( "对象.%d 连接到服务器 成功n", m_nIndex );
- return TRUE;
- }
- BOOL CDownloadPub::SetDownloadUrl(LPCTSTR lpszDownloadUrl)
- {
- if ( !lpszDownloadUrl ) return FALSE;
- m_csDownloadUrl = lpszDownloadUrl;
- // 检验要下载的URL是否为空
- m_csDownloadUrl.TrimLeft();
- m_csDownloadUrl.TrimRight();
- if( m_csDownloadUrl.IsEmpty() )
- return FALSE;
- // 检验要下载的URL是否有效
- if ( !ParseURL(m_csDownloadUrl, m_csServer, m_csObject, m_nPort, m_csProtocolType))
- {
- TRACE(_T("Failed to parse the URL: %sn"), m_csDownloadUrl);
- return FALSE;
- }
- return TRUE;
- }
- //
- // 从服务器接收数据并保存到文件中
- //
- BOOL CDownloadPub::RecvDataAndSaveToFile(CSocketClient &SocketClient,char *szTailData/*=NULL*/, int nTailSize/*=0*/)
- {
- int nDownloadedSize = Get_DownloadedSize();
- if ( szTailData && nTailSize > 0 )
- {
- nDownloadedSize = SaveDataToFile ( szTailData, nTailSize );
- if ( nDownloadedSize < 0 )
- {
- return FALSE;
- }
- }
- char szRecvBuf[NET_BUFFER_SIZE] = {0}, *szTempSaveBuf = new char[TEMP_SAVE_BUFFER_SIZE];
- if ( !szTempSaveBuf )
- {
- Log ( L_ERROR, "Allocate memory failed" );
- return FALSE;
- }
- m_nTempSaveBytes = 0;
- while ( TRUE )
- {
- BOOL bDownloadFinished = FALSE;
- int nReadSize = 0;
- int nTempSaveBytes = Get_TempSaveBytes ();
- int nRecvTotalBytes = nDownloadedSize+nTempSaveBytes; // 保存在文件中的字节数加上临时缓冲中的字节数就是总共接收到字节数
- int nWillDownloadSize = Get_WillDownloadSize ();
- // 从字节数判断,本次下载已经完成了
- if ( nWillDownloadSize > 0 && nRecvTotalBytes >= nWillDownloadSize )
- {
- bDownloadFinished = TRUE;
- }
- else
- {
- int nRecvBytesThisTimes = sizeof(szRecvBuf);
- if ( nWillDownloadSize > 0 )
- nRecvBytesThisTimes = nWillDownloadSize - nRecvTotalBytes;
- ASSERT ( nRecvBytesThisTimes >= 0 );
- nRecvBytesThisTimes = MIN ( nRecvBytesThisTimes, sizeof(szRecvBuf) );
- nReadSize = SocketClient.Receive ( szRecvBuf, nRecvBytesThisTimes );
- // 读不到数据了,所以认为下载已经完成
- if ( nReadSize <= 0 )
- {
- if ( nWillDownloadSize <= 0 )
- {
- bDownloadFinished = TRUE;
- }
- }
- else
- {
- // TRACE ( "对象.%d, 收到 %d 字节,我的任务是 %d (0x%08x)字节n",
- // m_nIndex, nReadSize, nWillDownloadSize , nWillDownloadSize );
- }
- }
- // 先将数据保存到临时缓冲中
- if ( nReadSize > 0 )
- {
- nReadSize = MIN ( nReadSize, TEMP_SAVE_BUFFER_SIZE-nTempSaveBytes );
- memcpy ( szTempSaveBuf+nTempSaveBytes, szRecvBuf, nReadSize );
- nTempSaveBytes += nReadSize;
- ASSERT ( nTempSaveBytes < TEMP_SAVE_BUFFER_SIZE );
- }
- // 当下载已完成或者收到的数据超过一定数量时才保存到文件中
- if ( bDownloadFinished || nTempSaveBytes >= WRITE_TEMP_SAVE_MIN_BYTES )
- {
- // 保存文件失败,下载也应该终止
- nDownloadedSize = SaveDataToFile ( szTempSaveBuf, nTempSaveBytes );
- if ( nDownloadedSize < 0 )
- {
- break;
- }
- nTempSaveBytes = 0;
- }
- Set_TempSaveBytes ( nTempSaveBytes );
- if ( bDownloadFinished )
- {
- ASSERT ( (nWillDownloadSize > 0 && nDownloadedSize >= nWillDownloadSize) || (nReadSize <= 0 && nWillDownloadSize <= 0) );
- break;
- }
-
- SLEEP_BREAK ( 1 );
- }
- if ( szTempSaveBuf ) delete[] szTempSaveBuf;
- szTempSaveBuf = NULL;
- BOOL bRes = FALSE;
- int nWillDownloadSize = Get_WillDownloadSize ();
- if ( nWillDownloadSize != -1 )
- {
- if ( nDownloadedSize >= nWillDownloadSize )
- bRes = TRUE;
- }
- else if ( nDownloadedSize > 0 )
- {
- bRes = TRUE;
- }
-
- return bRes;
- }
- int CDownloadPub::SaveDataToFile(char *data, int size)
- {
- ASSERT ( HANDLE_IS_VALID ( m_file.m_hFile ) );
- if ( !data || size < 0 )
- return -1;
- int nDownloadedSize = -1;
- // 保存下载的数据
- ASSERT ( HANDLE_IS_VALID(m_file.m_hFile) );
- BOOL bRet = TRUE;
- TRY
- {
- m_file.Write ( data, size );
- }
- CATCH( CFileException, e )
- {
- e->Delete ();
- bRet = FALSE;
- }
- END_CATCH
- if ( !bRet )
- {
- Log ( L_WARNING, "Write data to local file [%s] failed", m_file.GetFileName() );
- }
- else
- {
- nDownloadedSize = Get_DownloadedSize();
- // TRACE ( "对象.%d, 保存 %d(0x%08x) 字节,偏移 %d(0x%08x) 字节, 共 %d(0x%08x) 字节n",
- // m_nIndex, size, size, m_nWillDownloadStartPos+nDownloadedSize, m_nWillDownloadStartPos+nDownloadedSize,
- // nDownloadedSize + size, nDownloadedSize + size );
- nDownloadedSize += size;
- Set_DownloadedSize ( nDownloadedSize );
- if ( m_Proc_SaveDownloadInfo )
- m_Proc_SaveDownloadInfo ( m_nIndex, nDownloadedSize, size, m_wSaveDownloadInfo_Param );
- }
- if ( !bRet ) return -1;
- return nDownloadedSize;
- }
- BOOL CDownloadPub::GetRemoteSiteInfo()
- {
- return TRUE;
- }
- CString CDownloadPub::GetRemoteFileName()
- {
- int nPos = m_csObject.ReverseFind ( '/' );
- if ( nPos <= 0 ) return m_csObject;
- return m_csObject.Mid ( nPos+1 );
- }
- const char* g_szBase64TAB = _T( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" );
- // BASE64编码
- int Base64Encode(LPCTSTR lpszEncoding, CString &strEncoded)
- {
- UINT m_nBase64Mask[]= { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
- int nDigit;
- int nNumBits = 6;
- int nIndex = 0;
- int nInputSize;
- strEncoded = _T( "" );
- if( lpszEncoding == NULL )
- return 0;
- if( ( nInputSize = lstrlen(lpszEncoding) ) == 0 )
- return 0;
- int nBitsRemaining = 0;
- long lBitsStorage =0;
- long lScratch =0;
- int nBits;
- UCHAR c;
- while( nNumBits > 0 )
- {
- while( ( nBitsRemaining < nNumBits ) && ( nIndex < nInputSize ) )
- {
- c = lpszEncoding[ nIndex++ ];
- lBitsStorage <<= 8;
- lBitsStorage |= (c & 0xff);
- nBitsRemaining += 8;
- }
- if( nBitsRemaining < nNumBits )
- {
- lScratch = lBitsStorage << ( nNumBits - nBitsRemaining );
- nBits = nBitsRemaining;
- nBitsRemaining = 0;
- }
- else
- {
- lScratch = lBitsStorage >> ( nBitsRemaining - nNumBits );
- nBits = nNumBits;
- nBitsRemaining -= nNumBits;
- }
- nDigit = (int)(lScratch & m_nBase64Mask[nNumBits]);
- nNumBits = nBits;
- if( nNumBits <=0 )
- break;
-
- strEncoded += g_szBase64TAB[ nDigit ];
- }
- // Pad with '=' as per RFC 1521
- while( strEncoded.GetLength() % 4 != 0 )
- strEncoded += '=';
- return strEncoded.GetLength();
- }
- // STATIC BASE64解码
- int Base64Decode(LPCTSTR lpszDecoding, CString &strDecoded)
- {
- int nIndex =0;
- int nDigit;
- int nDecode[ 256 ];
- int nSize;
- int nNumBits = 6;
- if( lpszDecoding == NULL )
- return 0;
-
- if( ( nSize = lstrlen(lpszDecoding) ) == 0 )
- return 0;
- // Build Decode Table
- for( int i = 0; i < 256; i++ )
- nDecode[i] = -2; // Illegal digit
- for( i=0; i < 64; i++ )
- {
- nDecode[ g_szBase64TAB[ i ] ] = i;
- nDecode[ '=' ] = -1;
- }
- // Clear the output buffer
- strDecoded = _T("");
- long lBitsStorage =0;
- int nBitsRemaining = 0;
- int nScratch = 0;
- UCHAR c;
-
- // Decode the Input
- for( nIndex = 0, i = 0; nIndex < nSize; nIndex++ )
- {
- c = lpszDecoding[ nIndex ];
- // 忽略所有不合法的字符
- if( c> 0x7F)
- continue;
- nDigit = nDecode[c];
- if( nDigit >= 0 )
- {
- lBitsStorage = (lBitsStorage << nNumBits) | (nDigit & 0x3F);
- nBitsRemaining += nNumBits;
- while( nBitsRemaining > 7 )
- {
- nScratch = lBitsStorage >> (nBitsRemaining - 8);
- strDecoded += (nScratch & 0xFF);
- i++;
- nBitsRemaining -= 8;
- }
- }
- }
- return strDecoded.GetLength();
- }
- //
- // 从URL里面拆分出Server、Object、协议类型等信息,其中 Object 里的值是区分大小写的,否则有些网站可能会下载不了
- //
- BOOL ParseURL(LPCTSTR lpszURL, CString &strServer, CString &strObject,USHORT& nPort, CString &csProtocolType)
- {
- if ( !lpszURL || strlen(lpszURL) < 1 ) return FALSE;
- CString csURL_Lower(lpszURL);
- csURL_Lower.TrimLeft();
- csURL_Lower.TrimRight();
- csURL_Lower.Replace ( "\", "/" );
- CString csURL = csURL_Lower;
- csURL_Lower.MakeLower ();
-
- // 清除数据
- strServer = _T("");
- strObject = _T("");
- nPort = 0;
- int nPos = csURL_Lower.Find("://");
- if( nPos == -1 )
- {
- csURL_Lower.Insert ( 0, "http://" );
- csURL.Insert ( 0, "http://" );
- nPos = 4;
- }
- csProtocolType = csURL_Lower.Left ( nPos );
- csURL_Lower = csURL_Lower.Mid( csProtocolType.GetLength()+3 );
- csURL = csURL.Mid( csProtocolType.GetLength()+3 );
- nPos = csURL_Lower.Find('/');
- if ( nPos == -1 )
- return FALSE;
- strObject = csURL.Mid(nPos);
- CString csServerAndPort = csURL_Lower.Left(nPos);
- // 查找是否有端口号,站点服务器域名一般用小写
- nPos = csServerAndPort.Find(":");
- if( nPos == -1 )
- {
- strServer = csServerAndPort;
- nPort = DEFAULT_HTTP_PORT;
- if ( csProtocolType == "ftp" )
- nPort = DEFAULT_FTP_PORT;
- }
- else
- {
- strServer = csServerAndPort.Left( nPos );
- csServerAndPort = csServerAndPort.Mid( nPos+1 );
- nPort = (USHORT)_ttoi((LPCTSTR)csServerAndPort);
- }
- return TRUE;
- }
- void CDownloadPub::Set_DownloadedSize(int nDownloadedSize)
- {
- m_CSFor_DownloadedSize.Lock ();
- m_nDownloadedSize = nDownloadedSize;
- m_CSFor_DownloadedSize.Unlock ();
- DownloadNotify ( m_nIndex, NOTIFY_TYPE_THREAD_DOWNLOADED_SIZE, (LPVOID)nDownloadedSize, m_pDownloadMTR );
- }
- int CDownloadPub::Get_DownloadedSize()
- {
- int nDownloadedSize = 0;
- m_CSFor_DownloadedSize.Lock ();
- nDownloadedSize = m_nDownloadedSize;
- m_CSFor_DownloadedSize.Unlock ();
- return nDownloadedSize;
- }
- void CDownloadPub::Set_TempSaveBytes(int nTempSaveBytes)
- {
- m_CSFor_TempSaveBytes.Lock ();
- m_nTempSaveBytes = nTempSaveBytes;
- m_CSFor_TempSaveBytes.Unlock ();
- }
- int CDownloadPub::Get_TempSaveBytes()
- {
- int nTempSaveBytes = 0;
- m_CSFor_TempSaveBytes.Lock ();
- nTempSaveBytes = m_nTempSaveBytes;
- m_CSFor_TempSaveBytes.Unlock ();
- return nTempSaveBytes;
- }
- void CDownloadPub::Set_WillDownloadSize(int nWillDownloadSize)
- {
- m_CSFor_WillDownloadSize.Lock ();
- m_nWillDownloadSize = nWillDownloadSize;
- m_CSFor_WillDownloadSize.Unlock ();
- DownloadNotify ( m_nIndex, NOTIFY_TYPE_WILL_DOWNLOAD_SIZE, (LPVOID)m_nWillDownloadSize, m_pDownloadMTR );
- }
- int CDownloadPub::Get_WillDownloadSize()
- {
- int nWillDownloadSize = 0;
- m_CSFor_WillDownloadSize.Lock ();
- nWillDownloadSize = m_nWillDownloadSize;
- m_CSFor_WillDownloadSize.Unlock ();
- return nWillDownloadSize;
- }
- BOOL CDownloadPub::SetSaveFileName(LPCTSTR lpszSaveFileName)
- {
- if ( !lpszSaveFileName ) return FALSE;
- m_csSaveFileName = lpszSaveFileName;
- if ( m_csSaveFileName.IsEmpty() )
- return FALSE;
- return TRUE;
- }
- //
- // 获取尚未下载的字节数,写到文件中的和临时缓冲里的都算是已经下载的
- //
- int CDownloadPub::GetUndownloadBytes()
- {
- // 总共需要下载的字节数减去已经下载的字节数
- return Get_WillDownloadSize () - ( Get_DownloadedSize () + Get_TempSaveBytes () );
- }
- BOOL CDownloadPub::OpenFileForSave()
- {
- ASSERT ( !m_csSaveFileName.IsEmpty() );
- // 打开本地文件
- if ( HANDLE_IS_VALID ( m_file.m_hFile ) )
- {
- m_file.Close ();
- }
- BOOL bRet = FALSE;
- TRY
- {
- if ( m_file.Open ( m_csSaveFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite|CFile::typeBinary|CFile::shareDenyNone ) )
- {
- int nWillDownloadStartPos = Get_WillDownloadStartPos ();
- nWillDownloadStartPos += Get_DownloadedSize ();
- if ( m_file.Seek ( nWillDownloadStartPos, CFile::begin ) == nWillDownloadStartPos )
- bRet = TRUE;
- }
- }
- CATCH( CFileException, e )
- {
- e->Delete ();
- bRet = FALSE;
- }
- END_CATCH
- if ( !bRet )
- {
- Log ( L_WARNING, "Open file [%s] failed. %s", m_csSaveFileName, ::hwFormatMessage ( GetLastError() ) );
- }
- return bRet;
- }
- void CDownloadPub::Clear_Thread_Handle()
- {
- CLOSE_HANDLE ( m_hThread );
- }
- // 消息通知的回调函数
- FUNC_DownloadNotify f_Proc_DownloadNotify = NULL;
- WPARAM f_wDownloadNotify_Param = NULL;
- //
- // 设置通知回调函数
- //
- void Set_DownloadNotify_Callback ( FUNC_DownloadNotify Proc_DownloadNotify, WPARAM wParam )
- {
- f_Proc_DownloadNotify = Proc_DownloadNotify;
- f_wDownloadNotify_Param = wParam;
- }
- void DownloadNotify ( int nIndex, UINT nNotityType, LPVOID lpNotifyData, LPVOID pDownloadMTR )
- {
- ASSERT ( pDownloadMTR );
- t_DownloadNotifyPara DownloadNotifyPara = {0};
- DownloadNotifyPara.nIndex = nIndex;
- DownloadNotifyPara.nNotityType = nNotityType;
- DownloadNotifyPara.lpNotifyData = lpNotifyData;
- DownloadNotifyPara.pDownloadMTR = pDownloadMTR;
- if ( f_Proc_DownloadNotify )
- f_Proc_DownloadNotify ( &DownloadNotifyPara, f_wDownloadNotify_Param );
- }
- //
- // 获取下载对象的文件名(带扩展名的)
- //
- CString CDownloadPub::GetDownloadObjectFileName(CString *pcsExtensionName)
- {
- ASSERT ( !m_csObject.IsEmpty() );
- CString csOnlyPath, csOnlyFileName, csExtensionName;
- if ( !PartPathAndFileAndExtensionName ( m_csObject, &csOnlyPath, &csOnlyFileName, &csExtensionName ) )
- return "";
- if ( pcsExtensionName ) *pcsExtensionName = csExtensionName;
- if ( !csExtensionName.IsEmpty() )
- {
- csOnlyFileName += ".";
- csOnlyFileName += csExtensionName;
- }
- return csOnlyFileName;
- }