TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ListFile.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _LISTFILE_ENTRY
 
struct  _LISTFILE_MAP
 

Typedefs

typedef struct _LISTFILE_ENTRY LISTFILE_ENTRY
 
typedef struct _LISTFILE_ENTRYPLISTFILE_ENTRY
 
typedef struct _LISTFILE_MAP LISTFILE_MAP
 
typedef struct _LISTFILE_MAPPLISTFILE_MAP
 

Functions

void * ListFile_OpenExternal (const TCHAR *szListFile)
 
void * ListFile_FromBuffer (LPBYTE pbBuffer, DWORD cbBuffer)
 
bool ListFile_VerifyMD5 (void *pvListFile, LPBYTE pbHashMD5)
 
size_t ListFile_GetNextLine (void *pvListFile, const char **pszLineBegin, const char **pszLineEnd)
 
size_t ListFile_GetNextLine (void *pvListFile, char *szBuffer, size_t nMaxChars)
 
size_t ListFile_GetNext (void *pvListFile, const char *szMask, char *szBuffer, size_t nMaxChars)
 
void ListFile_Free (void *pvListFile)
 
PLISTFILE_MAP ListFile_CreateMap (const TCHAR *szListFile)
 
const char * ListFile_FindName (PLISTFILE_MAP pListMap, ULONGLONG FileNameHash)
 
void ListFile_FreeMap (PLISTFILE_MAP pListMap)
 

Typedef Documentation

typedef struct _LISTFILE_MAP LISTFILE_MAP
typedef struct _LISTFILE_ENTRY * PLISTFILE_ENTRY
typedef struct _LISTFILE_MAP * PLISTFILE_MAP

Function Documentation

PLISTFILE_MAP ListFile_CreateMap ( const TCHAR szListFile)
301 {
302  PLISTFILE_MAP pListMap = NULL;
303  void * pvListFile;
304  char szFileName[MAX_PATH+1];
305  size_t nLength;
306 
307  // Only if the listfile name has been given
308  if(szListFile != NULL)
309  {
310  // Create map for the listfile
311  pListMap = ListMap_Create();
312  if(pListMap != NULL)
313  {
314  // Open the external listfile
315  pvListFile = ListFile_OpenExternal(szListFile);
316  if(pvListFile != NULL)
317  {
318  // Go through the entire listfile and insert each name to the map
319  while((nLength = ListFile_GetNext(pvListFile, "*", szFileName, MAX_PATH)) != 0)
320  {
321  // Insert the file name to the map
322  pListMap = ListMap_InsertName(pListMap, szFileName, nLength);
323  if(pListMap == NULL)
324  break;
325  }
326 
327  // Finish the listfile map
328  pListMap = ListMap_Finish(pListMap);
329 
330  // Free the listfile
331  ListFile_Free(pvListFile);
332  }
333  }
334  }
335 
336  // Return the created map
337  return pListMap;
338 }
void * ListFile_OpenExternal(const TCHAR *szListFile)
Definition: ListFile.cpp:52
static PLISTFILE_MAP ListMap_Finish(PLISTFILE_MAP pListMap)
Definition: ListFile.cpp:268
void ListFile_Free(void *pvListFile)
Definition: ListFile.cpp:201
#define MAX_PATH
Definition: CascPort.h:160
arena_t NULL
Definition: jemalloc_internal.h:624
static PLISTFILE_MAP ListMap_InsertName(PLISTFILE_MAP pListMap, const char *szFileName, size_t nLength)
Definition: ListFile.cpp:234
size_t ListFile_GetNext(void *pvListFile, const char *szMask, char *szBuffer, size_t nMaxChars)
Definition: ListFile.cpp:172
Definition: ListFile.h:25
static PLISTFILE_MAP ListMap_Create()
Definition: ListFile.cpp:214

+ Here is the call graph for this function:

const char* ListFile_FindName ( PLISTFILE_MAP  pListMap,
ULONGLONG  FileNameHash 
)
341 {
342  PLISTFILE_ENTRY pListEntry = NULL;
343 
344  if(pListMap != NULL)
345  pListEntry = (PLISTFILE_ENTRY)Map_FindObject(pListMap->pNameMap, &FileNameHash, NULL);
346  return (pListEntry != NULL) ? pListEntry->szFileName : "";
347 }
void * Map_FindObject(PCASC_MAP pMap, void *pvKey, PDWORD PtrIndex)
Definition: Map.cpp:138
PCASC_MAP pNameMap
Definition: ListFile.h:27
arena_t NULL
Definition: jemalloc_internal.h:624
char szFileName[1]
Definition: ListFile.h:21
Definition: ListFile.h:17
struct _LISTFILE_ENTRY * PLISTFILE_ENTRY

+ Here is the call graph for this function:

void ListFile_Free ( void *  pvListFile)
202 {
203  if(pvListFile != NULL)
204  {
205  CASC_FREE(pvListFile);
206  }
207 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303

+ Here is the caller graph for this function:

void ListFile_FreeMap ( PLISTFILE_MAP  pListMap)
350 {
351  if(pListMap != NULL)
352  {
353  if(pListMap->pNameMap != NULL)
354  Map_Free(pListMap->pNameMap);
355  CASC_FREE(pListMap);
356  }
357 }
PCASC_MAP pNameMap
Definition: ListFile.h:27
void Map_Free(PCASC_MAP pMap)
Definition: Map.cpp:279
arena_t NULL
Definition: jemalloc_internal.h:624
#define CASC_FREE(ptr)
Definition: CascCommon.h:303

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* ListFile_FromBuffer ( LPBYTE  pbBuffer,
DWORD  cbBuffer 
)
87 {
88  PLISTFILE_CACHE pCache = NULL;
89 
90  // Create the in-memory cache for the entire listfile
91  // The listfile does not have any data loaded yet
92  pCache = CreateListFileCache(cbBuffer);
93  if(pCache != NULL)
94  memcpy(pCache->pBegin, pbBuffer, cbBuffer);
95 
96  return pCache;
97 }
arena_t NULL
Definition: jemalloc_internal.h:624
static PLISTFILE_CACHE CreateListFileCache(DWORD dwFileSize)
Definition: ListFile.cpp:31
char * pBegin
Definition: ListFile.cpp:20
Definition: ListFile.cpp:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ListFile_GetNext ( void *  pvListFile,
const char *  szMask,
char *  szBuffer,
size_t  nMaxChars 
)
173 {
174  size_t nLength = 0;
175  int nError = ERROR_SUCCESS;
176 
177  // Check for parameters
178  for(;;)
179  {
180  // Read the (next) line
181  nLength = ListFile_GetNextLine(pvListFile, szBuffer, nMaxChars);
182  if(nLength == 0)
183  {
184  nError = ERROR_NO_MORE_FILES;
185  break;
186  }
187 
188  // If some mask entered, check it
189  if(CheckWildCard(szBuffer, szMask))
190  {
191  nError = ERROR_SUCCESS;
192  break;
193  }
194  }
195 
196  if(nError != ERROR_SUCCESS)
197  SetLastError(nError);
198  return nLength;
199 }
bool CheckWildCard(const char *szString, const char *szWildCard)
Definition: Common.cpp:426
#define ERROR_NO_MORE_FILES
Definition: CascPort.h:215
void SetLastError(int nError)
Definition: Common.cpp:75
size_t ListFile_GetNextLine(void *pvListFile, const char **pszLineBegin, const char **pszLineEnd)
Definition: ListFile.cpp:111
#define ERROR_SUCCESS
Definition: CascPort.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t ListFile_GetNextLine ( void *  pvListFile,
const char **  pszLineBegin,
const char **  pszLineEnd 
)
112 {
113  PLISTFILE_CACHE pCache = (PLISTFILE_CACHE)pvListFile;
114  char * szExtraString = NULL;
115  char * szLineBegin;
116  char * szLineEnd;
117 
118  // Skip newlines, spaces, tabs and another non-printable stuff
119  while(pCache->pPos < pCache->pEnd && pCache->pPos[0] <= 0x20)
120  pCache->pPos++;
121 
122  // Remember the begin of the line
123  szLineBegin = pCache->pPos;
124 
125  // Copy the remaining characters
126  while(pCache->pPos < pCache->pEnd)
127  {
128  // If we have found a newline, stop loading
129  if(pCache->pPos[0] == 0x0D || pCache->pPos[0] == 0x0A)
130  break;
131 
132  // Blizzard listfiles can also contain information about patch:
133  // Pass1\Files\MacOS\unconditional\user\Background Downloader.app\Contents\Info.plist~Patch(Data#frFR#base-frFR,1326)
134  if(pCache->pPos[0] == '~')
135  szExtraString = pCache->pPos;
136 
137  // Move the position by one character forward
138  pCache->pPos++;
139  }
140 
141  // Remember the end of the line
142  szLineEnd = (szExtraString != NULL && szExtraString[0] == '~' && szExtraString[1] == 'P') ? szExtraString : pCache->pPos;
143 
144  // Give the caller the positions of the begin and end of the line
145  pszLineBegin[0] = szLineBegin;
146  pszLineEnd[0] = szLineEnd;
147  return (size_t)(szLineEnd - szLineBegin);
148 }
char * pEnd
Definition: ListFile.cpp:22
arena_t NULL
Definition: jemalloc_internal.h:624
struct _LISTFILE_CACHE * PLISTFILE_CACHE
char * pPos
Definition: ListFile.cpp:21
Definition: ListFile.cpp:18

+ Here is the caller graph for this function:

size_t ListFile_GetNextLine ( void *  pvListFile,
char *  szBuffer,
size_t  nMaxChars 
)
151 {
152  const char * szLineBegin = NULL;
153  const char * szLineEnd = NULL;
154  size_t nLength;
155 
156  // Retrieve the next line
157  nLength = ListFile_GetNextLine(pvListFile, &szLineBegin, &szLineEnd);
158 
159  // Check the length
160  if(nLength > nMaxChars)
161  {
163  return 0;
164  }
165 
166  // Copy the line to the user buffer
167  memcpy(szBuffer, szLineBegin, nLength);
168  szBuffer[nLength] = 0;
169  return nLength;
170 }
#define ERROR_INSUFFICIENT_BUFFER
Definition: CascPort.h:213
arena_t NULL
Definition: jemalloc_internal.h:624
void SetLastError(int nError)
Definition: Common.cpp:75
size_t ListFile_GetNextLine(void *pvListFile, const char **pszLineBegin, const char **pszLineEnd)
Definition: ListFile.cpp:111

+ Here is the call graph for this function:

void* ListFile_OpenExternal ( const TCHAR szListFile)
53 {
54  PLISTFILE_CACHE pCache = NULL;
55  TFileStream * pStream;
56  ULONGLONG FileSize = 0;
57 
58  // Open the external listfile
59  pStream = FileStream_OpenFile(szListFile, STREAM_FLAG_READ_ONLY);
60  if(pStream != NULL)
61  {
62  // Retrieve the size of the external listfile
63  FileStream_GetSize(pStream, &FileSize);
64  if(0 < FileSize && FileSize <= 0x30000000)
65  {
66  // Create the in-memory cache for the entire listfile
67  // The listfile does not have any data loaded yet
68  pCache = CreateListFileCache((DWORD)FileSize);
69  if(pCache != NULL)
70  {
71  if(!FileStream_Read(pStream, NULL, pCache->pBegin, (DWORD)FileSize))
72  {
73  ListFile_Free(pCache);
74  pCache = NULL;
75  }
76  }
77  }
78 
79  // Close the file stream
80  FileStream_Close(pStream);
81  }
82 
83  return pCache;
84 }
unsigned long long ULONGLONG
Definition: CascPort.h:144
bool FileStream_Read(TFileStream *pStream, ULONGLONG *pByteOffset, void *pvBuffer, DWORD dwBytesToRead)
Definition: FileStream.cpp:2551
void ListFile_Free(void *pvListFile)
Definition: ListFile.cpp:201
bool FileStream_GetSize(TFileStream *pStream, ULONGLONG *pFileSize)
Definition: FileStream.cpp:2595
arena_t NULL
Definition: jemalloc_internal.h:624
static PLISTFILE_CACHE CreateListFileCache(DWORD dwFileSize)
Definition: ListFile.cpp:31
char * pBegin
Definition: ListFile.cpp:20
void FileStream_Close(TFileStream *pStream)
Definition: FileStream.cpp:2707
unsigned int DWORD
Definition: CascPort.h:139
TFileStream * FileStream_OpenFile(const TCHAR *szFileName, DWORD dwStreamFlags)
Definition: FileStream.cpp:2384
Definition: ListFile.cpp:18
Definition: FileStream.h:153
#define STREAM_FLAG_READ_ONLY
Definition: CascLib.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ListFile_VerifyMD5 ( void *  pvListFile,
LPBYTE  pbHashMD5 
)
101 {
102  PLISTFILE_CACHE pCache = (PLISTFILE_CACHE)pvListFile;
103 
104  // Must be at the beginning
105  assert(pCache->pPos == pCache->pBegin);
106 
107  // Verify the MD5 hash for the entire block
108  return VerifyDataBlockHash(pCache->pBegin, (DWORD)(pCache->pEnd - pCache->pBegin), pbHashMD5);
109 }
char * pEnd
Definition: ListFile.cpp:22
bool VerifyDataBlockHash(void *pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5)
Definition: Common.cpp:494
struct _LISTFILE_CACHE * PLISTFILE_CACHE
char * pBegin
Definition: ListFile.cpp:20
unsigned int DWORD
Definition: CascPort.h:139
char * pPos
Definition: ListFile.cpp:21
Definition: ListFile.cpp:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function: