Example #1
0
/*****************************************************
  *类型:公有成员函数
  *功能:打开指定的文件.注意,此方法会将打开的文件内容清零.
  ***************************************************/
bool MyFile::Open(const QString& fileName)
{
    this->file = fopen(fileName.toAscii(), "w+");
    fclose(this->file);
    this->file = fopen(fileName.toAscii(), "r+b");
    MY_FILE_HEADER fileHeader;
    WriteFileHead(fileHeader);
    isSaveAs = true;
    this->fileName = fileName;
    return true;
}
Example #2
0
bool CResUpdater::Update(
    const char* pFilepath )
{
    GetOldFileHead(pFilepath);

    m_pPatchFileHead = GetPatchFileHead();
    DWORD dwRemoveFileCount = m_pPatchFileHead->dwRemoveFileCount;
    DWORD dwAddFileCount = m_pPatchFileHead->dwAddFileCount;
    const DWORD& dwVolumeCount = m_pPatchFileHead->dwVolumeCount;
    UHashValue* pRemoveList = (UHashValue*)(m_pPatchFileHead + 1);
    DataIndex1* pVolumeIndex = (DataIndex1*)(pRemoveList + dwRemoveFileCount);
    
    char szNewPath[260] = {0};
    sprintf(szNewPath, "%s.bak", pFilepath);
    
    /**
    *@note 将老文件中的保留的数据存进文件,并保存好新的索引
    */
    m_NewResFile.OpenByWrite(szNewPath);
    DWORD dwFileCount = m_pOldFileHead->dwFileCount + dwAddFileCount - dwRemoveFileCount;
    bool bRc = WriteOldData(dwFileCount, pRemoveList, dwRemoveFileCount);
    if ( !bRc )
    {
        return false;
    }

    /**
    *@note 将新加的数据写进新文件
    */
    BYTE szKey[8];
    bRc = Unpack(
        m_pPatchFileHead->dwMaxVolumeSize,
        m_pPatchFileHead->dwVolumeCount,
        Raw_E_Algo, szKey,
        pVolumeIndex);
    //bRc = !!WriteNewData(pVolumeIndex, dwVolumeCount);
    DestroyPatchFileHead(m_pPatchFileHead);
    if ( !bRc )
    {
        return false;
    }

    WriteFileHead();
    m_NewResFile.Close();

    bRc = !!FileSystem::CFile::Remove(pFilepath);
    if ( !bRc )
    {
        return false;
    }

    bRc = !!FileSystem::CFile::Rename(szNewPath, pFilepath);
    return bRc;
}