From e482d3847e175a99ba264f421e86df016570ff6d Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Wed, 31 Mar 2021 07:33:19 +0200 Subject: Fixed SFileSetFilePointer on local files --- src/SFileReadFile.cpp | 7 +++--- test/StormTest.cpp | 59 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp index a9d070f..192d212 100644 --- a/src/SFileReadFile.cpp +++ b/src/SFileReadFile.cpp @@ -886,10 +886,9 @@ DWORD WINAPI SFileSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHi if(!FileStream_Read(hf->pStream, &NewPosition, NULL, 0)) return SFILE_INVALID_POS; } - else - { - hf->dwFilePos = (DWORD)NewPosition; - } + + // Also, store the new file position to the TMPQFile struct + hf->dwFilePos = (DWORD)NewPosition; // Return the new file position if(plFilePosHigh != NULL) diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 8b54a43..83be4e2 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -45,7 +45,14 @@ typedef struct _TEST_INFO DWORD dwFlags; LPCSTR szFileName1; LPCSTR szFileName2; -} TEST_INFO, PTEST_INFO; +} TEST_INFO, *PTEST_INFO; + +typedef struct _LINE_INFO +{ + LONG nLinePos; + DWORD nLineLen; + char * szLine; +} LINE_INFO, *PLINE_INFO; //------------------------------------------------------------------------------ // Local variables @@ -2108,6 +2115,40 @@ static void TestGetFileInfo( // StormLib is able to open local files (as well as the original Storm.dll) // I want to keep this for occasional use + +static LINE_INFO Lines[] = +{ + {0x000, 18, "accountbilling.url"}, + {0x013, 45, "alternate/character/goblin/male/goblinmale.m2"}, + {0x9ab, 54, "alternate/character/goblin/male/goblinmale0186-00.anim"} +}; + +static DWORD TestOnLocalListFile_Read(TLogHelper & Logger, HANDLE hFile) +{ + for(size_t i = 0; i < _countof(Lines); i++) + { + DWORD dwBytesRead = 0; + char szFileLine[0x100] = {0}; + + SFileSetFilePointer(hFile, Lines[i].nLinePos, NULL, FILE_BEGIN); + SFileReadFile(hFile, szFileLine, Lines[i].nLineLen, &dwBytesRead, NULL); + + if(dwBytesRead != Lines[i].nLineLen) + { + Logger.PrintMessage("Line %u length mismatch", i); + return false; + } + + if(strcmp(szFileLine, Lines[i].szLine)) + { + Logger.PrintMessage("Line %u content mismatch", i); + return false; + } + } + + return true; +} + static DWORD TestOnLocalListFile(LPCTSTR szPlainName) { TLogHelper Logger("LocalListFile", szPlainName); @@ -2119,7 +2160,6 @@ static DWORD TestOnLocalListFile(LPCTSTR szPlainName) TCHAR szFullPath[MAX_PATH]; char szFileName1[MAX_PATH]; char szFileName2[MAX_PATH]; - char szFileLine[0x40] = {0}; int nFileCount = 0; // Get the full name of the local file @@ -2138,11 +2178,8 @@ static DWORD TestOnLocalListFile(LPCTSTR szPlainName) if(dwFileSizeHi != 0 || dwFileSizeLo != 0x04385a4e) Logger.PrintMessage("Local file size mismatch"); - // Read the first line - SFileReadFile(hFile, szFileLine, 18, NULL, NULL); - if(strcmp(szFileLine, "accountbilling.url")) - Logger.PrintMessage("Content of the listfile does not match"); - + // Read few lines, check their content + TestOnLocalListFile_Read(Logger, hFile); SFileCloseFile(hFile); } else @@ -4247,10 +4284,10 @@ int _tmain(int argc, TCHAR * argv[]) // Tests on a local listfile // - //if(dwErrCode == ERROR_SUCCESS) - //{ - // dwErrCode = TestOnLocalListFile(_T("ListFile_Blizzard.txt")); - //} + if(dwErrCode == ERROR_SUCCESS) + { + dwErrCode = TestOnLocalListFile(_T("ListFile_Blizzard.txt")); + } // // Open all files from the command line -- cgit v1.2.3