diff options
-rw-r--r-- | src/SFileFindFile.cpp | 39 | ||||
-rw-r--r-- | test/StormTest.cpp | 33 |
2 files changed, 43 insertions, 29 deletions
diff --git a/src/SFileFindFile.cpp b/src/SFileFindFile.cpp index 18bf4d5..3533549 100644 --- a/src/SFileFindFile.cpp +++ b/src/SFileFindFile.cpp @@ -175,26 +175,30 @@ static bool FileWasFoundBefore( static TFileEntry * FindPatchEntry(TMPQArchive * ha, TFileEntry * pFileEntry)
{
- TFileEntry * pPatchEntry = NULL;
+ TFileEntry * pPatchEntry = pFileEntry;
TFileEntry * pTempEntry;
char szFileName[MAX_PATH+1];
- // Go while there are patches
- while(ha->haPatch != NULL)
+ // Can't find patch entry for a file that doesn't have name
+ if(pFileEntry->szFileName != NULL && pFileEntry->szFileName[0] != 0)
{
- // Move to the patch archive
- ha = ha->haPatch;
- szFileName[0] = 0;
-
- // Prepare the prefix for the file name
- if(ha->pPatchPrefix != NULL)
- StringCopyA(szFileName, ha->pPatchPrefix->szPatchPrefix, MAX_PATH);
- StringCatA(szFileName, pFileEntry->szFileName, MAX_PATH);
-
- // Try to find the file there
- pTempEntry = GetFileEntryExact(ha, szFileName, 0, NULL);
- if(pTempEntry != NULL)
- pPatchEntry = pTempEntry;
+ // Go while there are patches
+ while(ha->haPatch != NULL)
+ {
+ // Move to the patch archive
+ ha = ha->haPatch;
+ szFileName[0] = 0;
+
+ // Prepare the prefix for the file name
+ if(ha->pPatchPrefix != NULL)
+ StringCopyA(szFileName, ha->pPatchPrefix->szPatchPrefix, MAX_PATH);
+ StringCatA(szFileName, pFileEntry->szFileName, MAX_PATH);
+
+ // Try to find the file there
+ pTempEntry = GetFileEntryExact(ha, szFileName, 0, NULL);
+ if(pTempEntry != NULL)
+ pPatchEntry = pTempEntry;
+ }
}
// Return the found patch entry
@@ -225,9 +229,8 @@ static bool DoMPQSearch_FileEntry( // DebugBreak();
// Find a patch to this file
+ // Note: This either succeeds or returns pFileEntry
pPatchEntry = FindPatchEntry(ha, pFileEntry);
- if(pPatchEntry == NULL)
- pPatchEntry = pFileEntry;
// Prepare the block index
dwBlockIndex = (DWORD)(pFileEntry - ha->pFileTable);
diff --git a/test/StormTest.cpp b/test/StormTest.cpp index afc0a9f..6a957ab 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -122,6 +122,13 @@ static const wchar_t szUnicodeName6[] = { // Arabic 0x0627, 0x0644, 0x0639, 0x0639, 0x0631, 0x0628, 0x064A, 0x0629, _T('.'), _T('m'), _T('p'), _T('q'), 0
};
+static const char * PatchList_StarCraft[] =
+{
+ "MPQ_1998_v1_StarCraft.mpq",
+ "s1-1998-BroodWar.mpq",
+ NULL
+};
+
static const char * PatchList_WoW_OldWorld13286[] =
{
"MPQ_2012_v4_OldWorld.MPQ",
@@ -4522,10 +4529,10 @@ int main(int argc, char * argv[]) // Open a partial MPQ with compressed hash table
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("part-file://MPQ_2010_v2_HashTableCompressed.MPQ.part");
-*/
-// if(nError == ERROR_SUCCESS)
-// nError = TestOpenArchive_ProtectedMap("MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.w3x", NULL, 114, "5250975ed917375fc6540d7be436d4de");
-/*
+
+ if(nError == ERROR_SUCCESS)
+ nError = TestOpenArchive_ProtectedMap("MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.w3x", NULL, 114, "5250975ed917375fc6540d7be436d4de");
+
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_2002_v1_ProtectedMap_InvalidUserData.w3x");
@@ -4561,11 +4568,11 @@ int main(int argc, char * argv[]) // Open an Warcraft III map locked by Spazy protector
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_2015_v1_MessListFile.mpq");
-*/
+
// Open an protected map
-// if(nError == ERROR_SUCCESS)
-// nError = TestOpenArchive_ProtectedMap("MPQ_2015_v1_flem1.w3x", NULL, 20, "1c4c13e627658c473e84d94371e31f37");
-/*
+ if(nError == ERROR_SUCCESS)
+ nError = TestOpenArchive_ProtectedMap("MPQ_2015_v1_flem1.w3x", NULL, 20, "1c4c13e627658c473e84d94371e31f37");
+
// Open another protected map
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive("MPQ_2016_v1_ProtectedMap_TableSizeOverflow.w3x");
@@ -4610,7 +4617,11 @@ int main(int argc, char * argv[]) // Test on an archive that has been invalidated by extending an old valid MPQ
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_Corrupt("MPQ_2013_vX_Battle.net.MPQ");
-
+*/
+ // Open a patched archive
+ if(nError == ERROR_SUCCESS)
+ nError = TestOpenArchive_Patched(PatchList_StarCraft, "music\\terran1.wav", 0);
+/*
// Open a patched archive
if(nError == ERROR_SUCCESS)
nError = TestOpenArchive_Patched(PatchList_WoW_OldWorld13286, "OldWorld\\World\\Model.blob", 2);
@@ -4722,11 +4733,11 @@ int main(int argc, char * argv[]) // Create an empty archive v4
if(nError == ERROR_SUCCESS)
nError = TestCreateArchive_EmptyMpq("StormLibTest_EmptyMpq_v4.mpq", MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES);
-*/
+
// Test creating of an archive the same way like MPQ Editor does
if(nError == ERROR_SUCCESS)
nError = TestCreateArchive_TestGaps("StormLibTest_GapsTest.mpq");
-/*
+
// Test creating of an archive with non standard file names
if(nError == ERROR_SUCCESS)
nError = TestCreateArchive_NonStdNames("StormLibTest_NonStdNames.mpq");
|