mirror of
				https://github.com/thunderbrewhq/thunderbrew
				synced 2025-11-01 00:36:04 +03:00 
			
		
		
		
	 f86f6d6d09
			
		
	
	
		f86f6d6d09
		
			
		
	
	
	
	
		
			
			* feat(app): add StormLib * feat(app): add OpenArchives * feat(util): update SFile to work with StormLib * feat(app): update SFile * feat(util): update SFile with logging (Windows only) * feat(ui): implemented termination w/o notice * chore(build): update StormLib * chore(util): replace std::string with SStr* functions * fix(stormlib): dwFlags argument for SFileOpenPatchArchive * chore(ui): add Script_* stubs * chore(util): clean up SFile::OpenEx * chore(build): update StormLib --------- Co-authored-by: Phaneron <superp00t@tutanota.com>
		
			
				
	
	
		
			65 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*****************************************************************************/
 | |
| /* SFileExtractFile.cpp                   Copyright (c) Ladislav Zezula 2003 */
 | |
| /*---------------------------------------------------------------------------*/
 | |
| /* Simple extracting utility                                                 */
 | |
| /*---------------------------------------------------------------------------*/
 | |
| /*   Date    Ver   Who  Comment                                              */
 | |
| /* --------  ----  ---  -------                                              */
 | |
| /* 20.06.03  1.00  Lad  The first version of SFileExtractFile.cpp            */
 | |
| /*****************************************************************************/
 | |
| 
 | |
| #define __STORMLIB_SELF__
 | |
| #include "StormLib.h"
 | |
| #include "StormCommon.h"
 | |
| 
 | |
| bool WINAPI SFileExtractFile(HANDLE hMpq, const char * szToExtract, const TCHAR * szExtracted, DWORD dwSearchScope)
 | |
| {
 | |
|     TFileStream * pLocalFile = NULL;
 | |
|     HANDLE hMpqFile = NULL;
 | |
|     DWORD dwErrCode = ERROR_SUCCESS;
 | |
| 
 | |
|     // Open the MPQ file
 | |
|     if(dwErrCode == ERROR_SUCCESS)
 | |
|     {
 | |
|         if(!SFileOpenFileEx(hMpq, szToExtract, dwSearchScope, &hMpqFile))
 | |
|             dwErrCode = GetLastError();
 | |
|     }
 | |
| 
 | |
|     // Create the local file
 | |
|     if(dwErrCode == ERROR_SUCCESS)
 | |
|     {
 | |
|         pLocalFile = FileStream_CreateFile(szExtracted, 0);
 | |
|         if(pLocalFile == NULL)
 | |
|             dwErrCode = GetLastError();
 | |
|     }
 | |
| 
 | |
|     // Copy the file's content
 | |
|     while(dwErrCode == ERROR_SUCCESS)
 | |
|     {
 | |
|         char  szBuffer[0x1000];
 | |
|         DWORD dwTransferred = 0;
 | |
| 
 | |
|         // dwTransferred is only set to nonzero if something has been read.
 | |
|         // dwErrCode can be ERROR_SUCCESS or ERROR_HANDLE_EOF
 | |
|         if(!SFileReadFile(hMpqFile, szBuffer, sizeof(szBuffer), &dwTransferred, NULL))
 | |
|             dwErrCode = GetLastError();
 | |
|         if(dwErrCode == ERROR_HANDLE_EOF)
 | |
|             dwErrCode = ERROR_SUCCESS;
 | |
|         if(dwTransferred == 0)
 | |
|             break;
 | |
| 
 | |
|         // If something has been actually read, write it
 | |
|         if(!FileStream_Write(pLocalFile, NULL, szBuffer, dwTransferred))
 | |
|             dwErrCode = GetLastError();
 | |
|     }
 | |
| 
 | |
|     // Close the files
 | |
|     if(hMpqFile != NULL)
 | |
|         SFileCloseFile(hMpqFile);
 | |
|     if(pLocalFile != NULL)
 | |
|         FileStream_Close(pLocalFile);
 | |
|     if(dwErrCode != ERROR_SUCCESS)
 | |
|         SetLastError(dwErrCode);
 | |
|     return (dwErrCode == ERROR_SUCCESS);
 | |
| }
 |