TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Common.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* CascCommon.h Copyright (c) Ladislav Zezula 2014 */
3 /*---------------------------------------------------------------------------*/
4 /* Common functions for CascLib */
5 /*---------------------------------------------------------------------------*/
6 /* Date Ver Who Comment */
7 /* -------- ---- --- ------- */
8 /* 29.04.14 1.00 Lad The first version of CascCommon.h */
9 /*****************************************************************************/
10 
11 #ifndef __COMMON_H__
12 #define __COMMON_H__
13 
14 //-----------------------------------------------------------------------------
15 // Common macros
16 
17 // Macro for building 64-bit file offset from two 32-bit
18 #define MAKE_OFFSET64(hi, lo) (((ULONGLONG)hi << 32) | (ULONGLONG)lo)
19 
20 #ifndef ALIGN_TO_SIZE
21 #define ALIGN_TO_SIZE(x, a) (((x) + (a)-1) & ~((a)-1))
22 #endif
23 
24 //-----------------------------------------------------------------------------
25 // Conversion tables
26 
27 extern unsigned char AsciiToLowerTable_Slash[256];
28 extern unsigned char AsciiToUpperTable_BkSlash[256];
29 extern unsigned char IntToHexChar[];
30 
31 //-----------------------------------------------------------------------------
32 // String manipulation
33 
34 void CopyString(char * szTarget, const char * szSource, size_t cchLength);
35 void CopyString(wchar_t * szTarget, const char * szSource, size_t cchLength);
36 void CopyString(char * szTarget, const wchar_t * szSource, size_t cchLength);
37 
38 char * CascNewStr(const char * szString, size_t nCharsToReserve);
39 wchar_t * CascNewStr(const wchar_t * szString, size_t nCharsToReserve);
40 
41 TCHAR * CascNewStrFromAnsi(const char * szBegin, const char * szEnd);
42 
43 TCHAR * CombinePath(const TCHAR * szPath, const TCHAR * szSubDir);
44 TCHAR * CombinePathAndString(const TCHAR * szPath, const char * szString, size_t nLength);
45 
46 size_t NormalizeFileName_UpperBkSlash(char * szNormName, const char * szFileName, size_t cchMaxChars);
47 size_t NormalizeFileName_LowerSlash(char * szNormName, const char * szFileName, size_t cchMaxChars);
48 
49 ULONGLONG CalcFileNameHash(const char * szFileName);
50 
51 int ConvertDigitToInt32(const TCHAR * szString, PDWORD PtrValue);
52 int ConvertStringToInt08(const char * szString, PDWORD PtrValue);
53 int ConvertStringToInt32(const TCHAR * szString, size_t nMaxDigits, PDWORD PtrValue);
54 int ConvertStringToBinary(const char * szString, size_t nMaxDigits, LPBYTE pbBinary);
55 char * StringFromBinary(LPBYTE pbBinary, size_t cbBinary, char * szBuffer);
56 char * StringFromMD5(LPBYTE md5, char * szBuffer);
57 
58 //-----------------------------------------------------------------------------
59 // File name utilities
60 
61 bool CheckWildCard(const char * szString, const char * szWildCard);
62 const wchar_t * GetPlainFileName(const wchar_t * szFileName);
63 const char * GetPlainFileName(const char * szFileName);
64 
65 //-----------------------------------------------------------------------------
66 // Hashing functions
67 
68 ULONGLONG HashStringJenkins(const char * szFileName);
69 
70 bool IsValidMD5(LPBYTE pbMd5);
71 void CalculateDataBlockHash(void * pvDataBlock, DWORD cbDataBlock, LPBYTE md5_hash);
72 bool VerifyDataBlockHash(void * pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5);
73 
74 //-----------------------------------------------------------------------------
75 // Scanning a directory
76 
77 typedef bool (*INDEX_FILE_FOUND)(const TCHAR * szFileName, PDWORD IndexArray, PDWORD OldIndexArray, void * pvContext);
78 
79 bool DirectoryExists(const TCHAR * szDirectory);
80 
82  const TCHAR * szIndexPath,
83  INDEX_FILE_FOUND pfnOnFileFound,
84  PDWORD IndexArray,
85  PDWORD OldIndexArray,
86  void * pvContext
87  );
88 
89 #endif // __COMMON_H__
size_t NormalizeFileName_UpperBkSlash(char *szNormName, const char *szFileName, size_t cchMaxChars)
Definition: Common.cpp:250
void CalculateDataBlockHash(void *pvDataBlock, DWORD cbDataBlock, LPBYTE md5_hash)
Definition: Common.cpp:512
bool DirectoryExists(const TCHAR *szDirectory)
Definition: Directory.cpp:18
unsigned long long ULONGLONG
Definition: CascPort.h:144
DWORD * PDWORD
Definition: CascPort.h:151
int ConvertStringToInt32(const TCHAR *szString, size_t nMaxDigits, PDWORD PtrValue)
Definition: Common.cpp:303
char TCHAR
Definition: CascPort.h:148
unsigned char IntToHexChar[]
Definition: Common.cpp:62
bool CheckWildCard(const char *szString, const char *szWildCard)
Definition: Common.cpp:426
BYTE * LPBYTE
Definition: CascPort.h:152
int ScanIndexDirectory(const TCHAR *szIndexPath, INDEX_FILE_FOUND pfnOnFileFound, PDWORD IndexArray, PDWORD OldIndexArray, void *pvContext)
Definition: Directory.cpp:41
#define bool
Definition: CascPort.h:16
TCHAR * CascNewStrFromAnsi(const char *szBegin, const char *szEnd)
Definition: Common.cpp:140
ULONGLONG CalcFileNameHash(const char *szFileName)
Definition: Common.cpp:260
const wchar_t * GetPlainFileName(const wchar_t *szFileName)
Definition: Common.cpp:398
unsigned char AsciiToLowerTable_Slash[256]
Definition: Common.cpp:20
int ConvertDigitToInt32(const TCHAR *szString, PDWORD PtrValue)
Definition: Common.cpp:275
int ConvertStringToInt08(const char *szString, PDWORD PtrValue)
Definition: Common.cpp:287
char * CascNewStr(const char *szString, size_t nCharsToReserve)
Definition: Common.cpp:102
unsigned int DWORD
Definition: CascPort.h:139
char * StringFromBinary(LPBYTE pbBinary, size_t cbBinary, char *szBuffer)
Definition: Common.cpp:372
bool(* INDEX_FILE_FOUND)(const TCHAR *szFileName, PDWORD IndexArray, PDWORD OldIndexArray, void *pvContext)
Definition: Common.h:77
size_t NormalizeFileName_LowerSlash(char *szNormName, const char *szFileName, size_t cchMaxChars)
Definition: Common.cpp:255
TCHAR * CombinePathAndString(const TCHAR *szPath, const char *szString, size_t nLength)
Definition: Common.cpp:219
unsigned char AsciiToUpperTable_BkSlash[256]
Definition: Common.cpp:42
bool VerifyDataBlockHash(void *pvDataBlock, DWORD cbDataBlock, LPBYTE expected_md5)
Definition: Common.cpp:494
void CopyString(char *szTarget, const char *szSource, size_t cchLength)
Definition: Common.cpp:84
ULONGLONG HashStringJenkins(const char *szFileName)
int ConvertStringToBinary(const char *szString, size_t nMaxDigits, LPBYTE pbBinary)
Definition: Common.cpp:338
char * StringFromMD5(LPBYTE md5, char *szBuffer)
Definition: Common.cpp:390
bool IsValidMD5(LPBYTE pbMd5)
Definition: Common.cpp:484
TCHAR * CombinePath(const TCHAR *szPath, const TCHAR *szSubDir)
Definition: Common.cpp:157