aboutsummaryrefslogtreecommitdiff
path: root/src/SFileFindFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFileFindFile.cpp')
-rw-r--r--src/SFileFindFile.cpp109
1 files changed, 37 insertions, 72 deletions
diff --git a/src/SFileFindFile.cpp b/src/SFileFindFile.cpp
index 0f7bd39..198f960 100644
--- a/src/SFileFindFile.cpp
+++ b/src/SFileFindFile.cpp
@@ -49,88 +49,55 @@ static TMPQSearch * IsValidSearchHandle(HANDLE hFind)
bool CheckWildCard(const char * szString, const char * szWildCard)
{
- const char * szSubString;
- int nSubStringLength;
- int nMatchCount = 0;
+ const char * szWildCardPtr;
- // When the mask is empty, it never matches
- if(szWildCard == NULL || *szWildCard == 0)
- return false;
-
- // If the wildcard contains just "*", then it always matches
- if(szWildCard[0] == '*' && szWildCard[1] == 0)
- return true;
-
- // Do normal test
for(;;)
{
// If there is '?' in the wildcard, we skip one char
- while(*szWildCard == '?')
+ while(szWildCard[0] == '?')
{
+ if(szString[0] == 0)
+ return false;
+
szWildCard++;
szString++;
}
- // If there is '*', means zero or more chars. We have to
- // find the sequence after '*'
- if(*szWildCard == '*')
+ // Handle '*'
+ szWildCardPtr = szWildCard;
+ if(szWildCardPtr[0] != 0)
{
- // More stars is equal to one star
- while(*szWildCard == '*' || *szWildCard == '?')
- szWildCard++;
-
- // If we found end of the wildcard, it's a match
- if(*szWildCard == 0)
- return true;
+ if(szWildCardPtr[0] == '*')
+ {
+ szWildCardPtr++;
- // Determine the length of the substring in szWildCard
- szSubString = szWildCard;
- while(*szSubString != 0 && *szSubString != '?' && *szSubString != '*')
- szSubString++;
- nSubStringLength = (int)(szSubString - szWildCard);
- nMatchCount = 0;
+ if(szWildCardPtr[0] == '*')
+ continue;
- // Now we have to find a substring in szString,
- // that matches the substring in szWildCard
- while(*szString != 0)
- {
- // Calculate match count
- while(nMatchCount < nSubStringLength)
- {
- if(AsciiToUpperTable[(BYTE)szString[nMatchCount]] != AsciiToUpperTable[(BYTE)szWildCard[nMatchCount]])
- break;
- if(szString[nMatchCount] == 0)
- break;
- nMatchCount++;
- }
+ if(szWildCardPtr[0] == 0)
+ return true;
- // If the match count has reached substring length, we found a match
- if(nMatchCount == nSubStringLength)
+ if(AsciiToUpperTable[szWildCardPtr[0]] == AsciiToUpperTable[szString[0]])
{
- szWildCard += nMatchCount;
- szString += nMatchCount;
- break;
+ if(CheckWildCard(szString, szWildCardPtr))
+ return true;
}
-
- // No match, move to the next char in szString
- nMatchCount = 0;
- szString++;
}
- }
- else
- {
- // If we came to the end of the string, compare it to the wildcard
- if(AsciiToUpperTable[(BYTE)*szString] != AsciiToUpperTable[(BYTE)*szWildCard])
- return false;
+ else
+ {
+ if(AsciiToUpperTable[szWildCardPtr[0]] != AsciiToUpperTable[szString[0]])
+ return false;
- // If we arrived to the end of the string, it's a match
- if(*szString == 0)
- return true;
+ szWildCard = szWildCardPtr + 1;
+ }
- // Otherwise, continue in comparing
- szWildCard++;
- szString++;
+ if(szString[0] == 0)
+ return false;
}
+
+ if(szString[0] == 0)
+ return true;
+ szString++;
}
}
@@ -218,7 +185,6 @@ static TFileEntry * FindPatchEntry(TMPQArchive * ha, TFileEntry * pFileEntry)
TFileEntry * pPatchEntry = NULL;
TFileEntry * pTempEntry;
char szFileName[MAX_PATH];
- LCID lcLocale = pFileEntry->lcLocale;
// Go while there are patches
while(ha->haPatch != NULL)
@@ -233,7 +199,7 @@ static TFileEntry * FindPatchEntry(TMPQArchive * ha, TFileEntry * pFileEntry)
strcat(szFileName, pFileEntry->szFileName);
// Try to find the file there
- pTempEntry = GetFileEntryExact(ha, szFileName, lcLocale);
+ pTempEntry = GetFileEntryExact(ha, szFileName, 0, NULL);
if(pTempEntry != NULL)
pPatchEntry = pTempEntry;
}
@@ -251,7 +217,7 @@ static int DoMPQSearch(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData)
TFileEntry * pFileEntry;
const char * szFileName;
HANDLE hFile;
- char szPseudoName[20];
+ char szNameBuff[MAX_PATH];
DWORD dwBlockIndex;
size_t nPrefixLength;
@@ -293,11 +259,11 @@ static int DoMPQSearch(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData)
if(szFileName == NULL)
{
// Open the file by its pseudo-name.
- // This also generates the file name with a proper extension
- sprintf(szPseudoName, "File%08u.xxx", (unsigned int)dwBlockIndex);
- if(SFileOpenFileEx((HANDLE)hs->ha, szPseudoName, SFILE_OPEN_BASE_FILE, &hFile))
+ sprintf(szNameBuff, "File%08u.xxx", (unsigned int)dwBlockIndex);
+ if(SFileOpenFileEx((HANDLE)hs->ha, szNameBuff, SFILE_OPEN_BASE_FILE, &hFile))
{
- szFileName = (pFileEntry->szFileName != NULL) ? pFileEntry->szFileName : szPseudoName;
+ SFileGetFileName(hFile, szNameBuff);
+ szFileName = szNameBuff;
SFileCloseFile(hFile);
}
}
@@ -309,12 +275,11 @@ static int DoMPQSearch(TMPQSearch * hs, SFILE_FIND_DATA * lpFindFileData)
if(CheckWildCard(szFileName + nPrefixLength, hs->szSearchMask))
{
// Fill the found entry. hash entry and block index are taken from the base MPQ
- lpFindFileData->dwHashIndex = pFileEntry->dwHashIndex;
lpFindFileData->dwBlockIndex = dwBlockIndex;
lpFindFileData->dwFileSize = pPatchEntry->dwFileSize;
lpFindFileData->dwFileFlags = pPatchEntry->dwFlags;
lpFindFileData->dwCompSize = pPatchEntry->dwCmpSize;
- lpFindFileData->lcLocale = pPatchEntry->lcLocale;
+ lpFindFileData->lcLocale = 0; // pPatchEntry->lcLocale;
// Fill the filetime
lpFindFileData->dwFileTimeHi = (DWORD)(pPatchEntry->FileTime >> 32);