Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




CommitLineData
62046253 1Attribute VB_Name = "SFmpqapi"
2Option Explicit
3
4' ShadowFlare MPQ API Library. (c) ShadowFlare Software 2002
5
6' All functions below are actual functions that are part of this
7' library and do not need any additional dll files. It does not
8' even require Storm to be able to decompress or compress files.
9
10' This library emulates the interface of Lmpqapi and Storm MPQ
11' functions, so it may be used as a replacement for them in
12' MPQ extractors/archivers without even needing to recompile
13' the program that uses Lmpqapi or Storm. It has a few features
14' not included in Lmpqapi and Storm, such as extra flags for some
15' functions, setting the locale ID of existing files, and adding
16' files without having to write them somewhere else first. Also,
17' MPQ handles used by functions prefixed with "SFile" and "Mpq"
18' can be used interchangably; all functions use the same type
19' of MPQ handles. You cannot, however, use handles from this
20' library with storm or lmpqapi or vice-versa. Doing so will
21' most likely result in a crash.
22
23' Revision History:
24' 20/10/2002 1.07 (ShadowFlare)
25' - No longer requires Storm.dll to compress or decompress
26' Warcraft III files
27' - Added SFileListFiles for getting names and information
28' about all of the files in an archive
29' - Fixed a bug with renaming and deleting files
30
31' 05/09/2002 1.06 (ShadowFlare)
32' - Compresses files without Storm.dll!
33' - If Warcraft III is installed, this library will be able to
34' find Storm.dll on its own. (Storm.dll is needed to
35' decompress Warcraft III files)
36' - Fixed a bug where an embedded archive and the file that
37' contains it would be corrupted if the archive was modified
38' - Able to open all .w3m maps now
39
40' 29/06/2002 1.05 (ShadowFlare)
41' - Supports decompressing files from Warcraft III MPQ archives
42' if using Storm.dll from Warcraft III
43' - Added MpqAddFileToArchiveEx and MpqAddFileFromBufferEx for
44' using extra compression types
45
46' 29/05/2002 1.04 (ShadowFlare)
47' - Files can be compressed now!
48' - Fixed a bug in SFileReadFile when reading data not aligned
49' to the block size
50' - Optimized some of SFileReadFile's code. It can read files
51' faster now
52' - SFile functions may now be used to access files not in mpq
53' archives as you can with the real storm functions
54' - MpqCompactArchive will no longer corrupt files with the
55' MODCRYPTKEY flag as long as the file is either compressed,
56' listed in "(listfile)", is "(listfile)", or is located in
57' the same place in the compacted archive; so it is safe
58' enough to use it on almost any archive
59' - Added MpqAddWaveFromBuffer
60' - Better handling of archives with no files
61' - Fixed compression with COMPRESS2 flag
62
63' 15/05/2002 1.03 (ShadowFlare)
64' - Supports adding files with the compression attribute (does
65' not actually compress files). Now archives created with
66' this dll can have files added to them through lmpqapi
67' without causing staredit to crash
68' - SFileGetBasePath and SFileSetBasePath work more like their
69' Storm equivalents now
70' - Implemented MpqCompactArchive, but it is not finished yet.
71' In its current state, I would recommend against using it
72' on archives that contain files with the MODCRYPTKEY flag,
73' since it will corrupt any files with that flag
74' - Added SFMpqGetVersionString2 which may be used in Visual
75' Basic to get the version string
76
77' 07/05/2002 1.02 (ShadowFlare)
78' - SFileReadFile no longer passes the lpOverlapped parameter it
79' receives to ReadFile. This is what was causing the function
80' to fail when used in Visual Basic
81' - Added support for more Storm MPQ functions
82' - GetLastError may now be used to get information about why a
83' function failed
84
85' 01/05/2002 1.01 (ShadowFlare)
86' - Added ordinals for Storm MPQ functions
87' - Fixed MPQ searching functionality of SFileOpenFileEx
88' - Added a check for whether a valid handle is given when
89' SFileCloseArchive is called
90' - Fixed functionality of SFileSetArchivePriority when multiple
91' files are open
92' - File renaming works for all filenames now
93' - SFileReadFile no longer reallocates the buffer for each block
94' that is decompressed. This should make SFileReadFile at least
95' a little faster
96
97' 30/04/2002 1.00 (ShadowFlare)
98' - First version.
99' - Compression not yet supported
100' - Does not use SetLastError yet, so GetLastError will not return any
101' errors that have to do with this library
102' - MpqCompactArchive not implemented
103
104' This library is freeware, you can do anything you want with it but with
105' one exception. If you use it in your program, you must specify this fact
106' in Help|About box or in similar way. You can obtain version string using
107' SFMpqGetVersionString call.
108
109' THIS LIBRARY IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED
110' OR IMPLIED. YOU USE AT YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR
111' DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING
112' OR MISUSING THIS SOFTWARE.
113
114' Any comments or suggestions are accepted at blakflare@hotmail.com (ShadowFlare)
115
116Type SFMPQVERSION
117 Major As Integer
118 Minor As Integer
119 Revision As Integer
120 Subrevision As Integer
121End Type
122
123' MpqInitialize does nothing. It is only provided for
124' compatibility with MPQ archivers that use lmpqapi.
125Declare Function MpqInitialize Lib "SFmpq.dll" () As Boolean
126
127Declare Function MpqGetVersionString Lib "SFmpq.dll" () As String
128Declare Function MpqGetVersion Lib "SFmpq.dll" () As Single
129
130Declare Sub SFMpqDestroy Lib "SFmpq.dll" () ' This no longer needs to be called. It is only provided for compatibility with older versions
131
132' SFMpqGetVersionString2's return value is the required length of the buffer plus
133' the terminating null, so use SFMpqGetVersionString2(ByVal 0&, 0) to get the length.
134Declare Function SFMpqGetVersionString Lib "SFmpq.dll" () As String
135Declare Function SFMpqGetVersionString2 Lib "SFmpq.dll" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Long
136Declare Function SFMpqGetVersion Lib "SFmpq.dll" () As SFMPQVERSION
137
138' General error codes
139Public Const MPQ_ERROR_MPQ_INVALID As Long = &H85200065
140Public Const MPQ_ERROR_FILE_NOT_FOUND As Long = &H85200066
141Public Const MPQ_ERROR_DISK_FULL As Long = &H85200068 'Physical write file to MPQ failed. Not sure of exact meaning
142Public Const MPQ_ERROR_HASH_TABLE_FULL As Long = &H85200069
143Public Const MPQ_ERROR_ALREADY_EXISTS As Long = &H8520006A
144Public Const MPQ_ERROR_BAD_OPEN_MODE As Long = &H8520006C 'When MOAU_READ_ONLY is used without MOAU_OPEN_EXISTING
145
146Public Const MPQ_ERROR_COMPACT_ERROR As Long = &H85300001
147
148' MpqOpenArchiveForUpdate flags
149Public Const MOAU_CREATE_NEW As Long = &H0
150Public Const MOAU_CREATE_ALWAYS As Long = &H8 'Was wrongly named MOAU_CREATE_NEW
151Public Const MOAU_OPEN_EXISTING As Long = &H4
152Public Const MOAU_OPEN_ALWAYS As Long = &H20
153Public Const MOAU_READ_ONLY As Long = &H10 'Must be used with MOAU_OPEN_EXISTING
154Public Const MOAU_MAINTAIN_LISTFILE As Long = &H1
155
156' MpqAddFileToArchive flags
157Public Const MAFA_EXISTS As Long = &H80000000 'Will be added if not present
158Public Const MAFA_UNKNOWN40000000 As Long = &H40000000
159Public Const MAFA_MODCRYPTKEY As Long = &H20000
160Public Const MAFA_ENCRYPT As Long = &H10000
161Public Const MAFA_COMPRESS As Long = &H200
162Public Const MAFA_COMPRESS2 As Long = &H100
163Public Const MAFA_REPLACE_EXISTING As Long = &H1
164
165' MpqAddFileToArchiveEx compression flags
166Public Const MAFA_COMPRESS_STANDARD As Long = &H8 'Standard PKWare DCL compression
167Public Const MAFA_COMPRESS_DEFLATE As Long = &H2 'ZLib's deflate compression
168Public Const MAFA_COMPRESS_WAVE As Long = &H81 'Standard wave compression
169Public Const MAFA_COMPRESS_WAVE2 As Long = &H41 'Unused wave compression
170
171' Flags for individual compression types used for wave compression
172Public Const MAFA_COMPRESS_WAVECOMP1 As Long = &H80 'Main compressor for standard wave compression
173Public Const MAFA_COMPRESS_WAVECOMP2 As Long = &H40 'Main compressor for unused wave compression
174Public Const MAFA_COMPRESS_WAVECOMP3 As Long = &H1 'Secondary compressor for wave compression
175
176' ZLib deflate compression level constants (used with MpqAddFileToArchiveEx and MpqAddFileFromBufferEx)
177Public Const Z_NO_COMPRESSION As Long = 0
178Public Const Z_BEST_SPEED As Long = 1
179Public Const Z_BEST_COMPRESSION As Long = 9
180Public Const Z_DEFAULT_COMPRESSION As Long = (-1)
181
182' MpqAddWAVToArchive quality flags
183Public Const MAWA_QUALITY_HIGH As Long = 1
184Public Const MAWA_QUALITY_MEDIUM As Long = 0
185Public Const MAWA_QUALITY_LOW As Long = 2
186
187' SFileGetFileInfo flags
188Public Const SFILE_INFO_BLOCK_SIZE As Long = &H1 'Block size in MPQ
189Public Const SFILE_INFO_HASH_TABLE_SIZE As Long = &H2 'Hash table size in MPQ
190Public Const SFILE_INFO_NUM_FILES As Long = &H3 'Number of files in MPQ
191Public Const SFILE_INFO_TYPE As Long = &H4 'Is Long a file or an MPQ?
192Public Const SFILE_INFO_SIZE As Long = &H5 'Size of MPQ or uncompressed file
193Public Const SFILE_INFO_COMPRESSED_SIZE As Long = &H6 'Size of compressed file
194Public Const SFILE_INFO_FLAGS As Long = &H7 'File flags (compressed, etc.), file attributes if a file not in an archive
195Public Const SFILE_INFO_PARENT As Long = &H8 'Handle of MPQ that file is in
196Public Const SFILE_INFO_POSITION As Long = &H9 'Position of file pointer in files
197Public Const SFILE_INFO_LOCALEID As Long = &HA 'Locale ID of file in MPQ
198Public Const SFILE_INFO_PRIORITY As Long = &HB 'Priority of open MPQ
199Public Const SFILE_INFO_HASH_INDEX As Long = &HC 'Hash index of file in MPQ
200
201' SFileListFiles flags
202Public Const SFILE_LIST_MEMORY_LIST As Long = &H1 ' Specifies that lpFilelists is a file list from memory, rather than being a list of file lists
203Public Const SFILE_LIST_ONLY_KNOWN As Long = &H2 ' Only list files that the function finds a name for
204Public Const SFILE_LIST_ONLY_UNKNOWN As Long = &H4 ' Only list files that the function does not find a name for
205
206Public Const SFILE_TYPE_MPQ As Long = &H1
207Public Const SFILE_TYPE_FILE As Long = &H2
208
209Public Const INVALID_HANDLE_VALUE As Long = -1
210
211Public Const FILE_BEGIN As Long = 0
212Public Const FILE_CURRENT As Long = 1
213Public Const FILE_END As Long = 2
214
215Public Const SFILE_OPEN_HARD_DISK_FILE As Long = &H0 'Open archive without regard to the drive type it resides on
216Public Const SFILE_OPEN_CD_ROM_FILE As Long = &H1 'Open the archive only if it is on a CD-ROM
217Public Const SFILE_OPEN_ALLOW_WRITE As Long = &H8000 'Open file with write access
218
219Public Const SFILE_SEARCH_CURRENT_ONLY As Long = &H0 'Used with SFileOpenFileEx; only the archive with the handle specified will be searched for the file
220Public Const SFILE_SEARCH_ALL_OPEN As Long = &H1 'SFileOpenFileEx will look through all open archives for the file
221
222Type FILELISTENTRY
223 dwFileExists As Long ' Nonzero if this entry is used
224 lcLocale As Long ' Locale ID of file
225 dwCompressedSize As Long ' Compressed size of file
226 dwFullSize As Long ' Uncompressed size of file
227 dwFlags As Long ' Flags for file
228 szFileName(259) As Byte
229End Type
230
231' Storm functions implemented by this library
232Declare Function SFileOpenArchive Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwPriority As Long, ByVal dwFlags As Long, ByRef hMPQ As Long) As Boolean
233Declare Function SFileCloseArchive Lib "SFmpq.dll" (ByVal hMPQ As Long) As Boolean
234Declare Function SFileGetArchiveName Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
235Declare Function SFileOpenFile Lib "SFmpq.dll" (ByVal lpFileName As String, ByRef hFile As Long) As Boolean
236Declare Function SFileOpenFileEx Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal dwSearchScope As Long, ByRef hFile As Long) As Boolean
237Declare Function SFileCloseFile Lib "SFmpq.dll" (ByVal hFile As Long) As Boolean
238Declare Function SFileGetFileSize Lib "SFmpq.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
239Declare Function SFileGetFileArchive Lib "SFmpq.dll" (ByVal hFile As Long, ByRef hMPQ As Long) As Boolean
240Declare Function SFileGetFileName Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
241Declare Function SFileSetFilePointer Lib "SFmpq.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lplDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
242Declare Function SFileReadFile Lib "SFmpq.dll" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Boolean
243Declare Function SFileSetLocale Lib "SFmpq.dll" (ByVal nNewLocale As Long) As Long
244Declare Function SFileGetBasePath Lib "SFmpq.dll" (ByVal lpBuffer As String, ByVal dwBufferLength As Long) As Boolean
245Declare Function SFileSetBasePath Lib "SFmpq.dll" (ByVal lpNewBasePath As String) As Boolean
246
247' Extra storm-related functions
248Declare Function SFileGetFileInfo Lib "SFmpq.dll" (ByVal hFile As Long, ByVal dwInfoType As Long) As Long
249Declare Function SFileSetArchivePriority Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal dwPriority As Long) As Boolean
250Declare Function SFileFindMpqHeader Lib "SFmpq.dll" (ByVal hFile As Long) As Long
251Declare Function SFileListFiles Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileLists As String, ByRef lpListBuffer As FILELISTENTRY, ByVal dwFlags As Long) As Boolean
252
253' Archive editing functions implemented by this library
254Declare Function MpqOpenArchiveForUpdate Lib "SFmpq.dll" (ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwMaximumFilesInArchive As Long) As Long
255Declare Function MpqCloseUpdatedArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal dwUnknown2 As Long) As Long
256Declare Function MpqAddFileToArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long) As Boolean
257Declare Function MpqAddWaveToArchive Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long, ByVal dwQuality As Long) As Boolean
258Declare Function MpqRenameFile Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpcOldFileName As String, ByVal lpcNewFileName As String) As Boolean
259Declare Function MpqDeleteFile Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String) As Boolean
260Declare Function MpqCompactArchive Lib "SFmpq.dll" (ByVal hMPQ As Long) As Boolean
261
262' Extra archive editing functions
263Declare Function MpqAddFileToArchiveEx Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpSourceFileName As String, ByVal lpDestFileName As String, ByVal dwFlags As Long, ByVal dwCompressionType As Long, ByVal dwCompressLevel As Long) As Boolean
264Declare Function MpqAddFileFromBufferEx Lib "SFmpq.dll" (ByVal hMPQ As Long, lpBuffer As Any, ByVal dwLength As Long, ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwCompressionType As Long, ByVal dwCompressLevel As Long) As Boolean
265Declare Function MpqAddFileFromBuffer Lib "SFmpq.dll" (ByVal hMPQ As Long, lpBuffer As Any, ByVal dwLength As Long, ByVal lpFileName As String, ByVal dwFlags As Long) As Boolean
266Declare Function MpqAddWaveFromBuffer Lib "SFmpq.dll" (ByVal hMPQ As Long, lpBuffer As Any, ByVal dwLength As Long, ByVal lpFileName As String, ByVal dwFlags As Long, ByVal dwQuality As Long) As Boolean
267Declare Function MpqSetFileLocale Lib "SFmpq.dll" (ByVal hMPQ As Long, ByVal lpFileName As String, ByVal nOldLocale As Long, ByVal nNewLocale As Long) As Boolean
268
269' These functions do nothing. They are only provided for
270' compatibility with MPQ extractors that use storm.
271Declare Function SFileDestroy Lib "SFmpq.dll" () As Boolean
272Declare Sub StormDestroy Lib "SFmpq.dll" ()
273
274' Returns 0 if the dll version is equal to the version your program was compiled
275' with, 1 if the dll is newer, -1 if the dll is older.
276Function SFMpqCompareVersion() As Long
277 Dim ExeVersion As SFMPQVERSION, DllVersion As SFMPQVERSION
278 With ExeVersion
279 .Major = 1
280 .Minor = 0
281 .Revision = 7
282 .Subrevision = 3
283 End With
284 DllVersion = SFMpqGetVersion()
285 If DllVersion.Major > ExeVersion.Major Then
286 SFMpqCompareVersion = 1
287 Exit Function
288 ElseIf DllVersion.Major < ExeVersion.Major Then
289 SFMpqCompareVersion = -1
290 Exit Function
291 End If
292 If DllVersion.Minor > ExeVersion.Minor Then
293 SFMpqCompareVersion = 1
294 Exit Function
295 ElseIf DllVersion.Minor < ExeVersion.Minor Then
296 SFMpqCompareVersion = -1
297 Exit Function
298 End If
299 If DllVersion.Revision > ExeVersion.Revision Then
300 SFMpqCompareVersion = 1
301 Exit Function
302 ElseIf DllVersion.Revision < ExeVersion.Revision Then
303 SFMpqCompareVersion = -1
304 Exit Function
305 End If
306 If DllVersion.Subrevision > ExeVersion.Subrevision Then
307 SFMpqCompareVersion = 1
308 Exit Function
309 ElseIf DllVersion.Subrevision < ExeVersion.Subrevision Then
310 SFMpqCompareVersion = -1
311 Exit Function
312 End If
313 SFMpqCompareVersion = 0
314End Function
315