void * ListFile_OpenExternal(const TCHAR * szListFile) { TListFileCache * pCache; TFileStream * pStream; ULONGLONG FileSize = 0; // Open the external listfile pStream = FileStream_OpenFile(szListFile, STREAM_FLAG_READ_ONLY); if(pStream != NULL) { // Retrieve the size of the external listfile FileStream_GetSize(pStream, &FileSize); if(0 < FileSize && FileSize <= 0xFFFFFFFF) { // Create the cache for the listfile pCache = CreateListFileCache(ReloadCache_ExternalFile, CloseStream_ExternalFile, pStream, (DWORD)FileSize); if(pCache != NULL) return pCache; } // Close the file stream FileStream_Close(pStream); } return NULL; }
void * ListFile_OpenExternal(const TCHAR * szListFile) { PLISTFILE_CACHE pCache = NULL; TFileStream * pStream; ULONGLONG FileSize = 0; // Open the external listfile pStream = FileStream_OpenFile(szListFile, STREAM_FLAG_READ_ONLY); if(pStream != NULL) { // Retrieve the size of the external listfile FileStream_GetSize(pStream, &FileSize); if(0 < FileSize && FileSize <= 0x30000000) { // Create the in-memory cache for the entire listfile // The listfile does not have any data loaded yet pCache = CreateListFileCache((DWORD)FileSize); if(pCache != NULL) { if(!FileStream_Read(pStream, NULL, pCache->pBegin, (DWORD)FileSize)) { ListFile_Free(pCache); pCache = NULL; } } } // Close the file stream FileStream_Close(pStream); } return pCache; }
void * ListFile_FromBuffer(LPBYTE pbBuffer, DWORD cbBuffer) { PLISTFILE_CACHE pCache = NULL; // Create the in-memory cache for the entire listfile // The listfile does not have any data loaded yet pCache = CreateListFileCache(cbBuffer); if(pCache != NULL) memcpy(pCache->pBegin, pbBuffer, cbBuffer); return pCache; }
static int SFileAddArbitraryListFile( TMPQArchive * ha, HANDLE hListFile) { TListFileCache * pCache = NULL; size_t nLength; char szFileName[MAX_PATH]; // Create the listfile cache for that file pCache = CreateListFileCache(hListFile, NULL); if(pCache != NULL) { // Load the node list. Add the node for every locale in the archive while((nLength = ReadListFileLine(pCache, szFileName, sizeof(szFileName))) > 0) SListFileCreateNodeForAllLocales(ha, szFileName); // Delete the cache FreeListFileCache(pCache); } return (pCache != NULL) ? ERROR_SUCCESS : ERROR_FILE_CORRUPT; }
HANDLE WINAPI SListFileFindFirstFile(HANDLE hMpq, const char * szListFile, const char * szMask, SFILE_FIND_DATA * lpFindFileData) { TListFileCache * pCache = NULL; HANDLE hListFile = NULL; size_t nLength = 0; DWORD dwSearchScope = SFILE_OPEN_LOCAL_FILE; int nError = ERROR_SUCCESS; // Initialize the structure with zeros memset(lpFindFileData, 0, sizeof(SFILE_FIND_DATA)); // If the szListFile is NULL, it means we have to open internal listfile if(szListFile == NULL) { // Use SFILE_OPEN_ANY_LOCALE for listfile. This will allow us to load // the listfile even if there is only non-neutral version of the listfile in the MPQ dwSearchScope = SFILE_OPEN_ANY_LOCALE; szListFile = LISTFILE_NAME; } // Open the local/internal listfile if(!SFileOpenFileEx(hMpq, szListFile, dwSearchScope, &hListFile)) nError = GetLastError(); // Load the listfile to cache if(nError == ERROR_SUCCESS) { pCache = CreateListFileCache(hListFile, szMask); if(pCache == NULL) nError = ERROR_FILE_CORRUPT; } // Perform file search if(nError == ERROR_SUCCESS) { for(;;) { // Read the (next) line nLength = ReadListFileLine(pCache, lpFindFileData->cFileName, sizeof(lpFindFileData->cFileName)); if(nLength == 0) { nError = ERROR_NO_MORE_FILES; break; } // If some mask entered, check it if(CheckWildCard(lpFindFileData->cFileName, pCache->szMask)) break; } } // Cleanup & exit if(nError != ERROR_SUCCESS) { memset(lpFindFileData, 0, sizeof(SFILE_FIND_DATA)); SetLastError(nError); } if(pCache != NULL) FreeListFileCache(pCache); if(hListFile != NULL) SFileCloseFile(hListFile); return (HANDLE)pCache; }