增加Lua函数
This commit is contained in:
@@ -84,4 +84,46 @@ uint32_t CFileStream::crc32(void)
|
||||
return m_crc32;
|
||||
}
|
||||
|
||||
bool CFileStream::writeToDiskFile(const wchar_t* diskPathFile)
|
||||
{
|
||||
HANDLE hFile = ::CreateFileW(diskPathFile,
|
||||
FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
0,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_ARCHIVE,
|
||||
0);
|
||||
|
||||
if (hFile == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
setLastError(NPK_ERR_FILE_CREATE, "Failed to open output file for writing, LastError=%d.", ::GetLastError());
|
||||
return false; // Failed to open output file
|
||||
}
|
||||
|
||||
//store current read offset
|
||||
uint32_t currentOffset = m_currentOffset;
|
||||
m_currentOffset = 0;
|
||||
|
||||
//read loop
|
||||
char buffer[4096] = { 0 };
|
||||
uint32_t bytesRead = 0;
|
||||
|
||||
while ((bytesRead = this->read(buffer, sizeof(buffer))) > 0)
|
||||
{
|
||||
DWORD dwWriteBytes = 0;
|
||||
if (!WriteFile(hFile, buffer, bytesRead, &dwWriteBytes, 0) ||
|
||||
dwWriteBytes != bytesRead)
|
||||
{
|
||||
setLastError(NPK_ERR_FILE_WRITE, "Failed to write to output file, LastError=%d", ::GetLastError());
|
||||
|
||||
CloseHandle(hFile);
|
||||
m_currentOffset = currentOffset;
|
||||
return false; // Failed to write to output file
|
||||
}
|
||||
}
|
||||
CloseHandle(hFile);
|
||||
m_currentOffset = currentOffset;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user