本文整理汇总了C++中FileLoader::length方法的典型用法代码示例。如果您正苦于以下问题:C++ FileLoader::length方法的具体用法?C++ FileLoader::length怎么用?C++ FileLoader::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileLoader
的用法示例。
在下文中一共展示了FileLoader::length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadDBFile
char* LocalPlayerDataManager::LoadDBFile(std::string fileName, long& length)
{
FileLoader loader;
if (!loader.load((char*)fileName.c_str(), FileLoader::_TYPED_READ_ONLY_))
{
loader.unload();
return NULL;
}
length = loader.length();
if (length <= (sizeof(char)*32+sizeof(int)))
{
loader.unload();
return NULL;
}
// 读取文件信息
char* pBuffer = new char[length+1];
memset(pBuffer, 0, length+1);
loader.read(pBuffer, length);
loader.unload();
// 先进行解密
DBSYSTEM->XORBuffer((char*)DBSYSTEM->GetLocalDataEncryptionKey().c_str(), pBuffer, length);
// 判断文件是否完整
std::string md5Key = MD5Crypto::md5((unsigned char*)pBuffer, length-32);
if (md5Key.compare(pBuffer+length-32) != 0)
{
delete[] pBuffer;
return NULL;
}
return pBuffer;
}
示例2: LoadTempFile
bool EngineSystem::LoadTempFile(char* pFileName, char*& pBuffer, unsigned int& iLength)
{
assert(pFileName != NULL);
assert(strlen(pFileName) > 0);
std::string filepath = EngineSystem::GetDocumentDir();
filepath += pFileName;
FileLoader loader;
if (!loader.load((char*)filepath.c_str(), FileLoader::_TYPED_READ_ONLY_))
return false;
// 读取文件内容
iLength = loader.length();
pBuffer = new char[iLength+1];
memset(pBuffer, 0, iLength+1);
loader.read(pBuffer, iLength);
loader.unload();
return true;
}
示例3: SaveToFile
void LocalPlayerDataManager::SaveToFile()
{
// 设置当前保存的时间
m_PlayerLastLogoutTime = TimeSystem::GetCurrentMicroSecond();
// 版本号长度
int versionLen = NinjiaTribeApp::get_instance2()->GetVersion().length();
EPacket packet;
// 插入版本信息
packet<<versionLen;
packet.append((char*)NinjiaTribeApp::get_instance2()->GetVersion().c_str(), versionLen);
// 保存当前时间信息
packet<<m_PlayerLastLogoutTime;
// 保存基本信息
packet<<m_LocalCurrentPlayerId;
packet<<m_LocalRubyNum;
packet<<m_LocalGoldNum;
int num = m_LocalHeroStateList.size();
packet<<num;
if (num > 0)
{
std::list<_LOCAL_HERO_STATE_>::iterator iter = m_LocalHeroStateList.begin();
std::list<_LOCAL_HERO_STATE_>::iterator iter_e = m_LocalHeroStateList.end();
for ( ; iter!=iter_e; ++iter)
{
_LOCAL_HERO_STATE_ temp = (*iter);
packet.append<_LOCAL_HERO_STATE_>(temp);
}
}
// 增加md5存档校验码
std::string md5Key = MD5Crypto::md5((unsigned char*)packet.get_packet_buff(), packet.size());
packet.append((char*)md5Key.c_str(), md5Key.length());
// 更新备份文件
try
{
do
{
std::string filePath = EngineSystem::GetDocumentDir();
filePath += GetName();
FileLoader loader;
if (!loader.load((char*)filePath.c_str(), FileLoader::_TYPED_READ_ONLY_))
{
loader.unload();
break;
}
int fileLength = loader.length();
char* pBuffer = new char[fileLength+1];
memset(pBuffer, 0, fileLength+1);
loader.read(pBuffer, fileLength);
loader.unload();
filePath = EngineSystem::GetDocumentDir();
filePath += GetTempName();
if (!loader.load((char*)filePath.c_str(), FileLoader::_TYPED_CLEAR_WRITE_))
{
loader.unload();
delete []pBuffer;
break;
}
loader.write(pBuffer, fileLength);
loader.unload();
delete []pBuffer;
}
while (false);
}
catch (...)
{
;
}
try
{
// 先进行解密
DBSYSTEM->XORBuffer((char*)DBSYSTEM->GetLocalDataEncryptionKey().c_str(), packet.get_packet_buff(), packet.size());
std::string filePath = EngineSystem::GetDocumentDir();
filePath += GetName();
FileLoader loader;
if (!loader.load((char*)filePath.c_str(), FileLoader::_TYPED_CLEAR_WRITE_))
return ;
loader.write(packet.get_packet_buff(), packet.size());
loader.unload();
}
catch (...)
{
;
}
}