本文整理汇总了C++中ComprDataIO::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ ComprDataIO::Init方法的具体用法?C++ ComprDataIO::Init怎么用?C++ ComprDataIO::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComprDataIO
的用法示例。
在下文中一共展示了ComprDataIO::Init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFileContents
void CPsfRarArchive::ReadFileContents(const char* fileName, void* buffer, unsigned int bufferLength)
{
Archive* arc(ConvertArchive(m_archive));
if(!arc->IsOpened())
{
throw std::runtime_error("Archive isn't opened.");
}
std::string fixedFileName(fileName);
boost::replace_all(fixedFileName, "/", "\\");
arc->Seek(0, SEEK_SET);
ComprDataIO dataIo;
dataIo.Init();
Unpack unpack(&dataIo);
while(arc->ReadHeader() > 0)
{
if(arc->ShortBlock.HeaderType == HEAD_FILE)
{
if(!arc->IsArcDir())
{
bool isGoodFile = !stricmp(fixedFileName.c_str(), string_cast<std::string>(arc->FileHead.FileName).c_str());
dataIo.SetFiles(arc, NULL);
dataIo.SetPackedSizeToRead(arc->FileHead.PackSize);
dataIo.CurUnpRead = 0;
dataIo.CurUnpWrite = 0;
dataIo.UnpHash.Init(arc->FileHead.FileHash.Type, 1);
dataIo.PackedDataHash.Init(arc->FileHead.FileHash.Type, 1);
dataIo.SetTestMode(!isGoodFile);
if(isGoodFile)
{
dataIo.SetUnpackToMemory(reinterpret_cast<byte*>(buffer), bufferLength);
}
unpack.Init(arc->FileHead.WinSize, arc->FileHead.Solid);
unpack.SetDestSize(arc->FileHead.UnpSize);
if(arc->FileHead.Method == 0x30)
{
std::vector<byte> unstoreBuffer;
unstoreBuffer.resize(0x10000);
uint toReadSize = arc->FileHead.UnpSize;
while(1)
{
uint code = dataIo.UnpRead(&unstoreBuffer[0], unstoreBuffer.size());
if(code == 0 || code == -1) break;
code = code < toReadSize ? code : toReadSize;
dataIo.UnpWrite(&unstoreBuffer[0], code);
if(toReadSize >= 0)
{
toReadSize -= code;
}
}
}
else
{
unpack.DoUnpack(arc->FileHead.UnpVer, arc->FileHead.Solid);
}
if(!dataIo.UnpHash.Cmp(&arc->FileHead.FileHash, arc->FileHead.UseHashKey ? arc->FileHead.HashKey : nullptr))
{
throw std::runtime_error("CRC check error.");
}
if(isGoodFile)
{
return;
}
}
}
arc->SeekToNext();
}
throw std::runtime_error("Couldn't read file from archive.");
}