本文整理汇总了C++中DiskFile::Error方法的典型用法代码示例。如果您正苦于以下问题:C++ DiskFile::Error方法的具体用法?C++ DiskFile::Error怎么用?C++ DiskFile::Error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiskFile
的用法示例。
在下文中一共展示了DiskFile::Error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckRegularFile
void ParRenamer::CheckRegularFile(const char* destDir, const char* filename)
{
debug("Computing hash for %s", filename);
DiskFile file;
if (!file.Open(filename, DiskFile::omRead))
{
PrintMessage(Message::mkError, "Could not open file %s", filename);
return;
}
// load first 16K of the file into buffer
static const int blockSize = 16*1024;
CharBuffer buffer(blockSize);
int readBytes = (int)file.Read(buffer, buffer.Size());
if (readBytes != buffer.Size() && file.Error())
{
PrintMessage(Message::mkError, "Could not read file %s", filename);
return;
}
file.Close();
Par2::MD5Hash hash16k;
Par2::MD5Context context;
context.Update(buffer, readBytes);
context.Final(hash16k);
debug("file: %s; hash16k: %s", FileSystem::BaseFileName(filename), hash16k.print().c_str());
for (FileHash& fileHash : m_fileHashList)
{
if (!strcmp(fileHash.GetHash(), hash16k.print().c_str()))
{
debug("Found correct filename: %s", fileHash.GetFilename());
fileHash.SetFileExists(true);
BString<1024> dstFilename("%s%c%s", destDir, PATH_SEPARATOR, fileHash.GetFilename());
if (!FileSystem::FileExists(dstFilename) && !IsSplittedFragment(filename, fileHash.GetFilename()))
{
RenameFile(filename, dstFilename);
}
break;
}
}
}
示例2: CheckParFile
void ParRenamer::CheckParFile(const char* destDir, const char* filename)
{
debug("Checking par2-header for %s", filename);
DiskFile file;
if (!file.Open(filename, DiskFile::omRead))
{
PrintMessage(Message::mkError, "Could not open file %s", filename);
return;
}
// load par2-header
Par2::PACKET_HEADER header;
int readBytes = (int)file.Read(&header, sizeof(header));
if (readBytes != sizeof(header) && file.Error())
{
PrintMessage(Message::mkError, "Could not read file %s", filename);
return;
}
file.Close();
// Check the packet header
if (Par2::packet_magic != header.magic || // not par2-file
sizeof(Par2::PACKET_HEADER) > header.length || // packet length is too small
0 != (header.length & 3) || // packet length is not a multiple of 4
FileSystem::FileSize(filename) < (int)header.length) // packet would extend beyond the end of the file
{
// not par2-file or damaged header, ignoring the file
return;
}
BString<100> setId = header.setid.print().c_str();
for (char* p = setId; *p; p++) *p = tolower(*p); // convert string to lowercase
debug("Storing: %s; setid: %s", FileSystem::BaseFileName(filename), *setId);
m_parInfoList.emplace_back(filename, setId);
}