Пример #1
0
static TFileEntry * FindPatchEntry(TMPQArchive * ha, TFileEntry * pFileEntry)
{
    TFileEntry * pPatchEntry = NULL;
    TFileEntry * pTempEntry;
    char szFileName[MAX_PATH+1];

    // Go while there are patches
    while(ha->haPatch != NULL)
    {
        // Move to the patch archive
        ha = ha->haPatch;
        szFileName[0] = 0;

        // Prepare the prefix for the file name
        if(ha->pPatchPrefix != NULL)
            StringCopyA(szFileName, ha->pPatchPrefix->szPatchPrefix, MAX_PATH);
        StringCatA(szFileName, pFileEntry->szFileName, MAX_PATH);

        // Try to find the file there
        pTempEntry = GetFileEntryExact(ha, szFileName, 0, NULL);
        if(pTempEntry != NULL)
            pPatchEntry = pTempEntry;
    }

    // Return the found patch entry
    return pPatchEntry;
}
Пример #2
0
//===========================================================
//
// Desc: Add a new memory info to the hash table
//       If it successfully executes, it will return true, otherwise false.
//
// [In]
// ptr - The start address allocated
// size - The memory size of ptr
// file - The file name calling this function
// line - The line number calling this function
//
// [Return]
// true/false
//
//===========================================================
// Hash table version
bool new_AddMemoryInfo( void *ptr, unsigned int size, const char *file, int line )
{
	StructMemUnit *pMemUnit = (StructMemUnit*)malloc( sizeof(StructMemUnit) );
	if( pMemUnit )
	{
		// the name name of allocating this memory unit
		if( StringLengthA( file ) < NEW_MEM_FILE_NAME_MAX )
		{
			//StringCopyA( pMemUnit->szFileName, NEW_MEM_FILE_NAME_MAX, file );
			StringCopyA( pMemUnit->szFileName, file );
		}
		else
		{
			StringCopyNA( pMemUnit->szFileName, file, 8 );
			pMemUnit->szFileName[8]  = '\0';
			StringCatA( pMemUnit->szFileName, "..." );
			StringCatA( pMemUnit->szFileName, &file[_g_long_string_size] );
		}
		
		// the line number of allocating this memory unit
		pMemUnit->nFileLine = line;
		
		// the length of allocating this memory unit
		pMemUnit->nSize = size;
		
		// the address of allocating this memory unit
		pMemUnit->pPtr = ptr;

		// count the amnount of memory
		_g_new_memory.m_memory_used_cur += size;
		if( _g_new_memory.m_memory_used_cur > _g_new_memory.m_memory_used_max )
		{
			_g_new_memory.m_memory_used_max = _g_new_memory.m_memory_used_cur;
		}

		// add this mem-unit to the _g_new_memory
		unsigned int dwAddress = (unsigned int)(pMemUnit->pPtr);
		_g_new_memory.AppendItem( (void*)&dwAddress, sizeof(dwAddress), pMemUnit );
	}
	else
	{
		return false;
	}

	return true;
}