-
Notifications
You must be signed in to change notification settings - Fork 1
/
wcx_mpq.h
286 lines (242 loc) · 11.1 KB
/
wcx_mpq.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*****************************************************************************/
/* wcx_mpq.h Copyright (c) Ladislav Zezula 2003 */
/*---------------------------------------------------------------------------*/
/* Main header file for the wcx_mpq plugin */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* xx.xx.xx 0.00 Pol Created by Konstantin Polyakov */
/* 13.07.03 1.00 Lad Derived from wcxapi.h */
/*****************************************************************************/
#ifndef __WCX_MPQ_H__
#define __WCX_MPQ_H__
#pragma warning (disable: 4091) // 4091: 'typedef ': ignored on left of 'tagDTI_ADTIWUI' when no variable is declared
#include <tchar.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <strsafe.h>
// Include StormLib
#include "StormLib.h"
#include "Utils.h" // Utils functions
#include "TStringConvert.h" // String convertions
//-----------------------------------------------------------------------------
// Defines
/* Error codes returned to calling application */
#define E_END_ARCHIVE 10 // No more files in archive
#define E_NO_MEMORY 11 // Not enough memory
#define E_BAD_DATA 12 // Data is bad
#define E_BAD_ARCHIVE 13 // CRC error in archive data
#define E_UNKNOWN_FORMAT 14 // Archive format unknown
#define E_EOPEN 15 // Cannot open existing file
#define E_ECREATE 16 // Cannot create file
#define E_ECLOSE 17 // Error closing file
#define E_EREAD 18 // Error reading from file
#define E_EWRITE 19 // Error writing to file
#define E_SMALL_BUF 20 // Buffer too small
#define E_EABORTED 21 // Function aborted by user
#define E_NO_FILES 22 // No files found
#define E_TOO_MANY_FILES 23 // Too many files to pack
#define E_NOT_SUPPORTED 24 // Function not supported
/* flags for ProcessFile */
#define PK_SKIP 0 // Skip this file
#define PK_TEST 1 // Test file integrity
#define PK_EXTRACT 2 // Extract to disk
/* Flags passed through PFN_CHANGE_VOL */
#define PK_VOL_ASK 0 // Ask user for location of next volume
#define PK_VOL_NOTIFY 1 // Notify app that next volume will be unpacked
/* Flags for packing */
/* For PackFiles */
#define PK_PACK_MOVE_FILES 1 // Delete original after packing
#define PK_PACK_SAVE_PATHS 2 // Save path names of files
/* Returned by GetPackCaps */
#define PK_CAPS_NEW 1 // Can create new archives
#define PK_CAPS_MODIFY 2 // Can modify existing archives
#define PK_CAPS_MULTIPLE 4 // Archive can contain multiple files
#define PK_CAPS_DELETE 8 // Can delete files
#define PK_CAPS_OPTIONS 16 // Has options dialog
#define PK_CAPS_MEMPACK 32 // Supports packing in memory
#define PK_CAPS_BY_CONTENT 64 // Detect archive type by content
#define PK_CAPS_SEARCHTEXT 128 // Allow searching for text in archives
// created with this plugin}
#define PK_CAPS_HIDE 256 // Show as normal files (hide packer
// icon), open with Ctrl+PgDn, not Enter
/* Flags for packing in memory */
#define MEM_OPTIONS_WANTHEADERS 1 // Return archive headers with packed data
#define MEMPACK_OK 0 // Function call finished OK, but there is more data
#define MEMPACK_DONE 1 // Function call finished OK, there is no more data
#define FILE_COMPRESSION_NONE 0
#define FILE_COMPRESSION_INFLATE 1
#define FILE_COMPRESSION_ZLIB 2
#define FILE_COMPRESSION_BZIP2 3
#define FILE_COMPRESSION_LZMA 4
#define INVALID_SIZE_T (size_t)(-1)
//-----------------------------------------------------------------------------
// Definitions of callback functions
// Ask to swap disk for multi-volume archive
typedef int (WINAPI * PFN_CHANGE_VOLUMEA)(LPCSTR szArcName, int nMode);
typedef int (WINAPI * PFN_CHANGE_VOLUMEW)(LPCWSTR szArcName, int nMode);
// Notify that data is processed - used for progress dialog
typedef int (WINAPI * PFN_PROCESS_DATAA)(LPCSTR szFileName, int nSize);
typedef int (WINAPI * PFN_PROCESS_DATAW)(LPCWSTR szFileName, int nSize);
//-----------------------------------------------------------------------------
// Structures
struct DOS_FTIME
{
unsigned ft_tsec : 5; // Two second interval
unsigned ft_min : 6; // Minutes
unsigned ft_hour : 5; // Hours
unsigned ft_day : 5; // Days
unsigned ft_month : 4; // Months
unsigned ft_year : 7; // Year
};
struct THeaderData
{
char ArcName[260];
char FileName[260];
DWORD Flags;
DWORD PackSize;
DWORD UnpSize;
DWORD HostOS;
DWORD FileCRC;
DOS_FTIME FileTime;
DWORD UnpVer;
DWORD Method;
DWORD FileAttr;
char * CmtBuf;
DWORD CmtBufSize;
DWORD CmtSize;
DWORD CmtState;
};
#pragma pack(push, 4)
struct THeaderDataEx
{
char ArcName[1024];
char FileName[1024];
DWORD Flags;
ULONGLONG PackSize;
ULONGLONG UnpSize;
DWORD HostOS;
DWORD FileCRC;
DOS_FTIME FileTime;
DWORD UnpVer;
DWORD Method;
DWORD FileAttr;
char * CmtBuf;
DWORD CmtBufSize;
DWORD CmtSize;
DWORD CmtState;
char Reserved[1024];
};
struct THeaderDataExW
{
WCHAR ArcName[1024];
WCHAR FileName[1024];
DWORD Flags;
ULONGLONG PackSize;
ULONGLONG UnpSize;
DWORD HostOS;
DWORD FileCRC;
DOS_FTIME FileTime;
DWORD UnpVer;
DWORD Method;
DWORD FileAttr;
char* CmtBuf;
DWORD CmtBufSize;
DWORD CmtSize;
DWORD CmtState;
char Reserved[1024];
};
#pragma pack(pop, 4)
//-----------------------------------------------------------------------------
// Open archive information
#define PK_OM_LIST 0
#define PK_OM_EXTRACT 1
struct TOpenArchiveData
{
union
{
LPCSTR szArchiveNameA; // Archive name to open
LPCWSTR szArchiveNameW; // Archive name to open
};
int OpenMode; // Open reason (See PK_OM_XXXX)
int OpenResult;
char * CmtBuf;
int CmtBufSize;
int CmtSize;
int CmtState;
};
typedef struct
{
int size;
DWORD PluginInterfaceVersionLow;
DWORD PluginInterfaceVersionHi;
char DefaultIniName[MAX_PATH];
} TPackDefaultParamStruct;
//-----------------------------------------------------------------------------
// Information about loading archive
typedef enum _LDST
{
LOADSTATE_FIND_FIRST, // Loading files using listfile (first)
LOADSTATE_FIND_NEXT, // Loading files using listfile (first)
LOADSTATE_COMPLETE, // Complete
} LDST, *PLDST;
// Our structure describing open archive archive
struct TOpenMpqInfo
{
ULONGLONG dwSignature; // Handle signature
//PFN_PROCESS_DATAA PfnProcessDataA; // Process data procedure (ANSI)
//PFN_PROCESS_DATAW PfnProcessDataW; // Process data procedure (UNICODE)
//PFN_CHANGE_VOLUMEA PfnChangeVolA; // Change volume procedure (ANSI)
//PFN_CHANGE_VOLUMEW PfnChangeVolW; // Change volume procedure (UNICODE)
SFILE_FIND_DATA sf; // Current search record
DOS_FTIME ArchiveTime; // Date and time of the archive
HANDLE hMPQ; // Handle of open archive
HANDLE hFind; // Search handle
HANDLE hStopEvent; // Event saying "stop" to the worker thread(s);
DWORD dwBytesProcessed; // Number of bytes processed since last call of ProcessDataProc
DWORD dwMaxFileIndex; // Size of block table (number of files)
DWORD dwLastFileIndex; // Last file indes that was tried to open
char * szFullPath; // Full path of the file currently being processed
char * szDestPath; // Dest path
char * szDestName;
BOOL bResult; // Last result of SFileFindNextFile
int nOpenMode; // The mode which the archive has been open for
LDST LoadState; // Current load state. See LOADSTATE_XXXX definitions
BYTE FoundFile[1]; // List of BYTEs indicating that a file has been already found (variable length)
};
//-----------------------------------------------------------------------------
// Configuration structures
typedef struct
{
DWORD dwMaxFileCount; // Maximum file count for newly created files
DWORD dwCompression; // Compression for newly added files
LCID lcFileLocale; // Locale for newly added files
BOOL bCreateMpqV2; // If TRUE, plugin will create archives version 2
// (supports archive sizes > 4BG)
BOOL bAddLocaleToName; // If TRUE, the file name will contain the locale
// ID, e.g. "File.ext (40A)"
BOOL bEncryptAddedFiles; // If TRUE, the newly added files will be encrypted
BOOL bCompactAfterDelete; // If TRUE, the plugin will compact the MPQ archive
// after a change operation
TCHAR szListFile[MAX_PATH]; // External listfile
TCHAR szExcludedTypes[0x400]; // File types that are excluded from compression
} TConfiguration;
//-----------------------------------------------------------------------------
// Global variables
extern TConfiguration g_cfg; // Plugin configuration
extern HINSTANCE g_hInst; // Our DLL instance
extern HANDLE g_hHeap; // Process heap
extern TCHAR g_szIniFile[MAX_PATH]; // Packer INI file
//-----------------------------------------------------------------------------
// Global functions
// Configuration functions
int SetDefaultConfiguration();
int LoadConfiguration();
int SaveConfiguration();
//-----------------------------------------------------------------------------
// Dialogs
INT_PTR SettingsDialog(HWND hParent);
#endif // __WCX_MPQ_H__