本文整理汇总了C++中CAtlFile::Seek方法的典型用法代码示例。如果您正苦于以下问题:C++ CAtlFile::Seek方法的具体用法?C++ CAtlFile::Seek怎么用?C++ CAtlFile::Seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAtlFile
的用法示例。
在下文中一共展示了CAtlFile::Seek方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UrlUnescapeInPlace
//.........这里部分代码省略.........
CAtlFile OutFile;
if (pData->m_pUrlInfo->m_dwDownloadFlags & HTTP_FLAG_NO_RESUME)
DeleteFile(pData->m_pUrlInfo->m_DownloadFile);
hr = OutFile.Create(pData->m_pUrlInfo->m_DownloadFile, GENERIC_WRITE, 0, OPEN_ALWAYS);
if (FAILED(hr))
{
_DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: CreateFile failed: 0x%x, %d : %s\n", hr, GetLastError(), pData->m_pUrlInfo->m_DownloadFile);
return E_HTTP_WRITE_FILE;
}
size_type llTotalRead = 0;
size_type llSizeMax = 0;
size_type ContentLen = FConn.GetContentLength();
pData->m_pUrlInfo->m_ContentLength = ContentLen;
if (dwStatusCode == 206)
{
FString FStrRange = FConn.GetHeader(HTTP_QUERY_CONTENT_RANGE);
if (FStrRange)
{
//Content-Range: bytes 21010-47021/47022
const char* pszBytes = strstr(FStrRange, "bytes ");
if (pszBytes != NULL)
{
pszBytes+=sizeof("bytes");
LONGLONG llOffset = _strtoi64(pszBytes, NULL, 10);
hr = OutFile.Seek(llOffset, FILE_BEGIN);
llTotalRead = (size_type)llOffset;
if (FAILED(hr))
{
_DBGAlert("**FAsyncDownload::FHttpDownloadTP::ProcessDownload: Seek to position %d failed: 0x%x, %d\n", hr, GetLastError());
}
const char* pszTotal = strchr(pszBytes, '/');
if (pszTotal != NULL)
llSizeMax = _strtoi64(pszTotal + 1, NULL, 10);
}
}
}
else
{
if (ContentLen > 0 && ContentLen == FileSize)
{
OutFile.Close();
return S_OK;
}
}
if (llSizeMax == 0)
llSizeMax = ContentLen;
pData->pBindStatusCallback.OnProgress((ULONG)llTotalRead, (ULONG)llSizeMax, BINDSTATUS_BEGINDOWNLOADDATA, L"");
DWORD dwBytesRead = 0;
for (;;)
{
if (!InternetReadFile(hReq, pBuffer, dwBufferSize, &dwBytesRead))
{
示例2: RunMergeFile
//.........这里部分代码省略.........
bFound = TRUE; // Avoid fallback check below
break;
}
nOffset += pFile->m_nSize;
}
}
if ( ! bFound ) // No filename match, try exact size
{
nOffset = 0;
// const CString strExt = PathFindExtension( strSourceName );
for ( POSITION pos = pDownload->m_pTorrent.m_pFiles.GetHeadPosition() ; pos ; )
{
pFile = pDownload->m_pTorrent.m_pFiles.GetNext( pos );
if ( pFile->m_nSize == nSourceSize ) // && strExt == PathFindExtension( pFile->m_sPath )
{
DEBUG_ONLY( theApp.Message( MSG_DEBUG, _T("Merge Filesize Fallback") ) );
nSourceOffset = nOffset;
// bFound = TRUE;
break;
}
nOffset += pFile->m_nSize;
}
}
}
pLock.Unlock();
const float fIncrement = fProgress / oList.size();
const DWORD nBufferLength = 256 * 1024; // Was 65536?
// Read missing file fragments from selected file
auto_array< BYTE > Buf( new BYTE [nBufferLength] );
Fragments::List::const_iterator pItr = oList.begin();
const Fragments::List::const_iterator pEnd = oList.end();
for ( ; ! m_pEvent && pItr != pEnd ; ++pItr )
{
m_fProgress += fIncrement; // Update tooltip
QWORD qwLength = pItr->end() - pItr->begin();
QWORD qwOffset = pItr->begin();
// Check for overlapped fragments
if ( qwOffset + qwLength <= nSourceOffset ||
nSourceOffset + nSourceSize <= qwOffset )
continue; // No overlaps
// Calculate overlapped range end offset
QWORD qwEnd = min( qwOffset + qwLength, nSourceOffset + nSourceSize );
// Calculate overlapped range start offset
qwOffset = max( qwOffset, nSourceOffset );
// Calculate overlapped range length
qwLength = qwEnd - qwOffset;
// Calculate file offset if any
QWORD qwFileOffset = ( qwOffset > nSourceOffset ) ? qwOffset - nSourceOffset : 0;
if ( FAILED( oSource.Seek( qwFileOffset, FILE_BEGIN ) ) )
continue;
DWORD dwToRead;
while ( ( dwToRead = (DWORD)min( qwLength, (QWORD)nBufferLength ) ) != 0 && ! m_pEvent )
{
DWORD dwReaded = 0;
if ( SUCCEEDED( oSource.Read( Buf.get(), dwToRead, dwReaded ) ) && dwReaded )
{
pLock.Lock();
if ( ! Downloads.Check( pDownload ) || pDownload->IsCompleted() || pDownload->IsMoving() )
return;
pDownload->SubmitData( qwOffset, Buf.get(), (QWORD)dwReaded );
pLock.Unlock();
qwOffset += (QWORD)dwReaded;
qwLength -= (QWORD)dwReaded;
}
else
{
// File error or end of file. Non-Fatal
break;
}
}
pLock.Lock();
if ( ! Downloads.Check( pDownload ) || pDownload->IsCompleted() || pDownload->IsMoving() )
return;
if ( bMergeValidation )
pDownload->RunValidation();
pDownload->SetModified();
pLock.Unlock();
}
// m_bSuccess = true;
}
示例3: GetProperties
bool CTrueType::GetProperties(LPCTSTR pszFilePath, TTF_PROPERTIES* pProperties)
{
CAtlFile FontFile;
HRESULT hr = FontFile.Create(pszFilePath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);
if (FAILED(hr))
return false;
TTF_OFFSET_TABLE ttOffsetTable;
FontFile.Read(&ttOffsetTable, sizeof(TTF_OFFSET_TABLE));
ttOffsetTable.uNumOfTables = SWAPWORD(ttOffsetTable.uNumOfTables);
ttOffsetTable.uMajorVersion = SWAPWORD(ttOffsetTable.uMajorVersion);
ttOffsetTable.uMinorVersion = SWAPWORD(ttOffsetTable.uMinorVersion);
// See if this is a true type font and the version is 1.0
if (ttOffsetTable.uMajorVersion != 1 || ttOffsetTable.uMinorVersion != 0)
return false;
TTF_TABLE_DIRECTORY tblDir;
TTF_TABLE_DIRECTORY tblName;
TTF_TABLE_DIRECTORY tblOS2;
bool bFoundNameTable = false;
bool bFoundOS2Table = false;
for (int i=0; i< ttOffsetTable.uNumOfTables; i++)
{
FontFile.Read(&tblDir, sizeof(TTF_TABLE_DIRECTORY));
CString strName = CString(tblDir.szTag, 4);
if (strName.IsEmpty())
break;
if (!strName.CompareNoCase("name"))
{
bFoundNameTable = true;
tblName = tblDir;
tblName.uLength = SWAPLONG(tblName.uLength);
tblName.uOffset = SWAPLONG(tblName.uOffset);
}
else
if (!strName.CompareNoCase("OS/2"))
{
bFoundOS2Table = true;
tblOS2 = tblDir;
tblOS2.uLength = SWAPLONG(tblOS2.uLength);
tblOS2.uOffset = SWAPLONG(tblOS2.uOffset);
}
if (bFoundNameTable && bFoundOS2Table)
break;
}
if (bFoundNameTable)
{
FontFile.Seek(tblName.uOffset, FILE_BEGIN);
TTF_NAME_TABLE_HEADER ttNTHeader;
FontFile.Read(&ttNTHeader, sizeof(TTF_NAME_TABLE_HEADER));
ttNTHeader.uFSelector = SWAPWORD(ttNTHeader.uFSelector);
ttNTHeader.uNRCount = SWAPWORD(ttNTHeader.uNRCount);
ttNTHeader.uStorageOffset = SWAPWORD(ttNTHeader.uStorageOffset);
for (int i=0; i<ttNTHeader.uNRCount; i++)
{
TTF_NAME_RECORD ttRecord;
FontFile.Read(&ttRecord, sizeof(TTF_NAME_RECORD));
ttRecord.uPlatformID = SWAPWORD(ttRecord.uPlatformID);
ttRecord.uEncodingID = SWAPWORD(ttRecord.uEncodingID);
ttRecord.uLanguageID = SWAPWORD(ttRecord.uLanguageID);
ttRecord.uNameID = SWAPWORD(ttRecord.uNameID);
ttRecord.uStringLength = SWAPWORD(ttRecord.uStringLength);
ttRecord.uStringOffset = SWAPWORD(ttRecord.uStringOffset);
if (ttRecord.uPlatformID != 3) // Microsoft
continue;
ULONGLONG nPos = 0;
FontFile.GetPosition(nPos);
FontFile.Seek(tblName.uOffset + ttRecord.uStringOffset + ttNTHeader.uStorageOffset, FILE_BEGIN);
int iUnicodeChars = (ttRecord.uStringLength + 1) / 2;
WCHAR* pUnicodeBuffer = new WCHAR[iUnicodeChars];
FontFile.Read(pUnicodeBuffer, ttRecord.uStringLength);
for (int i = 0; i < iUnicodeChars; i++)
pUnicodeBuffer[i] = SWAPWORD(pUnicodeBuffer[i]);
CString strName = CString(pUnicodeBuffer, iUnicodeChars);
delete [] pUnicodeBuffer;
FontFile.Seek(nPos, FILE_BEGIN);
if (strName.IsEmpty())
continue;
switch (ttRecord.uNameID)
{
case 1: // Font family
pProperties->strFamily.IsEmpty() ? pProperties->strFamily = strName : void();
break;
case 0: // Copyright notice
pProperties->strCopyright.IsEmpty() ? pProperties->strCopyright = strName : void();
break;
case 7: // Trademark notice
pProperties->strTrademark.IsEmpty() ? pProperties->strTrademark = strName : void();
//.........这里部分代码省略.........