本文整理汇总了C++中CFile::ReadStruct方法的典型用法代码示例。如果您正苦于以下问题:C++ CFile::ReadStruct方法的具体用法?C++ CFile::ReadStruct怎么用?C++ CFile::ReadStruct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::ReadStruct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OpenArchive
CIMGArchiveTranslatorHandle* imgExtension::OpenArchive( CFileTranslator *srcRoot, const char *srcPath )
{
CIMGArchiveTranslatorHandle *transOut = NULL;
bool hasValidArchive = false;
eIMGArchiveVersion theVersion;
CFile *contentFile = srcRoot->Open( srcPath, "rb+" );
if ( !contentFile )
{
return NULL;
}
bool hasUniqueRegistryFile = false;
CFile *registryFile = NULL;
// Check for version 2.
struct mainHeader
{
union
{
unsigned char version[4];
unsigned int checksum;
};
};
mainHeader imgHeader;
bool hasReadMainHeader = contentFile->ReadStruct( imgHeader );
if ( hasReadMainHeader && imgHeader.checksum == '2REV' )
{
hasValidArchive = true;
theVersion = IMG_VERSION_2;
registryFile = contentFile;
}
if ( !hasValidArchive )
{
// Check for version 1.
std::string dirOfArchive;
std::string extOrig;
std::string nameItem = FileSystem::GetFileNameItem( srcPath, false, &dirOfArchive, &extOrig );
if ( nameItem.size() != 0 )
{
hasUniqueRegistryFile = true;
// Try to open the registry file.
std::string regFilePath = dirOfArchive + nameItem + ".DIR";
registryFile = srcRoot->Open( regFilePath.c_str(), "rb+" );
if ( registryFile )
{
hasValidArchive = true;
theVersion = IMG_VERSION_1;
}
}
}
if ( hasValidArchive )
{
CIMGArchiveTranslator *translator = new CIMGArchiveTranslator( *this, contentFile, registryFile, theVersion );
if ( translator )
{
bool loadingSuccess = translator->ReadArchive();
if ( loadingSuccess )
{
transOut = translator;
}
else
{
delete translator;
contentFile = NULL;
registryFile = NULL;
}
}
}
if ( !transOut )
{
if ( contentFile )
{
delete contentFile;
contentFile = NULL;
}
if ( hasUniqueRegistryFile && registryFile )
{
delete registryFile;
registryFile = NULL;
//.........这里部分代码省略.........
示例2: GenOpenArchiveTemplate
static inline CIMGArchiveTranslatorHandle* GenOpenArchiveTemplate( imgExtension *env, CFileTranslator *srcRoot, const charType *srcPath, constructionHandler constr )
{
CIMGArchiveTranslatorHandle *transOut = NULL;
bool hasValidArchive = false;
eIMGArchiveVersion theVersion;
CFile *contentFile = srcRoot->Open( srcPath, GetReadWriteMode <charType> ( false ), FILE_FLAG_WRITESHARE );
if ( !contentFile )
{
return NULL;
}
bool hasUniqueRegistryFile = false;
CFile *registryFile = NULL;
// Check for version 2.
struct mainHeader
{
union
{
unsigned char version[4];
fsUInt_t checksum;
};
};
mainHeader imgHeader;
bool hasReadMainHeader = contentFile->ReadStruct( imgHeader );
if ( hasReadMainHeader && imgHeader.checksum == '2REV' )
{
hasValidArchive = true;
theVersion = IMG_VERSION_2;
registryFile = contentFile;
}
if ( !hasValidArchive )
{
// Check for version 1.
hasUniqueRegistryFile = true;
registryFile = OpenSeperateIMGRegistryFile( srcRoot, srcPath, false );
if ( registryFile )
{
hasValidArchive = true;
theVersion = IMG_VERSION_1;
}
}
if ( hasValidArchive )
{
CIMGArchiveTranslator *translator = constr( env, registryFile, contentFile, theVersion );
if ( translator )
{
bool loadingSuccess = translator->ReadArchive();
if ( loadingSuccess )
{
transOut = translator;
}
else
{
delete translator;
contentFile = NULL;
registryFile = NULL;
}
}
}
if ( !transOut )
{
if ( contentFile )
{
delete contentFile;
contentFile = NULL;
}
if ( hasUniqueRegistryFile && registryFile )
{
delete registryFile;
registryFile = NULL;
}
}
return transOut;
}