You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.1 KiB
163 lines
4.1 KiB
/*++
|
|
|
|
Copyright (c) Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
pcmWriterStream.cpp
|
|
|
|
Abstract:
|
|
implementation of a filestream for Precompiled manifest writer
|
|
|
|
Author:
|
|
|
|
Xiaoyu Wu (xiaoyuw) June 2000
|
|
|
|
Revision History:
|
|
|
|
--*/
|
|
|
|
#include "stdinc.h"
|
|
#include "pcm.h"
|
|
#include "pcmwriterstream.h"
|
|
|
|
// NTRAID#NTBUG9 - 587991 - 2002/03/26 - xiaoyuw:
|
|
// (1) currently not in the build
|
|
// (2) no fusion tracing macros used
|
|
//
|
|
|
|
HRESULT CPrecompiledManifestWriterStream::WriteWithDelay(void const *pv, ULONG cb, ULONG *pcbWritten)
|
|
{
|
|
HRESULT hr=NOERROR;
|
|
|
|
if (pcbWritten)
|
|
*pcbWritten = 0 ;
|
|
|
|
if (m_fBuffer)
|
|
{
|
|
if (FAILED(hr = m_buffer.Append(reinterpret_cast<const BYTE*>(pv), cb)))
|
|
goto Exit;
|
|
if ( pcbWritten)
|
|
*pcbWritten = cb;
|
|
}
|
|
else
|
|
{
|
|
DWORD dwBytesWritten = 0;
|
|
|
|
ASSERT(m_hFile != INVALID_HANDLE_VALUE);
|
|
|
|
BOOL fSuccess = (cb == 0) || WriteFile(m_hFile, pv, cb, &dwBytesWritten, NULL);
|
|
if (!fSuccess)
|
|
// NTRAID#NTBUG9 - 587991 - 2002/03/26 - xiaoyuw:
|
|
// in the case of (cb ==0), no LastError is set, and hr would be S_OK;
|
|
hr = ::FusionpHresultFromLastError();
|
|
else if (dwBytesWritten != cb)
|
|
hr = E_FAIL;
|
|
if ( pcbWritten)
|
|
*pcbWritten = dwBytesWritten;
|
|
}
|
|
|
|
// NTRAID#NTBUG9 - 587991 - 2002/03/26 - xiaoyuw:
|
|
// NOERROR would overwrite all hr error code ever set.
|
|
hr = NOERROR;
|
|
Exit:
|
|
return hr;
|
|
|
|
}
|
|
|
|
BOOL
|
|
CPrecompiledManifestWriterStream::SetSink(
|
|
const CBaseStringBuffer &rbuff,
|
|
DWORD openOrCreate
|
|
)
|
|
{
|
|
BOOL fSuccess = FALSE;
|
|
DWORD dwBytesWritten = 0;
|
|
DWORD dwBufferSize = 0;
|
|
|
|
//
|
|
// NTRAID#NTBUG9-164736-2000/8/17-a-JayK,JayKrell share should be 0
|
|
//
|
|
if (!Base::OpenForWrite(rbuff, FILE_SHARE_WRITE, openOrCreate))
|
|
goto Exit;
|
|
|
|
dwBufferSize = static_cast<DWORD>(m_buffer.GetCurrentCb());
|
|
fSuccess = TRUE;
|
|
if (dwBufferSize > 0){
|
|
// NTRAID#NTBUG9 - 587991 - 2002/03/26 - xiaoyuw:
|
|
// change assert to INTERNAL_ERROR_CHECK
|
|
ASSERT ( m_hFile != INVALID_HANDLE_VALUE );
|
|
fSuccess = WriteFile(m_hFile, m_buffer, dwBufferSize, &dwBytesWritten, NULL/*overlapped*/);
|
|
|
|
if (fSuccess && dwBytesWritten != dwBufferSize){
|
|
::FusionpSetLastWin32Error(ERROR_WRITE_FAULT);
|
|
fSuccess = FALSE;
|
|
}
|
|
}
|
|
m_fBuffer = FALSE;
|
|
|
|
Exit:
|
|
if (!fSuccess){
|
|
// NTRAID#NTBUG9 - 587991 - 2002/03/26 - xiaoyuw:
|
|
// CSxsPreserveLastError should be used here to make the code cleaner.
|
|
//
|
|
DWORD dwLastError = ::FusionpGetLastWin32Error();
|
|
m_buffer.Clear(true);
|
|
::FusionpSetLastWin32Error(dwLastError);
|
|
}
|
|
else
|
|
m_buffer.Clear(true);
|
|
|
|
return fSuccess;
|
|
}
|
|
|
|
//besides close, rewrite MaxNodeCount, RecordCount into the header of the file
|
|
HRESULT CPrecompiledManifestWriterStream::Close(ULONG ulRecordCount, DWORD dwMaxNodeCount)
|
|
{
|
|
HRESULT hr = NOERROR;
|
|
LARGE_INTEGER liMove ;
|
|
|
|
ASSERT(m_hFile != INVALID_HANDLE_VALUE);
|
|
|
|
// write RecordCount;
|
|
liMove.LowPart = offsetof(PCMHeader, ulRecordCount);
|
|
liMove.HighPart = 0 ;
|
|
|
|
hr = Base::Seek(liMove, FILE_BEGIN, NULL);
|
|
if ( FAILED(hr))
|
|
goto Exit;
|
|
|
|
hr = WriteWithDelay((PVOID)&ulRecordCount, sizeof(ULONG), NULL);
|
|
if ( FAILED(hr))
|
|
goto Exit;
|
|
|
|
// write MaxNodeCount;
|
|
liMove.LowPart = offsetof(PCMHeader, usMaxNodeCount);
|
|
liMove.HighPart = 0 ;
|
|
|
|
hr = Base::Seek(liMove, FILE_BEGIN, NULL);
|
|
if ( FAILED(hr))
|
|
goto Exit;
|
|
|
|
hr = WriteWithDelay((PVOID)&dwMaxNodeCount, sizeof(ULONG), NULL);
|
|
if ( FAILED(hr))
|
|
goto Exit;
|
|
|
|
if ( ! Base::Close()) {
|
|
hr = HRESULT_FROM_WIN32(::FusionpGetLastWin32Error());
|
|
goto Exit;
|
|
}
|
|
|
|
hr = NOERROR;
|
|
Exit:
|
|
return hr;
|
|
|
|
}
|
|
|
|
BOOL CPrecompiledManifestWriterStream::IsSinkedStream()
|
|
{
|
|
if ((m_fBuffer == FALSE) && (m_hFile != INVALID_HANDLE_VALUE))
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|