| 204 | } |
| 205 | |
| 206 | static bool DoMPQSearch_FileEntry( |
| 207 | TMPQSearch * hs, |
| 208 | SFILE_FIND_DATA * lpFindFileData, |
| 209 | TMPQArchive * ha, |
| 210 | TMPQHash * pHashEntry, |
| 211 | TFileEntry * pFileEntry) |
| 212 | { |
| 213 | TFileEntry * pPatchEntry; |
| 214 | HANDLE hFile = NULL; |
| 215 | const char * szFileName; |
| 216 | size_t nPrefixLength = (ha->pPatchPrefix != NULL) ? ha->pPatchPrefix->nLength : 0; |
| 217 | DWORD dwBlockIndex; |
| 218 | char szNameBuff[MAX_PATH]; |
| 219 | |
| 220 | // Is it a file but not a patch file? |
| 221 | if((pFileEntry->dwFlags & hs->dwFlagMask) == MPQ_FILE_EXISTS) |
| 222 | { |
| 223 | // Ignore fake files which are not compressed but have size higher than the archive |
| 224 | if((pFileEntry->dwFlags & MPQ_FILE_COMPRESS_MASK) == 0 && (pFileEntry->dwFileSize > ha->FileSize)) |
| 225 | return false; |
| 226 | |
| 227 | // Now we have to check if this file was not enumerated before |
| 228 | if(!FileWasFoundBefore(ha, hs, pFileEntry)) |
| 229 | { |
| 230 | // if(pFileEntry != NULL && !_stricmp(pFileEntry->szFileName, "TriggerLibs\\NativeLib.galaxy")) |
| 231 | // DebugBreak(); |
| 232 | |
| 233 | // Find a patch to this file |
| 234 | // Note: This either succeeds or returns pFileEntry |
| 235 | pPatchEntry = FindPatchEntry(ha, pFileEntry); |
| 236 | |
| 237 | // Prepare the block index |
| 238 | dwBlockIndex = (DWORD)(pFileEntry - ha->pFileTable); |
| 239 | |
| 240 | // Get the file name. If it's not known, we will create pseudo-name |
| 241 | szFileName = pFileEntry->szFileName; |
| 242 | if(szFileName == NULL) |
| 243 | { |
| 244 | // Open the file by its pseudo-name. |
| 245 | StringCreatePseudoFileName(szNameBuff, _countof(szNameBuff), dwBlockIndex, "xxx"); |
| 246 | if(SFileOpenFileEx((HANDLE)hs->ha, szNameBuff, SFILE_OPEN_BASE_FILE, &hFile)) |
| 247 | { |
| 248 | SFileGetFileName(hFile, szNameBuff); |
| 249 | szFileName = szNameBuff; |
| 250 | SFileCloseFile(hFile); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // If the file name is still NULL, we cannot include the file to search results |
| 255 | if(szFileName != NULL) |
| 256 | { |
| 257 | // Check the file name against the wildcard |
| 258 | if(SFileCheckWildCard(szFileName + nPrefixLength, hs->szSearchMask)) |
| 259 | { |
| 260 | // Fill the found entry. hash entry and block index are taken from the base MPQ |
| 261 | lpFindFileData->dwHashIndex = HASH_ENTRY_FREE; |
| 262 | lpFindFileData->dwBlockIndex = dwBlockIndex; |
| 263 | lpFindFileData->dwFileSize = pPatchEntry->dwFileSize; |
no test coverage detected