| 230 | // PtrFile - Pointer to store opened file handle |
| 231 | |
| 232 | bool WINAPI SFileOpenFileEx(HANDLE hMpq, const char * szFileName, DWORD dwSearchScope, HANDLE * PtrFile) |
| 233 | { |
| 234 | TMPQArchive * ha = IsValidMpqHandle(hMpq); |
| 235 | TFileEntry * pFileEntry = NULL; |
| 236 | TMPQFile * hf = NULL; |
| 237 | DWORD dwHashIndex = HASH_ENTRY_FREE; |
| 238 | DWORD dwFileIndex = 0; |
| 239 | DWORD dwErrCode = ERROR_SUCCESS; |
| 240 | bool bOpenByIndex = false; |
| 241 | |
| 242 | // Don't accept NULL pointer to file handle |
| 243 | if(szFileName == NULL || *szFileName == 0) |
| 244 | dwErrCode = ERROR_INVALID_PARAMETER; |
| 245 | |
| 246 | // When opening a file from MPQ, the handle must be valid |
| 247 | if(dwSearchScope != SFILE_OPEN_LOCAL_FILE && ha == NULL) |
| 248 | dwErrCode = ERROR_INVALID_HANDLE; |
| 249 | |
| 250 | // When not checking for existence, the pointer to file handle must be valid |
| 251 | if(dwSearchScope != SFILE_OPEN_CHECK_EXISTS && PtrFile == NULL) |
| 252 | dwErrCode = ERROR_INVALID_PARAMETER; |
| 253 | |
| 254 | // Prepare the file opening |
| 255 | if(dwErrCode == ERROR_SUCCESS) |
| 256 | { |
| 257 | switch(dwSearchScope) |
| 258 | { |
| 259 | case SFILE_OPEN_FROM_MPQ: |
| 260 | case SFILE_OPEN_BASE_FILE: |
| 261 | case SFILE_OPEN_CHECK_EXISTS: |
| 262 | |
| 263 | // If this MPQ has no patches, open the file from this MPQ directly |
| 264 | if(ha->haPatch == NULL || dwSearchScope == SFILE_OPEN_BASE_FILE) |
| 265 | { |
| 266 | pFileEntry = GetFileEntryLocale(ha, szFileName, g_lcFileLocale, &dwHashIndex); |
| 267 | } |
| 268 | |
| 269 | // If this MPQ is a patched archive, open the file as patched |
| 270 | else |
| 271 | { |
| 272 | return OpenPatchedFile(hMpq, szFileName, PtrFile); |
| 273 | } |
| 274 | break; |
| 275 | |
| 276 | case SFILE_OPEN_ANY_LOCALE: |
| 277 | |
| 278 | // This open option is reserved for opening MPQ internal listfile. |
| 279 | // No argument validation. Tries to open file with neutral locale first, |
| 280 | // then any other available. |
| 281 | pFileEntry = GetFileEntryLocale(ha, szFileName, 0, &dwHashIndex); |
| 282 | break; |
| 283 | |
| 284 | case SFILE_OPEN_LOCAL_FILE: |
| 285 | |
| 286 | // Open a local file |
| 287 | return OpenLocalFile(szFileName, PtrFile); |
| 288 | |
| 289 | default: |