本文整理汇总了C++中CBuffer::EnsureBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ CBuffer::EnsureBuffer方法的具体用法?C++ CBuffer::EnsureBuffer怎么用?C++ CBuffer::EnsureBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBuffer
的用法示例。
在下文中一共展示了CBuffer::EnsureBuffer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CBuffer
CBuffer* CZIPFile::File::Decompress()
{
z_stream pStream;
if ( m_nSize > 32*1024*1024 ) return NULL;
if ( ! PrepareToDecompress( &pStream ) ) return NULL;
if ( m_nCompression == 0 )
{
CBuffer* pTarget = new CBuffer();
pTarget->EnsureBuffer( (DWORD)m_nSize );
ReadFile( m_pZIP->m_hFile, pTarget->m_pBuffer, (DWORD)m_nSize, &pTarget->m_nLength, NULL );
if ( pTarget->m_nLength == (DWORD)m_nSize ) return pTarget;
delete pTarget;
return NULL;
}
DWORD nSource = (DWORD)m_nCompressedSize;
BYTE* pSource = new BYTE[ nSource ];
ReadFile( m_pZIP->m_hFile, pSource, nSource, &nSource, NULL );
if ( nSource != (DWORD)m_nCompressedSize )
{
inflateEnd( &pStream );
return NULL;
}
CBuffer* pTarget = new CBuffer();
pTarget->EnsureBuffer( (DWORD)m_nSize );
pTarget->m_nLength = (DWORD)m_nSize;
pStream.next_in = pSource;
pStream.avail_in = (DWORD)m_nCompressedSize;
pStream.next_out = pTarget->m_pBuffer;
pStream.avail_out = pTarget->m_nLength;
inflate( &pStream, Z_FINISH );
delete [] pSource;
if ( pStream.avail_out != 0 )
{
delete pTarget;
pTarget = NULL;
}
inflateEnd( &pStream );
return pTarget;
}
示例2: LoadDC
BOOL CHostBrowser::LoadDC(LPCTSTR pszFile, CQueryHit*& pHits)
{
CFile pFile;
if ( ! pFile.Open( pszFile, CFile::modeRead | CFile::shareDenyWrite ) )
return FALSE; // File open error
UINT nInSize = (UINT)pFile.GetLength();
if ( ! nInSize )
return FALSE; // Empty file
CBuffer pBuffer;
if ( ! pBuffer.EnsureBuffer( nInSize ) )
return FALSE; // Out of memory
if ( pFile.Read( pBuffer.GetData(), nInSize ) != nInSize )
return FALSE; // File read error
pBuffer.m_nLength = nInSize;
if ( ! pBuffer.UnBZip() )
return FALSE; // Decompression error
augment::auto_ptr< CXMLElement > pXML ( CXMLElement::FromString( pBuffer.ReadString( pBuffer.m_nLength, CP_UTF8 ), TRUE ) );
if ( ! pXML.get() )
return FALSE; // XML decoding error
// <FileListing Version="1" CID="SKCB4ZF4PZUDF7RKQ5LX6SVAARQER7QEVELZ2TY" Base="/" Generator="DC++ 0.762">
if ( ! pXML->IsNamed( L"FileListing" ) )
return FALSE; // Invalid XML file format
// CString strTitle = pXML->GetAttributeValue( L"CID" );
return LoadDCDirectory( pXML.get(), pHits );
}
示例3: Import
BOOL CSecurity::Import(LPCTSTR pszFile)
{
CString strText;
CBuffer pBuffer;
CFile pFile;
if ( ! pFile.Open( pszFile, CFile::modeRead ) ) return FALSE;
pBuffer.EnsureBuffer( (DWORD)pFile.GetLength() );
pBuffer.m_nLength = (DWORD)pFile.GetLength();
pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength );
pFile.Close();
CXMLElement* pXML = CXMLElement::FromBytes( pBuffer.m_pBuffer, pBuffer.m_nLength, TRUE );
BOOL bResult = FALSE;
if ( pXML != NULL )
{
bResult = FromXML( pXML );
delete pXML;
}
else
{
CString strLine;
while ( pBuffer.ReadLine( strLine ) )
{
strLine.Trim();
if ( strLine.IsEmpty() ) continue;
if ( strLine.GetAt( 0 ) == ';' ) continue;
CSecureRule* pRule = new CSecureRule();
if ( pRule->FromGnucleusString( strLine ) )
{
CQuickLock oLock( m_pSection );
m_pRules.AddTail( pRule );
bResult = TRUE;
}
else
{
delete pRule;
}
}
}
// Check all lists for newly denied hosts
PostMainWndMessage( WM_SANITY_CHECK );
return bResult;
}
示例4: LoadDC
BOOL CCollectionFile::LoadDC(LPCTSTR pszFile)
{
m_nType = SimpleCollection;
// ToDo: Add schema detection
m_sThisURI = CSchema::uriFolder;
m_sParentURI = CSchema::uriCollectionsFolder;
CFile pFile;
if ( ! pFile.Open( pszFile, CFile::modeRead | CFile::shareDenyWrite ) )
return FALSE; // File open error
UINT nInSize = (UINT)pFile.GetLength();
if ( ! nInSize )
return FALSE; // Empty file
CBuffer pBuffer;
if ( ! pBuffer.EnsureBuffer( nInSize ) )
return FALSE; // Out of memory
if ( pFile.Read( pBuffer.GetData(), nInSize ) != nInSize )
return FALSE; // File read error
pBuffer.m_nLength = nInSize;
if ( ! pBuffer.UnBZip() )
return FALSE; // Decompression error
augment::auto_ptr< CXMLElement > pXML ( CXMLElement::FromString( pBuffer.ReadString( pBuffer.m_nLength, CP_UTF8 ), TRUE ) );
if ( ! pXML.get() )
return FALSE; // XML decoding error
// <FileListing Version="1" CID="SKCB4ZF4PZUDF7RKQ5LX6SVAARQER7QEVELZ2TY" Base="/" Generator="DC++ 0.762">
if ( ! pXML->IsNamed( L"FileListing" ) )
return FALSE; // Invalid XML file format
m_sTitle = pXML->GetAttributeValue( L"CID" );
LoadDC( pXML.get() );
return ( m_pFiles.GetCount() != 0 );
}
示例5: min
BOOL CUploadTransferED2K::DispatchNextChunk()
{
ASSERT( m_nState == upsUploading );
if ( !m_pDiskFile ) return FALSE;
ASSERT( m_nLength < SIZE_UNKNOWN );
ASSERT( m_nPosition < m_nLength );
QWORD nChunk = m_nLength - m_nPosition;
nChunk = min( nChunk, QWORD(Settings.eDonkey.FrameSize) );
#if 0
// Use packet form
CEDPacket* pPacket = CEDPacket::New( ED2K_C2C_SENDINGPART );
pPacket->Write( &m_pED2K, sizeof(MD4) );
pPacket->WriteLongLE( m_nOffset + m_nPosition );
pPacket->WriteLongLE( m_nOffset + m_nPosition + nChunk );
m_pDiskFile->Read( m_nFileBase + m_nOffset + m_nPosition, pPacket->GetWritePointer( nChunk ), nChunk, &nChunk );
// SetFilePointer( hFile, m_nFileBase + m_nOffset + m_nPosition, NULL, FILE_BEGIN );
// ReadFile( hFile, pPacket->WriteGetPointer( nChunk ), nChunk, &nChunk, NULL );
if ( nChunk == 0 )
{
pPacket->Release();
return FALSE;
}
pPacket->m_nLength = sizeof(MD4) + 8 + nChunk;
Send( pPacket );
#else
// Raw write
CBuffer* pBuffer = m_pClient->m_pOutput;
pBuffer->EnsureBuffer( sizeof(ED2K_PART_HEADER) + (DWORD)nChunk );
ED2K_PART_HEADER* pHeader = (ED2K_PART_HEADER*)( pBuffer->m_pBuffer + pBuffer->m_nLength );
if ( ! m_pDiskFile->Read( m_nFileBase + m_nOffset + m_nPosition, &pHeader[1], nChunk, &nChunk ) ) return FALSE;
// SetFilePointer( hFile, m_nFileBase + m_nOffset + m_nPosition, NULL, FILE_BEGIN );
// ReadFile( hFile, &pHeader[1], nChunk, &nChunk, NULL );
if ( nChunk == 0 ) return FALSE;
pHeader->nProtocol = ED2K_PROTOCOL_EDONKEY;
pHeader->nType = ED2K_C2C_SENDINGPART;
pHeader->nLength = 1 + sizeof(MD4) + 8 + (DWORD)nChunk;
pHeader->pMD4 = m_pED2K;
pHeader->nOffset1 = (DWORD)( m_nOffset + m_nPosition );
pHeader->nOffset2 = (DWORD)( m_nOffset + m_nPosition + nChunk );
pBuffer->m_nLength += sizeof(ED2K_PART_HEADER) + (DWORD)nChunk;
m_pClient->Send( NULL );
#endif
m_nPosition += nChunk;
m_nUploaded += nChunk;
Statistics.Current.Uploads.Volume += ( nChunk / 1024 );
return TRUE;
}
示例6: Ungzip
// If the contents of this buffer are between headers and compressed with gzip, this method can remove all that
// Returns false on error
BOOL CBuffer::Ungzip()
{
// Make sure there are at least 10 bytes in this buffer
if ( m_nLength < 10 ) return FALSE;
// Make sure the first 3 bytes are not 1f8b08
if ( m_pBuffer[0] != 0x1F || m_pBuffer[1] != 0x8B || m_pBuffer[2] != 8 ) return FALSE;
// At a distance of 3 bytes into the buffer, read the byte there and call it nFlags
BYTE nFlags = m_pBuffer[3];
// Remove the first 10 bytes of the buffer
Remove( 10 );
// If there is a 1 in position 0000 0100 in the flags byte
if ( nFlags & 0x04 )
{
// Make sure the buffer has 2 or more bytes
if ( m_nLength < 2 ) return FALSE;
// Look at the first 2 bytes in the buffer as a word, this says how long the data it beyond it
WORD nLen = *(WORD*)m_pBuffer;
// If the buffer has less data than it should, return false
if ( (int)m_nLength < (int)nLen + 2 ) return FALSE;
// Remove the length word and the length it describes from the front of the buffer
Remove( 2 + nLen );
}
// If there is a 1 in position 0000 1000 in the flags byte
if ( nFlags & 0x08 )
{
// Loop until after we remove a 0 byte from the buffer
for ( ;; )
{
// If the buffer is empty, return false
if ( m_nLength == 0 ) return FALSE;
// Move the first byte of the buffer into an int
int nChar = m_pBuffer[0]; // Copy one byte from the start of the buffer into an int named nChar
Remove( 1 ); // Remove that first byte from the buffer
// If we just removed a 0 byte, exit the loop
if ( nChar == 0 ) break;
}
}
// If there is a 1 in position 0001 0000 in the flags byte
if ( nFlags & 0x10 )
{
// Loop until after we remove a 0 byte from the buffer
for ( ;; )
{
// If the buffer is empty, return false
if ( m_nLength == 0 ) return FALSE;
// Move the first byte of the buffer into an int
int nChar = m_pBuffer[0]; // Copy one byte from the start of the buffer into an int named nChar
Remove( 1 ); // Remove that first byte from the buffer
// If we just removed a 0 byte, exit the loop
if ( nChar == 0 ) break;
}
}
// If there is a 1 in position 0000 0010 in the flags byte
if ( nFlags & 0x02 )
{
// Make sure the buffer has at least 2 bytes, and then remove them
if ( m_nLength < 2 ) return FALSE;
Remove( 2 );
}
// After removing all that header information from the front, remove the last 8 bytes from the end
if ( m_nLength <= 8 ) return FALSE; // Make sure the buffer has more than 8 bytes
m_nLength -= 8; // Remove the last 8 bytes in the buffer
// Setup a z_stream structure to perform a raw inflate
z_stream pStream;
ZeroMemory( &pStream, sizeof(pStream) );
if ( Z_OK != inflateInit2( // Initialize a stream inflation with more options than just inflateInit
&pStream, // Stream structure to initialize
-MAX_WBITS ) ) { // Window bits value of -15 to perform a raw inflate
// The Zlib function inflateInit2 returned something other than Z_OK, report error
return FALSE;
}
// Make a new buffer for the output
CBuffer pOutput;
pOutput.EnsureBuffer( m_nLength * 6 ); // Guess that inflating the data won't make it more than 6 times as big
// Tell the z_stream structure where to work
pStream.next_in = m_pBuffer; // Decompress the memory here
pStream.avail_in = m_nLength; // There is this much of it
pStream.next_out = pOutput.m_pBuffer; // Write decompressed data here
pStream.avail_out = pOutput.m_nBuffer; // Tell ZLib it has this much space, it make this smaller to show how much space is left
//.........这里部分代码省略.........
示例7: LoadDefaultInterests
int CProfileProfilePage::LoadDefaultInterests()
{
int nCount = 0;
const CString strFile = Settings.General.Path + _T("\\Data\\Interests.dat"); // Settings.General.DataPath ?
CFile pFile;
if ( ! pFile.Open( strFile, CFile::modeRead ) )
return nCount;
try
{
CString strLine;
CString strLang = _T(" ") + Settings.General.Language;
CBuffer pBuffer;
pBuffer.EnsureBuffer( (DWORD)pFile.GetLength() );
pBuffer.m_nLength = (DWORD)pFile.GetLength();
pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength );
pFile.Close();
// Format: Delineated List, enabled by prespecified #languages: #start en ... #end en
// (Allows multiple/nested/overlapped languages, all applicable results displayed alphabetically)
BOOL bActive = FALSE;
while ( pBuffer.ReadLine( strLine ) )
{
if ( strLine.GetLength() < 2 ) continue; // Blank line
if ( strLine.GetAt( 0 ) == '#' ) // Language start/end line
{
if ( strLine.Find( strLang, 4 ) < 1 && strLine.Find( _T(" all"), 4 ) < 1 )
{
if ( strLine.Left( 10 ) == _T("#languages") )
strLang = _T(" en");
}
else if ( strLine.Left( 6 ) == _T("#start") || strLine.Left( 6 ) == _T("#begin") )
bActive = TRUE;
else if ( strLine.Left( 4 ) == _T("#end") )
bActive = FALSE; //break;
continue;
}
if ( ! bActive ) continue; // Disinterested language
if ( strLine.Find( _T("\t") ) > 0 ) // Trim at whitespace (remove any comments)
strLine.Left( strLine.Find( _T("\t") ) );
nCount++;
m_wndInterestAll.AddString( strLine );
}
}
catch ( CException* pException )
{
if ( pFile.m_hFile != CFile::hFileNull )
pFile.Close(); // File is still open so close it
pException->Delete();
}
return nCount;
}
示例8: OnRun
void CListLoader::OnRun()
{
while ( IsThreadEnabled() && m_pQueue.GetCount() )
{
CSecureRule* pRule = m_pQueue.GetHead();
if ( ! pRule || ! pRule->m_pContent || pRule->m_nType != CSecureRule::srExternal )
{
m_pQueue.RemoveHead();
continue;
}
CString strPath = pRule->GetContentWords();
if ( strPath.GetLength() < 6 )
{
m_pQueue.RemoveHead();
continue;
}
CString strCommentBase = pRule->m_sComment;
if ( strCommentBase.IsEmpty() )
strCommentBase = _T("• %u");
else if ( strCommentBase.ReverseFind( _T('•') ) >= 0 )
strCommentBase = strCommentBase.Left( strCommentBase.ReverseFind( _T('•') ) + 1 ) + _T(" %u");
else
strCommentBase += _T(" • %u");
if ( strPath[1] != _T(':') )
strPath = Settings.General.DataPath + strPath;
CFile pFile;
if ( ! pFile.Open( (LPCTSTR)strPath.GetBuffer(), CFile::modeRead ) )
{
m_pQueue.RemoveHead();
continue;
}
const BYTE nIndex = Security.SetRuleIndex( pRule );
try
{
CBuffer pBuffer;
const DWORD nLength = pFile.GetLength();
pBuffer.EnsureBuffer( nLength );
pBuffer.m_nLength = nLength;
pFile.Read( pBuffer.m_pBuffer, nLength );
pFile.Close();
// Format: Delineated Lists
CString strLine, strURN;
DWORD nCount = 0;
int nPos;
//TIMER_START
while ( pBuffer.ReadLine( strLine ) && IsThreadEnabled() && pRule )
{
strLine.TrimRight();
if ( strLine.GetLength() < 7 )
continue; // Blank/Invalid line
if ( strLine[ 0 ] == '#' )
{
if ( strLine[ strLine.GetLength() - 1 ] == _T(':') && strLine.Find( _T("urn:") ) > 0 )
strURN = strLine.Mid( strLine.Find( _T("urn:") ) ); // Default "# urn:type:"
continue; // Comment line
}
if ( strLine[ 0 ] < '0' || strLine[ 0 ] > 'z' ) // Whitespace/Chars
continue; // Invalid line
if ( ++nCount % 10 == 0 )
{
if ( pRule->m_sComment.IsEmpty() )
strCommentBase = _T("• %u");
else if ( pRule->m_sComment.ReverseFind( _T('•') ) < 0 )
strCommentBase = pRule->m_sComment + _T(" • %u");
pRule->m_sComment.Format( strCommentBase, nCount );
Sleep( 1 ); // Limit CPU
}
// Hashes:
if ( ( ! strURN.IsEmpty() && strLine.Find( _T('.'), 5 ) < 0 ) || StartsWith( strLine, _PT("urn:") ) )
{
nPos = strLine.FindOneOf( _T(" \t") );
if ( nPos > 0 )
strLine.Truncate( nPos ); // Trim at whitespace (remove any trailing comments)
if ( ! strURN.IsEmpty() && ! StartsWith( strLine, _PT("urn:") ) )
strLine = strURN + strLine; // Default "urn:type:" prepended
if ( strLine.GetLength() > 35 )
Security.SetHashMap( strLine, nIndex );
else
nCount--;
continue;
}
// IPs:
//.........这里部分代码省略.........
示例9: Load
void CMessageFilter::Load()
{
CFile pFile;
CString strFilteredPhrases, strED2KSpamPhrases;
const CString strFile = Settings.General.Path + _T("\\Data\\MessageFilter.dat");
// Delete current filter (if present)
if ( m_pszFilteredPhrases ) delete [] m_pszFilteredPhrases;
m_pszFilteredPhrases = NULL;
// Load the message filter from disk
if ( pFile.Open( strFile, CFile::modeRead ) )
{
try
{
CBuffer pBuffer;
DWORD nLen = (DWORD)pFile.GetLength();
if ( ! pBuffer.EnsureBuffer( nLen ) )
AfxThrowUserException();
pBuffer.m_nLength = nLen;
pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength );
pFile.Close();
pBuffer.ReadLine( strED2KSpamPhrases );
pBuffer.ReadLine( strFilteredPhrases );
}
catch ( CException* pException )
{
if ( pFile.m_hFile != CFile::hFileNull )
pFile.Close(); // If file is still open close it
pException->Delete();
}
}
// Insert some defaults if there was a read error
if ( strED2KSpamPhrases.IsEmpty() )
strED2KSpamPhrases = _T("Your client is connecting too fast|Join the L33cher Team|PeerFactor|Your client is making too many connections|ZamBoR 2|AUTOMATED MESSAGE:|eMule FX the BEST eMule ever|DI-Emule");
if ( strFilteredPhrases.IsEmpty() )
strFilteredPhrases = _T("");
// Load the ED2K spam into the filter
if ( strED2KSpamPhrases.GetLength() > 3 )
{
LPCTSTR pszPtr = strED2KSpamPhrases;
int nWordLen = 3;
CList< CString > pWords;
int nStart = 0, nPos = 0;
for ( ; *pszPtr ; nPos++, pszPtr++ )
{
if ( *pszPtr == '|' )
{
if ( nStart < nPos )
{
pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) );
nWordLen += ( nPos - nStart ) + 1;
}
nStart = nPos + 1;
}
}
if ( nStart < nPos )
{
pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) );
nWordLen += ( nPos - nStart ) + 1;
}
m_pszED2KSpam = new TCHAR[ nWordLen ];
LPTSTR pszFilter = m_pszED2KSpam;
for ( POSITION pos = pWords.GetHeadPosition() ; pos ; )
{
CString strWord( pWords.GetNext( pos ) );
ToLower( strWord );
CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) );
pszFilter += strWord.GetLength() + 1;
}
*pszFilter++ = 0;
*pszFilter++ = 0;
}
// Load the blocked strings into the filter
if ( strFilteredPhrases.GetLength() > 3 )
{
LPCTSTR pszPtr = strFilteredPhrases;
int nWordLen = 3;
CList< CString > pWords;
int nStart = 0, nPos = 0;
for ( ; *pszPtr ; nPos++, pszPtr++ )
{
if ( *pszPtr == '|' )
{
if ( nStart < nPos )
{
//.........这里部分代码省略.........