aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLadislav <Zezula>2013-12-16 12:18:32 +0100
committerLadislav <Zezula>2013-12-16 12:18:32 +0100
commit60ef0346ba14b7153c9efd40d0aa6dd01d1d2671 (patch)
treeb065cfb6c3ee9cc47ac85dc6d435fe017e956d86
parentfe51da468be9ca0963192c5f3a1705562bc957ba (diff)
+ Fixed bugs in listfile search
-rw-r--r--src/SFileListFile.cpp17
-rw-r--r--test/TLogHelper.cpp4
-rw-r--r--test/Test.cpp37
3 files changed, 41 insertions, 17 deletions
diff --git a/src/SFileListFile.cpp b/src/SFileListFile.cpp
index c1197c9..058fc7a 100644
--- a/src/SFileListFile.cpp
+++ b/src/SFileListFile.cpp
@@ -53,14 +53,9 @@ static bool FreeListFileCache(TListFileCache * pCache)
if(pCache == NULL)
return false;
- //
- // Note: don't close the pCache->hFile handle.
- // This has to be done by the creator of the listfile cache
- //
-
- // Free all allocated buffers
- if(pCache->szMask != NULL)
- STORM_FREE(pCache->szMask);
+ // Close the listfile
+ if(pCache->hFile != NULL)
+ SFileCloseFile(pCache->hFile);
STORM_FREE(pCache);
return true;
}
@@ -82,7 +77,7 @@ static TListFileCache * CreateListFileCache(HANDLE hListFile, const char * szMas
nMaskLength = strlen(szMask) + 1;
// Allocate cache for one file block
- pCache = (TListFileCache *)STORM_ALLOC(BYTE, sizeof(TListFileCache));
+ pCache = (TListFileCache *)STORM_ALLOC(BYTE, sizeof(TListFileCache) + nMaskLength);
if(pCache != NULL)
{
// Clear the entire structure
@@ -596,10 +591,6 @@ HANDLE WINAPI SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const
}
}
- // Close the listfile
- if(hListFile != NULL)
- SFileCloseFile(hListFile);
-
// Cleanup & exit
if(nError != ERROR_SUCCESS)
{
diff --git a/test/TLogHelper.cpp b/test/TLogHelper.cpp
index 229f9fb..6bad08e 100644
--- a/test/TLogHelper.cpp
+++ b/test/TLogHelper.cpp
@@ -185,7 +185,7 @@ int TLogHelper::PrintWithClreol(const TCHAR * szFormat, va_list argList, bool bP
bMessagePrinted = true;
// Spit out the text in one single printf
- _tprintf(szMessage);
+ _tprintf(_T("%s"), szMessage);
return nError;
}
@@ -283,7 +283,7 @@ int TLogHelper::PrintWithClreol(const char * szFormat, va_list argList, bool bPr
bMessagePrinted = true;
// Spit out the text in one single printf
- printf(szMessage, 0);
+ printf("%s", szMessage, 0);
return nError;
}
diff --git a/test/Test.cpp b/test/Test.cpp
index 7566fbe..7487cad 100644
--- a/test/Test.cpp
+++ b/test/Test.cpp
@@ -260,6 +260,7 @@ static const char * GetShortPlainName(const char * szFileName)
// If the name is still too long, cut it
if((szPlainEnd - szPlainName) > 50)
szPlainName = szPlainEnd - 50;
+
return szPlainName;
}
@@ -1629,6 +1630,30 @@ static int TestOpenLocalFile(const char * szPlainName)
return ERROR_SUCCESS;
}
+static int TestSearchListFile(const char * szPlainName)
+{
+ SFILE_FIND_DATA sf;
+ TLogHelper Logger("SearchListFile", szPlainName);
+ HANDLE hFind;
+ char szFullPath[MAX_PATH];
+ int nFileCount = 0;
+
+ CreateFullPathName(szFullPath, szMpqSubDir, szPlainName);
+ hFind = SListFileFindFirstFile(NULL, szFullPath, "*", &sf);
+ if(hFind != NULL)
+ {
+ for(;;)
+ {
+ Logger.PrintProgress("Found file (%04u): %s", nFileCount++, GetShortPlainName(sf.cFileName));
+ if(!SListFileFindNextFile(hFind, &sf))
+ break;
+ }
+
+ SListFileFindClose(hFind);
+ }
+ return ERROR_SUCCESS;
+}
+
//
static int TestPartFileRead(const char * szPlainName)
{
@@ -2861,8 +2886,8 @@ int main(int argc, char * argv[])
nError = InitializeMpqDirectory(argv, argc);
// Not a test, but rather a tool for creating links to duplicated files
- if(nError == ERROR_SUCCESS)
- nError = FindFilePairs(ForEachFile_CreateArchiveLink, "2004 - WoW\\16965", "2004 - WoW\\17658");
+// if(nError == ERROR_SUCCESS)
+// nError = FindFilePairs(ForEachFile_CreateArchiveLink, "2004 - WoW\\06080", "2004 - WoW\\06299");
// Search all testing archives and verify their SHA1 hash
if(nError == ERROR_SUCCESS)
@@ -2872,6 +2897,10 @@ int main(int argc, char * argv[])
if(nError == ERROR_SUCCESS)
nError = TestOpenLocalFile("ListFile_Blizzard.txt");
+ // Search in listfile
+ if(nError == ERROR_SUCCESS)
+ nError = TestSearchListFile("ListFile_Blizzard.txt");
+
// Test reading partial file
if(nError == ERROR_SUCCESS)
nError = TestPartFileRead("MPQ_2009_v2_WoW_patch.MPQ.part");
@@ -2882,6 +2911,10 @@ int main(int argc, char * argv[])
// Open an empty archive (found in WoW cache - it's just a header)
if(nError == ERROR_SUCCESS)
+ nError = TestOpenArchive("WoW-1.2.4-to-1.3.0-enGB-patch.exe");
+
+ // Open an empty archive (found in WoW cache - it's just a header)
+ if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_2012_v2_EmptyMpq.MPQ");
// Open an empty archive (created artificially - it's just a header)