本文整理汇总了C++中nio::COutFile::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ COutFile::Open方法的具体用法?C++ COutFile::Open怎么用?C++ COutFile::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nio::COutFile
的用法示例。
在下文中一共展示了COutFile::Open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyFileSpec
static HRESULT CopyFileSpec(CFSTR fromPath, CFSTR toPath, bool writeToDisk, UInt64 fileSize,
UInt32 bufferSize, UInt64 progressStart, IProgress *progress)
{
NIO::CInFile inFile;
if (!inFile.Open(fromPath))
return GetLastError();
if (fileSize == (UInt64)(Int64)-1)
{
if (!inFile.GetLength(fileSize))
::GetLastError();
}
NIO::COutFile outFile;
if (writeToDisk)
{
if (!outFile.Open(toPath, FILE_SHARE_WRITE, OPEN_EXISTING, 0))
return GetLastError();
}
else
if (!outFile.Create(toPath, true))
return GetLastError();
CPhysTempBuffer tempBuffer;
tempBuffer.buffer = MidAlloc(bufferSize);
if (!tempBuffer.buffer)
return E_OUTOFMEMORY;
for (UInt64 pos = 0; pos < fileSize;)
{
UInt64 progressCur = progressStart + pos;
RINOK(progress->SetCompleted(&progressCur));
UInt64 rem = fileSize - pos;
UInt32 curSize = (UInt32)MyMin(rem, (UInt64)bufferSize);
UInt32 processedSize;
if (!inFile.Read(tempBuffer.buffer, curSize, processedSize))
return GetLastError();
if (processedSize == 0)
break;
curSize = processedSize;
if (writeToDisk)
{
const UInt32 kMask = 0x1FF;
curSize = (curSize + kMask) & ~kMask;
if (curSize > bufferSize)
return E_FAIL;
}
if (!outFile.Write(tempBuffer.buffer, curSize, processedSize))
return GetLastError();
if (curSize != processedSize)
return E_FAIL;
pos += curSize;
}
return S_OK;
}