| 13 | #include "StormCommon.h" |
| 14 | |
| 15 | bool STORMAPI SFileExtractFile(HANDLE hMpq, const char * szToExtract, const TCHAR * szExtracted, DWORD dwSearchScope) |
| 16 | { |
| 17 | TFileStream * pLocalFile = NULL; |
| 18 | HANDLE hMpqFile = NULL; |
| 19 | int nError = ERROR_SUCCESS; |
| 20 | |
| 21 | // Open the MPQ file |
| 22 | if(nError == ERROR_SUCCESS) |
| 23 | { |
| 24 | if(!SFileOpenFileEx(hMpq, szToExtract, dwSearchScope, &hMpqFile)) |
| 25 | nError = GetLastError(); |
| 26 | } |
| 27 | |
| 28 | // Create the local file |
| 29 | if(nError == ERROR_SUCCESS) |
| 30 | { |
| 31 | pLocalFile = FileStream_CreateFile(szExtracted, 0); |
| 32 | if(pLocalFile == NULL) |
| 33 | nError = GetLastError(); |
| 34 | } |
| 35 | |
| 36 | // Copy the file's content |
| 37 | while(nError == ERROR_SUCCESS) |
| 38 | { |
| 39 | char szBuffer[0x1000]; |
| 40 | DWORD dwTransferred = 0; |
| 41 | |
| 42 | // dwTransferred is only set to nonzero if something has been read. |
| 43 | // nError can be ERROR_SUCCESS or ERROR_HANDLE_EOF |
| 44 | if(!SFileReadFile(hMpqFile, szBuffer, sizeof(szBuffer), &dwTransferred, NULL)) |
| 45 | nError = GetLastError(); |
| 46 | if(nError == ERROR_HANDLE_EOF) |
| 47 | nError = ERROR_SUCCESS; |
| 48 | if(dwTransferred == 0) |
| 49 | break; |
| 50 | |
| 51 | // If something has been actually read, write it |
| 52 | if(!FileStream_Write(pLocalFile, NULL, szBuffer, dwTransferred)) |
| 53 | nError = GetLastError(); |
| 54 | } |
| 55 | |
| 56 | // Close the files |
| 57 | if(hMpqFile != NULL) |
| 58 | SFileCloseFile(hMpqFile); |
| 59 | if(pLocalFile != NULL) |
| 60 | FileStream_Close(pLocalFile); |
| 61 | if(nError != ERROR_SUCCESS) |
| 62 | SetLastError(nError); |
| 63 | return (nError == ERROR_SUCCESS); |
| 64 | } |
nothing calls this directly
no test coverage detected