TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CascLib.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* CascLib.h Copyright (c) Ladislav Zezula 2014 */
3 /*---------------------------------------------------------------------------*/
4 /* CascLib library v 1.00 */
5 /* */
6 /* Author : Ladislav Zezula */
7 /* E-mail : [email protected] */
8 /* WWW : http://www.zezula.net */
9 /*---------------------------------------------------------------------------*/
10 /* Date Ver Who Comment */
11 /* -------- ---- --- ------- */
12 /* 29.04.14 1.00 Lad Created */
13 /*****************************************************************************/
14 
15 #ifndef __CASCLIB_H__
16 #define __CASCLIB_H__
17 
18 #ifdef _MSC_VER
19 #pragma warning(disable:4668) // 'XXX' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
20 #pragma warning(disable:4820) // 'XXX' : '2' bytes padding added after data member 'XXX::yyy'
21 #endif
22 
23 #include "CascPort.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 //-----------------------------------------------------------------------------
30 // Defines
31 
32 #define CASCLIB_VERSION 0x0100 // Current version of CascLib (1.0)
33 #define CASCLIB_VERSION_STRING "1.00" // String version of CascLib version
34 
35 #define ERROR_UNKNOWN_FILE_KEY 10001 // Returned by encrypted stream when can't find file key
36 #define ERROR_FILE_INCOMPLETE 10006 // The required file part is missing
37 
38 // Values for CascOpenStorage
39 #define CASC_STOR_XXXXX 0x00000001 // Not used
40 
41 // Values for CascOpenFile
42 #define CASC_OPEN_BY_ENCODING_KEY 0x00000001 // The name is just the encoding key; skip ROOT file processing
43 
44 // Flags for file stream
45 #define BASE_PROVIDER_FILE 0x00000000 // Base data source is a file
46 #define BASE_PROVIDER_MAP 0x00000001 // Base data source is memory-mapped file
47 #define BASE_PROVIDER_HTTP 0x00000002 // Base data source is a file on web server
48 #define BASE_PROVIDER_MASK 0x0000000F // Mask for base provider value
49 
50 #define STREAM_PROVIDER_FLAT 0x00000000 // Stream is linear with no offset mapping
51 #define STREAM_PROVIDER_PARTIAL 0x00000010 // Stream is partial file (.part)
52 #define STREAM_PROVIDER_ENCRYPTED 0x00000020 // Stream is an encrypted archive
53 #define STREAM_PROVIDER_BLOCK4 0x00000030 // 0x4000 per block, text MD5 after each block, max 0x2000 blocks per file
54 #define STREAM_PROVIDER_MASK 0x000000F0 // Mask for stream provider value
55 
56 #define STREAM_FLAG_READ_ONLY 0x00000100 // Stream is read only
57 #define STREAM_FLAG_WRITE_SHARE 0x00000200 // Allow write sharing when open for write
58 #define STREAM_FLAG_USE_BITMAP 0x00000400 // If the file has a file bitmap, load it and use it
59 #define STREAM_OPTIONS_MASK 0x0000FF00 // Mask for stream options
60 
61 #define STREAM_PROVIDERS_MASK 0x000000FF // Mask to get stream providers
62 #define STREAM_FLAGS_MASK 0x0000FFFF // Mask for all stream flags (providers+options)
63 
64 #define CASC_LOCALE_ALL 0xFFFFFFFF
65 #define CASC_LOCALE_NONE 0x00000000
66 #define CASC_LOCALE_UNKNOWN1 0x00000001
67 #define CASC_LOCALE_ENUS 0x00000002
68 #define CASC_LOCALE_KOKR 0x00000004
69 #define CASC_LOCALE_RESERVED 0x00000008
70 #define CASC_LOCALE_FRFR 0x00000010
71 #define CASC_LOCALE_DEDE 0x00000020
72 #define CASC_LOCALE_ZHCN 0x00000040
73 #define CASC_LOCALE_ESES 0x00000080
74 #define CASC_LOCALE_ZHTW 0x00000100
75 #define CASC_LOCALE_ENGB 0x00000200
76 #define CASC_LOCALE_ENCN 0x00000400
77 #define CASC_LOCALE_ENTW 0x00000800
78 #define CASC_LOCALE_ESMX 0x00001000
79 #define CASC_LOCALE_RURU 0x00002000
80 #define CASC_LOCALE_PTBR 0x00004000
81 #define CASC_LOCALE_ITIT 0x00008000
82 #define CASC_LOCALE_PTPT 0x00010000
83 
84 #define CASC_LOCALE_BIT_ENUS 0x01
85 #define CASC_LOCALE_BIT_KOKR 0x02
86 #define CASC_LOCALE_DUAL_LANG 0x03
87 #define CASC_LOCALE_BIT_FRFR 0x04
88 #define CASC_LOCALE_BIT_DEDE 0x05
89 #define CASC_LOCALE_BIT_ZHCN 0x06
90 #define CASC_LOCALE_BIT_ESES 0x07
91 #define CASC_LOCALE_BIT_ZHTW 0x08
92 #define CASC_LOCALE_BIT_ENGB 0x09
93 #define CASC_LOCALE_BIT_ENCN 0x0A
94 #define CASC_LOCALE_BIT_ENTW 0x0B
95 #define CASC_LOCALE_BIT_ESMX 0x0C
96 #define CASC_LOCALE_BIT_RURU 0x0D
97 #define CASC_LOCALE_BIT_PTBR 0x0E
98 #define CASC_LOCALE_BIT_ITIT 0x0F
99 #define CASC_LOCALE_BIT_PTPT 0x10
100 
101 
102 #define MAX_CASC_KEY_LENGTH 0x10 // Maximum length of the key (equal to MD5 hash)
103 
104 #ifndef MD5_HASH_SIZE
105 #define MD5_HASH_SIZE 0x10
106 #define MD5_STRING_SIZE 0x20
107 #endif
108 
109 #ifndef SHA1_DIGEST_SIZE
110 #define SHA1_DIGEST_SIZE 0x14 // 160 bits
111 #endif
112 
113 #ifndef LANG_NEUTRAL
114 #define LANG_NEUTRAL 0x00 // Neutral locale
115 #endif
116 
117 // Return value for CascGetFileSize and CascSetFilePointer
118 #define CASC_INVALID_SIZE 0xFFFFFFFF
119 #define CASC_INVALID_POS 0xFFFFFFFF
120 
121 // Flags for CascGetStorageInfo
122 #define CASC_FEATURE_LISTFILE 0x00000001 // The storage supports listfile
123 
124 //-----------------------------------------------------------------------------
125 // Structures
126 
128 {
134 
136 
137 
138 typedef struct _QUERY_KEY
139 {
143 
144 // Structure for SFileFindFirstFile and SFileFindNextFile
145 typedef struct _CASC_FIND_DATA
146 {
147  char szFileName[MAX_PATH]; // Full name of the found file
148  char * szPlainName; // Plain name of the found file
149  BYTE EncodingKey[MD5_HASH_SIZE]; // Encoding key
150  DWORD dwLocaleFlags; // Locale flags (WoW only)
151  DWORD dwFileSize; // Size of the file
152 
154 
155 //-----------------------------------------------------------------------------
156 // Callback functions
157 
158 typedef struct TFileStream TFileStream;
159 typedef void (WINAPI * STREAM_DOWNLOAD_CALLBACK)(void * pvUserData, ULONGLONG ByteOffset, DWORD dwTotalBytes);
160 
161 //-----------------------------------------------------------------------------
162 // We have our own qsort implementation, optimized for sorting array of pointers
163 
164 void qsort_pointer_array(void ** base, size_t num, int (*compare)(const void *, const void *, const void *), const void * context);
165 
166 //-----------------------------------------------------------------------------
167 // Functions for storage manipulation
168 
169 bool WINAPI CascOpenStorage(const TCHAR * szDataPath, DWORD dwLocaleMask, HANDLE * phStorage);
170 bool WINAPI CascGetStorageInfo(HANDLE hStorage, CASC_STORAGE_INFO_CLASS InfoClass, void * pvStorageInfo, size_t cbStorageInfo, size_t * pcbLengthNeeded);
171 bool WINAPI CascCloseStorage(HANDLE hStorage);
172 
173 bool WINAPI CascOpenFileByIndexKey(HANDLE hStorage, PQUERY_KEY pIndexKey, DWORD dwFlags, HANDLE * phFile);
174 bool WINAPI CascOpenFileByEncodingKey(HANDLE hStorage, PQUERY_KEY pEncodingKey, DWORD dwFlags, HANDLE * phFile);
175 bool WINAPI CascOpenFile(HANDLE hStorage, const char * szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE * phFile);
176 DWORD WINAPI CascGetFileSize(HANDLE hFile, PDWORD pdwFileSizeHigh);
177 DWORD WINAPI CascSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHigh, DWORD dwMoveMethod);
178 bool WINAPI CascReadFile(HANDLE hFile, void * lpBuffer, DWORD dwToRead, PDWORD pdwRead);
179 bool WINAPI CascCloseFile(HANDLE hFile);
180 
181 HANDLE WINAPI CascFindFirstFile(HANDLE hStorage, const char * szMask, PCASC_FIND_DATA pFindData, const TCHAR * szListFile);
182 bool WINAPI CascFindNextFile(HANDLE hFind, PCASC_FIND_DATA pFindData);
183 bool WINAPI CascFindClose(HANDLE hFind);
184 
185 //-----------------------------------------------------------------------------
186 // GetLastError/SetLastError support for non-Windows platform
187 
188 #ifndef PLATFORM_WINDOWS
189 
190 int GetLastError();
191 void SetLastError(int nError);
192 
193 #endif // PLATFORM_WINDOWS
194 
195 #ifdef __cplusplus
196 } // extern "C"
197 #endif
198 
199 #endif // __CASCLIB_H__
Definition: CascLib.h:131
DWORD WINAPI CascSetFilePointer(HANDLE hFile, LONG lFilePos, LONG *plFilePosHigh, DWORD dwMoveMethod)
Definition: CascReadFile.cpp:395
Definition: CascLib.h:132
void * HANDLE
Definition: CascPort.h:146
unsigned long long ULONGLONG
Definition: CascPort.h:144
DWORD * PDWORD
Definition: CascPort.h:151
char * szPlainName
Definition: CascLib.h:148
Definition: CascLib.h:138
#define MAX_PATH
Definition: CascPort.h:160
HANDLE WINAPI CascFindFirstFile(HANDLE hStorage, const char *szMask, PCASC_FIND_DATA pFindData, const TCHAR *szListFile)
Definition: CascFindFile.cpp:248
char TCHAR
Definition: CascPort.h:148
void qsort_pointer_array(void **base, size_t num, int(*compare)(const void *, const void *, const void *), const void *context)
Definition: Common.cpp:533
struct _QUERY_KEY QUERY_KEY
_CASC_STORAGE_INFO_CLASS
Definition: CascLib.h:127
struct _CASC_FIND_DATA * PCASC_FIND_DATA
int LONG
Definition: CascPort.h:138
Definition: CascLib.h:129
BYTE * LPBYTE
Definition: CascPort.h:152
bool WINAPI CascOpenFileByIndexKey(HANDLE hStorage, PQUERY_KEY pIndexKey, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:150
#define WINAPI
Definition: CascPort.h:163
Definition: CascLib.h:145
DWORD cbData
Definition: CascLib.h:141
DWORD dwFileSize
Definition: CascLib.h:151
#define MD5_HASH_SIZE
Definition: CascLib.h:105
bool WINAPI CascCloseStorage(HANDLE hStorage)
Definition: CascOpenStorage.cpp:1133
Definition: CascLib.h:130
void SetLastError(int nError)
Definition: Common.cpp:75
bool WINAPI CascGetStorageInfo(HANDLE hStorage, CASC_STORAGE_INFO_CLASS InfoClass, void *pvStorageInfo, size_t cbStorageInfo, size_t *pcbLengthNeeded)
Definition: CascOpenStorage.cpp:1075
TCHAR * szFileName
Definition: FileStream.h:182
LPBYTE pbData
Definition: CascLib.h:140
void(WINAPI * STREAM_DOWNLOAD_CALLBACK)(void *pvUserData, ULONGLONG ByteOffset, DWORD dwTotalBytes)
Definition: CascLib.h:159
BYTE EncodingKey[MD5_HASH_SIZE]
Definition: CascLib.h:149
DWORD WINAPI CascGetFileSize(HANDLE hFile, PDWORD pdwFileSizeHigh)
Definition: CascReadFile.cpp:367
enum _CASC_STORAGE_INFO_CLASS * PCASC_STORAGE_INFO_CLASS
unsigned int DWORD
Definition: CascPort.h:139
bool WINAPI CascFindNextFile(HANDLE hFind, PCASC_FIND_DATA pFindData)
Definition: CascFindFile.cpp:293
char szFileName[MAX_PATH]
Definition: CascLib.h:147
int GetLastError()
Definition: Common.cpp:70
bool WINAPI CascFindClose(HANDLE hFind)
Definition: CascFindFile.cpp:310
bool WINAPI CascCloseFile(HANDLE hFile)
Definition: CascOpenFile.cpp:273
DWORD dwLocaleFlags
Definition: CascLib.h:150
DWORD dwFlags
Definition: FileStream.h:187
bool WINAPI CascOpenFileByEncodingKey(HANDLE hStorage, PQUERY_KEY pEncodingKey, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:173
bool WINAPI CascReadFile(HANDLE hFile, void *lpBuffer, DWORD dwToRead, PDWORD pdwRead)
Definition: CascReadFile.cpp:459
Definition: FileStream.h:153
enum _CASC_STORAGE_INFO_CLASS CASC_STORAGE_INFO_CLASS
struct _QUERY_KEY * PQUERY_KEY
bool WINAPI CascOpenStorage(const TCHAR *szDataPath, DWORD dwLocaleMask, HANDLE *phStorage)
Definition: CascOpenStorage.cpp:1011
unsigned char BYTE
Definition: CascPort.h:136
Definition: CascLib.h:133
struct _CASC_FIND_DATA CASC_FIND_DATA
bool WINAPI CascOpenFile(HANDLE hStorage, const char *szFileName, DWORD dwLocale, DWORD dwFlags, HANDLE *phFile)
Definition: CascOpenFile.cpp:196