| 113 | } |
| 114 | |
| 115 | static bool FileWasFoundBefore( |
| 116 | TMPQArchive * ha, |
| 117 | TMPQSearch * hs, |
| 118 | TFileEntry * pFileEntry) |
| 119 | { |
| 120 | TFileEntry * pEntry; |
| 121 | char * szRealFileName = pFileEntry->szFileName; |
| 122 | DWORD dwStartIndex; |
| 123 | DWORD dwNameHash; |
| 124 | DWORD dwIndex; |
| 125 | |
| 126 | if(hs->pSearchTable != NULL && szRealFileName != NULL) |
| 127 | { |
| 128 | // If we are in patch MPQ, we check if patch prefix matches |
| 129 | // and then trim the patch prefix |
| 130 | if(ha->pPatchPrefix != NULL) |
| 131 | { |
| 132 | // If the patch prefix doesn't fit, we pretend that the file |
| 133 | // was there before and it will be skipped |
| 134 | if(_strnicmp(szRealFileName, ha->pPatchPrefix->szPatchPrefix, ha->pPatchPrefix->nLength)) |
| 135 | return true; |
| 136 | |
| 137 | szRealFileName += ha->pPatchPrefix->nLength; |
| 138 | } |
| 139 | |
| 140 | // Calculate the hash to the table |
| 141 | dwNameHash = ha->pfnHashString(szRealFileName, MPQ_HASH_NAME_A); |
| 142 | dwStartIndex = dwIndex = (dwNameHash % hs->dwSearchTableItems); |
| 143 | |
| 144 | // The file might have been found before |
| 145 | // only if this is not the first MPQ being searched |
| 146 | if(ha->haBase != NULL) |
| 147 | { |
| 148 | // Enumerate all entries in the search table |
| 149 | for(;;) |
| 150 | { |
| 151 | // Get the file entry at that position |
| 152 | pEntry = hs->pSearchTable[dwIndex]; |
| 153 | if(pEntry == NULL) |
| 154 | break; |
| 155 | |
| 156 | if(pEntry->szFileName != NULL) |
| 157 | { |
| 158 | // Does the name match? |
| 159 | if(!_stricmp(pEntry->szFileName, szRealFileName)) |
| 160 | return true; |
| 161 | } |
| 162 | |
| 163 | // Move to the next entry |
| 164 | dwIndex = (dwIndex + 1) % hs->dwSearchTableItems; |
| 165 | if(dwIndex == dwStartIndex) |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // Put the entry to the table for later use |
| 171 | hs->pSearchTable[dwIndex] = pFileEntry; |
| 172 | } |
no outgoing calls
no test coverage detected