| 1 |
Attribute VB_Name = "VBZipBas" |
| 2 |
|
| 3 |
Option Explicit |
| 4 |
|
| 5 |
'--------------------------------------------------------------- |
| 6 |
'-- Please Do Not Remove These Comments!!! |
| 7 |
'--------------------------------------------------------------- |
| 8 |
'-- Sample VB 6 code to drive zip32z64.dll |
| 9 |
'-- Based on the code contributed to the Info-ZIP project |
| 10 |
'-- by Mike Le Voi |
| 11 |
'-- |
| 12 |
'-- See the original VB example in a separate directory for |
| 13 |
'-- more information |
| 14 |
'-- |
| 15 |
'-- Use this code at your own risk. Nothing implied or warranted |
| 16 |
'-- to work on your machine :-) |
| 17 |
'--------------------------------------------------------------- |
| 18 |
'-- |
| 19 |
'-- The Source Code Is Freely Available From Info-ZIP At: |
| 20 |
'-- ftp://ftp.info-zip.org/pub/infozip/infozip.html |
| 21 |
'-- |
| 22 |
'-- A Very Special Thanks To Mr. Mike Le Voi |
| 23 |
'-- And Mr. Mike White Of The Info-ZIP |
| 24 |
'-- For Letting Me Use And Modify His Orginal |
| 25 |
'-- Visual Basic 5.0 Code! Thank You Mike Le Voi. |
| 26 |
'--------------------------------------------------------------- |
| 27 |
|
| 28 |
'--------------------------------------------------------------- |
| 29 |
' This example is redesigned to work with Zip32z64.dll compiled from |
| 30 |
' Zip 3.0 with Zip64 enabled. This allows for archives with more |
| 31 |
' and larger files than allowed in previous versions. |
| 32 |
' |
| 33 |
' Modified 4/24/2004, 12/4/2007 by Ed Gordon |
| 34 |
'--------------------------------------------------------------- |
| 35 |
|
| 36 |
'--------------------------------------------------------------- |
| 37 |
' Usage notes: |
| 38 |
' |
| 39 |
' This code uses Zip32z64.dll. You DO NOT need to register the |
| 40 |
' DLL to use it. You also DO NOT need to reference it in your |
| 41 |
' VB project. You DO have to copy the DLL to your SYSTEM |
| 42 |
' directory, your VB project directory, or place it in a directory |
| 43 |
' on your command PATH. |
| 44 |
' |
| 45 |
' Note that Zip32z64 is probably not thread safe so you should avoid |
| 46 |
' using the dll in multiple threads at the same time without first |
| 47 |
' testing for interaction. |
| 48 |
' |
| 49 |
' All code provided under the Info-Zip license. If you have |
| 50 |
' any questions please contact Info-Zip. |
| 51 |
' |
| 52 |
' April 24 2004 EG |
| 53 |
' |
| 54 |
'--------------------------------------------------------------- |
| 55 |
|
| 56 |
'-- C Style argv |
| 57 |
'-- Holds The Zip Archive Filenames |
| 58 |
' |
| 59 |
' Max for zFiles just over 8000 as each pointer takes up 4 bytes and |
| 60 |
' VB only allows 32 kB of local variables and that includes function |
| 61 |
' parameters. - 3/19/2004 EG |
| 62 |
' |
| 63 |
' Can put names in strZipFileNames instead of using this array, |
| 64 |
' which avoids this limit. File names are separated by spaces. |
| 65 |
' Enclose names in quotes if include spaces. |
| 66 |
Public Type ZIPnames |
| 67 |
zFiles(1 To 100) As String |
| 68 |
End Type |
| 69 |
|
| 70 |
'-- Call Back "String" |
| 71 |
Public Type ZipCBChar |
| 72 |
ch(4096) As Byte |
| 73 |
End Type |
| 74 |
|
| 75 |
'-- Version Structure |
| 76 |
Public Type VerType |
| 77 |
Major As Byte |
| 78 |
Minor As Byte |
| 79 |
PatchLevel As Byte |
| 80 |
NotUsed As Byte |
| 81 |
End Type |
| 82 |
Public Type ZipVerType |
| 83 |
structlen As Long ' Length Of The Structure Being Passed |
| 84 |
flag As Long ' Bit 0: is_beta bit 1: uses_zlib |
| 85 |
Beta As String * 10 ' e.g., "g BETA" or "" |
| 86 |
date As String * 20 ' e.g., "4 Sep 95" (beta) or "4 September 1995" |
| 87 |
ZLIB As String * 10 ' e.g., "1.0.5" or NULL |
| 88 |
encryption As Long ' 0 if encryption not available |
| 89 |
ZipVersion As VerType |
| 90 |
os2dllVersion As VerType |
| 91 |
windllVersion As VerType |
| 92 |
End Type |
| 93 |
|
| 94 |
'-- ZPOPT Is Used To Set The Options In The ZIP32z64.DLL |
| 95 |
Public Type ZpOpt |
| 96 |
date As String ' Date in either US 12/31/98 or 1998-12-31 format |
| 97 |
szRootDir As String ' Root Directory Pathname (Up To 256 Bytes Long) |
| 98 |
szTempDir As String ' Temp Directory Pathname (Up To 256 Bytes Long) |
| 99 |
fTemp As Long ' 1 If Temp dir Wanted, Else 0 |
| 100 |
fSuffix As Long ' Include Suffixes (Not Yet Implemented!) |
| 101 |
fEncrypt As Long ' 1 If Encryption Wanted, Else 0 |
| 102 |
fSystem As Long ' 1 To Include System/Hidden Files, Else 0 |
| 103 |
fVolume As Long ' 1 If Storing Volume Label, Else 0 |
| 104 |
fExtra As Long ' 1 If Excluding Extra Attributes, Else 0 |
| 105 |
fNoDirEntries As Long ' 1 If Ignoring Directory Entries (end with /), Else 0 |
| 106 |
fExcludeDate As Long ' 1 If Excluding Files After Specified Date, Else 0 |
| 107 |
fIncludeDate As Long ' 1 If Including Files After Specified Date, Else 0 |
| 108 |
fVerbose As Long ' 1 If Full Messages Wanted, Else 0 |
| 109 |
fQuiet As Long ' 1 If Minimum Messages Wanted, Else 0 |
| 110 |
fCRLF_LF As Long ' 1 If Translate CR/LF To LF, Else 0 |
| 111 |
fLF_CRLF As Long ' 1 If Translate LF To CR/LF, Else 0 |
| 112 |
fJunkDir As Long ' 1 If Junking Directory Names on entries, Else 0 |
| 113 |
fGrow As Long ' 1 If Allow Appending To Zip File, Else 0 |
| 114 |
fForce As Long ' 1 If Making Entries Using DOS File Names, Else 0 |
| 115 |
fMove As Long ' 1 If Deleting Files Added Or Updated, Else 0 |
| 116 |
fDeleteEntries As Long ' 1 If Files Passed Have To Be Deleted, Else 0 |
| 117 |
fUpdate As Long ' 1 If Updating Zip File-Overwrite Only If Newer, Else 0 |
| 118 |
fFreshen As Long ' 1 If Freshing Zip File-Overwrite Only, Else 0 |
| 119 |
fJunkSFX As Long ' 1 If Junking SFX Prefix, Else 0 |
| 120 |
fLatestTime As Long ' 1 If Setting Zip File Time To Time Of Latest File In Archive, Else 0 |
| 121 |
fComment As Long ' 1 If Putting Comment In Zip File, Else 0 |
| 122 |
fOffsets As Long ' 1 If Updating Archive Offsets For SFX Files, Else 0 |
| 123 |
fPrivilege As Long ' 1 If Not Saving Privileges, Else 0 |
| 124 |
fEncryption As Long ' Read Only Property!!! |
| 125 |
szSplitSize As String ' Size of split if splitting, Else NULL (empty string) |
| 126 |
' This string contains the size that you want to |
| 127 |
' split the archive into. i.e. 100 for 100 bytes, |
| 128 |
' 2K for 2 k bytes, where K is 1024, m for meg |
| 129 |
' and g for gig. |
| 130 |
szIncludeList As String ' If used, space separated list of Include filename |
| 131 |
' patterns where match includes file - put quotes |
| 132 |
' around each filename pattern. |
| 133 |
IncludeListCount As Long ' place filler (not for VB) - (inits to 0) DO NOT USE |
| 134 |
IncludeList As Long ' place filler (not for VB) - (inits to 0) DO NOT USE |
| 135 |
szExcludeList As String ' If used, space separated list of Exclude filename |
| 136 |
' patterns where match excludes file - put quotes |
| 137 |
' around each filename pattern. |
| 138 |
ExcludeListCount As Long ' place filler (not for VB) - (inits to 0) DO NOT USE |
| 139 |
ExcludeList As Long ' place filler (not for VB) - (inits to 0) DO NOT USE |
| 140 |
fRecurse As Long ' 1 (-r), 2 (-R) If Recursing Into Sub-Directories, Else 0 |
| 141 |
fRepair As Long ' 1 = Fix Archive, 2 = Try Harder To Fix, Else 0 |
| 142 |
flevel As Byte ' Compression Level - 0 = Stored 6 = Default 9 = Max |
| 143 |
End Type |
| 144 |
|
| 145 |
|
| 146 |
' Used by SetZipOptions |
| 147 |
Public Enum ZipModeType |
| 148 |
Add = 0 |
| 149 |
Delete = 1 |
| 150 |
Update = 2 |
| 151 |
Freshen = 3 |
| 152 |
End Enum |
| 153 |
Public Enum CompressionLevelType |
| 154 |
c0_NoCompression = 0 |
| 155 |
c1_Fast = 1 |
| 156 |
c2_Fast = 2 |
| 157 |
c3_Fast = 3 |
| 158 |
c4_Med = 4 |
| 159 |
c5_Med = 5 |
| 160 |
c6_Default = 6 |
| 161 |
c7_Extra = 7 |
| 162 |
c8_Extra = 8 |
| 163 |
c9_Max = 9 |
| 164 |
End Enum |
| 165 |
Public Enum Translate_LF_Type |
| 166 |
No_Line_End_Trans = 0 |
| 167 |
LF_To_CRLF = 1 |
| 168 |
CRLF_To_LF = 2 |
| 169 |
End Enum |
| 170 |
Public Enum RepairType |
| 171 |
NoRepair = 0 |
| 172 |
TryFix = 1 |
| 173 |
TryFixHarder = 2 |
| 174 |
End Enum |
| 175 |
Public Enum VerbosenessType |
| 176 |
Quiet = 0 |
| 177 |
Normal = 1 |
| 178 |
Verbose = 2 |
| 179 |
End Enum |
| 180 |
Public Enum RecurseType |
| 181 |
NoRecurse = 0 |
| 182 |
r_RecurseIntoSubdirectories = 1 |
| 183 |
R_RecurseUsingPatterns = 2 |
| 184 |
End Enum |
| 185 |
|
| 186 |
|
| 187 |
'-- This Structure Is Used For The ZIP32z64.DLL Function Callbacks |
| 188 |
' Assumes Zip32z64.dll with Zip64 enabled |
| 189 |
Public Type ZIPUSERFUNCTIONS |
| 190 |
ZDLLPrnt As Long ' Callback ZIP32z64.DLL Print Function |
| 191 |
ZDLLCOMMENT As Long ' Callback ZIP32z64.DLL Comment Function |
| 192 |
ZDLLPASSWORD As Long ' Callback ZIP32z64.DLL Password Function |
| 193 |
ZDLLSPLIT As Long ' Callback ZIP32z64.DLL Split Select Function |
| 194 |
' There are 2 versions of SERVICE, we use one does not need 64-bit data type |
| 195 |
ZDLLSERVICE As Long ' Callback ZIP32z64.DLL Service Function |
| 196 |
ZDLLSERVICE_NO_INT64 As Long ' Callback ZIP32z64.DLL Service Function |
| 197 |
End Type |
| 198 |
|
| 199 |
'-- Default encryption password (used in callback if not empty string) |
| 200 |
Public EncryptionPassword As String |
| 201 |
|
| 202 |
'-- For setting the archive comment |
| 203 |
Public ArchiveCommentText |
| 204 |
|
| 205 |
'-- version info |
| 206 |
Public ZipVersion As ZipVerType |
| 207 |
|
| 208 |
'-- Local Declarations |
| 209 |
Public ZOPT As ZpOpt |
| 210 |
Public ZUSER As ZIPUSERFUNCTIONS |
| 211 |
|
| 212 |
'-- This Assumes ZIP32z64.DLL Is In Your \windows\system directory |
| 213 |
'-- or a copy is in the program directory or in some other directory |
| 214 |
'-- listed in PATH |
| 215 |
Private Declare Function ZpInit Lib "zip32z64.dll" _ |
| 216 |
(ByRef Zipfun As ZIPUSERFUNCTIONS) As Long '-- Set Zip Callbacks |
| 217 |
|
| 218 |
Private Declare Function ZpArchive Lib "zip32z64.dll" _ |
| 219 |
(ByVal argc As Long, ByVal funame As String, _ |
| 220 |
ByRef argv As ZIPnames, ByVal strNames As String, ByRef Opts As ZpOpt) As Long '-- Real Zipping Action |
| 221 |
|
| 222 |
Private Declare Sub ZpVersion Lib "zip32z64.dll" _ |
| 223 |
(ByRef ZipVersion As ZipVerType) '-- Version of DLL |
| 224 |
|
| 225 |
|
| 226 |
'------------------------------------------------------- |
| 227 |
'-- Public Variables For Setting The ZPOPT Structure... |
| 228 |
'-- (WARNING!!!) You Must Set The Options That You |
| 229 |
'-- Want The ZIP32.DLL To Do! |
| 230 |
'-- Before Calling VBZip32! |
| 231 |
'-- |
| 232 |
'-- NOTE: See The Above ZPOPT Structure Or The VBZip32 |
| 233 |
'-- Function, For The Meaning Of These Variables |
| 234 |
'-- And How To Use And Set Them!!! |
| 235 |
'-- These Parameters Must Be Set Before The Actual Call |
| 236 |
'-- To The VBZip32 Function! |
| 237 |
'------------------------------------------------------- |
| 238 |
|
| 239 |
'-- Public Program Variables |
| 240 |
Public zArgc As Integer ' Number Of Files To Zip Up |
| 241 |
Public zZipArchiveName As String ' The Zip File Name ie: Myzip.zip |
| 242 |
Public zZipFileNames As ZIPnames ' File Names To Zip Up |
| 243 |
Public strZipFileNames As String ' String of names to Zip Up |
| 244 |
Public zZipInfo As String ' Holds The Zip File Information |
| 245 |
|
| 246 |
'-- Public Constants |
| 247 |
'-- For Zip & UnZip Error Codes! |
| 248 |
Public Const ZE_OK = 0 ' Success (No Error) |
| 249 |
Public Const ZE_EOF = 2 ' Unexpected End Of Zip File Error |
| 250 |
Public Const ZE_FORM = 3 ' Zip File Structure Error |
| 251 |
Public Const ZE_MEM = 4 ' Out Of Memory Error |
| 252 |
Public Const ZE_LOGIC = 5 ' Internal Logic Error |
| 253 |
Public Const ZE_BIG = 6 ' Entry Too Large To Split Error |
| 254 |
Public Const ZE_NOTE = 7 ' Invalid Comment Format Error |
| 255 |
Public Const ZE_TEST = 8 ' Zip Test (-T) Failed Or Out Of Memory Error |
| 256 |
Public Const ZE_ABORT = 9 ' User Interrupted Or Termination Error |
| 257 |
Public Const ZE_TEMP = 10 ' Error Using A Temp File |
| 258 |
Public Const ZE_READ = 11 ' Read Or Seek Error |
| 259 |
Public Const ZE_NONE = 12 ' Nothing To Do Error |
| 260 |
Public Const ZE_NAME = 13 ' Missing Or Empty Zip File Error |
| 261 |
Public Const ZE_WRITE = 14 ' Error Writing To A File |
| 262 |
Public Const ZE_CREAT = 15 ' Could't Open To Write Error |
| 263 |
Public Const ZE_PARMS = 16 ' Bad Command Line Argument Error |
| 264 |
Public Const ZE_OPEN = 18 ' Could Not Open A Specified File To Read Error |
| 265 |
|
| 266 |
'-- These Functions Are For The ZIP32z64.DLL |
| 267 |
'-- |
| 268 |
'-- Puts A Function Pointer In A Structure |
| 269 |
'-- For Use With Callbacks... |
| 270 |
Public Function FnPtr(ByVal lp As Long) As Long |
| 271 |
|
| 272 |
FnPtr = lp |
| 273 |
|
| 274 |
End Function |
| 275 |
|
| 276 |
'-- Callback For ZIP32z64.DLL - DLL Print Function |
| 277 |
Public Function ZDLLPrnt(ByRef fname As ZipCBChar, ByVal x As Long) As Long |
| 278 |
|
| 279 |
Dim s0 As String |
| 280 |
Dim xx As Long |
| 281 |
|
| 282 |
'-- Always Put This In Callback Routines! |
| 283 |
On Error Resume Next |
| 284 |
|
| 285 |
s0 = "" |
| 286 |
|
| 287 |
'-- Get Zip32.DLL Message For processing |
| 288 |
For xx = 0 To x |
| 289 |
If fname.ch(xx) = 0 Then |
| 290 |
Exit For |
| 291 |
Else |
| 292 |
s0 = s0 + Chr(fname.ch(xx)) |
| 293 |
End If |
| 294 |
Next |
| 295 |
|
| 296 |
'---------------------------------------------- |
| 297 |
'-- This Is Where The DLL Passes Back Messages |
| 298 |
'-- To You! You Can Change The Message Printing |
| 299 |
'-- Below Here! |
| 300 |
'---------------------------------------------- |
| 301 |
|
| 302 |
'-- Display Zip File Information |
| 303 |
'-- zZipInfo = zZipInfo & s0 |
| 304 |
Form1.Print s0; |
| 305 |
|
| 306 |
DoEvents |
| 307 |
|
| 308 |
ZDLLPrnt = 0 |
| 309 |
|
| 310 |
End Function |
| 311 |
|
| 312 |
'-- Callback For ZIP32z64.DLL - DLL Service Function |
| 313 |
Public Function ZDLLServ(ByRef mname As ZipCBChar, _ |
| 314 |
ByVal LowSize As Long, _ |
| 315 |
ByVal HighSize As Long) As Long |
| 316 |
|
| 317 |
Dim s0 As String |
| 318 |
Dim xx As Long |
| 319 |
Dim FS As Currency ' for large file sizes |
| 320 |
|
| 321 |
'-- Always Put This In Callback Routines! |
| 322 |
On Error Resume Next |
| 323 |
|
| 324 |
FS = (HighSize * &H10000 * &H10000) + LowSize |
| 325 |
' Form1.Print "ZDLLServ returned File Size High " & HighSize & _ |
| 326 |
' " Low " & LowSize & " = " & FS & " bytes" |
| 327 |
|
| 328 |
s0 = "" |
| 329 |
'-- Get Zip32.DLL Message For processing |
| 330 |
For xx = 0 To 4096 ' x |
| 331 |
If mname.ch(xx) = 0 Then |
| 332 |
Exit For |
| 333 |
Else |
| 334 |
s0 = s0 + Chr(mname.ch(xx)) |
| 335 |
End If |
| 336 |
Next |
| 337 |
' At this point, s0 contains the message passed from the DLL |
| 338 |
' It is up to the developer to code something useful here :) |
| 339 |
ZDLLServ = 0 ' Setting this to 1 will abort the zip! |
| 340 |
|
| 341 |
End Function |
| 342 |
|
| 343 |
'-- Callback For ZIP32z64.DLL - DLL Password Function |
| 344 |
Public Function ZDLLPass(ByRef p As ZipCBChar, _ |
| 345 |
ByVal n As Long, ByRef m As ZipCBChar, _ |
| 346 |
ByRef Name As ZipCBChar) As Integer |
| 347 |
|
| 348 |
Dim filename As String |
| 349 |
Dim prompt As String |
| 350 |
Dim xx As Integer |
| 351 |
Dim szpassword As String |
| 352 |
|
| 353 |
'-- Always Put This In Callback Routines! |
| 354 |
On Error Resume Next |
| 355 |
|
| 356 |
ZDLLPass = 1 |
| 357 |
|
| 358 |
'-- User Entered A Password So Proccess It |
| 359 |
|
| 360 |
'-- Enter or Verify |
| 361 |
For xx = 0 To 255 |
| 362 |
If m.ch(xx) = 0 Then |
| 363 |
Exit For |
| 364 |
Else |
| 365 |
prompt = prompt & Chr(m.ch(xx)) |
| 366 |
End If |
| 367 |
Next |
| 368 |
|
| 369 |
'-- If There Is A Password Have The User Enter It! |
| 370 |
'-- This Can Be Changed |
| 371 |
|
| 372 |
'-- Now skip asking if default password set |
| 373 |
If EncryptionPassword <> "" Then |
| 374 |
szpassword = EncryptionPassword |
| 375 |
Else |
| 376 |
szpassword = InputBox("Please Enter The Password!", prompt) |
| 377 |
End If |
| 378 |
|
| 379 |
'-- The User Did Not Enter A Password So Exit The Function |
| 380 |
If szpassword = "" Then Exit Function |
| 381 |
|
| 382 |
For xx = 0 To n - 1 |
| 383 |
p.ch(xx) = 0 |
| 384 |
Next |
| 385 |
|
| 386 |
For xx = 0 To Len(szpassword) - 1 |
| 387 |
p.ch(xx) = Asc(Mid(szpassword, xx + 1, 1)) |
| 388 |
Next |
| 389 |
|
| 390 |
p.ch(xx) = Chr(0) ' Put Null Terminator For C |
| 391 |
|
| 392 |
ZDLLPass = 0 |
| 393 |
|
| 394 |
End Function |
| 395 |
|
| 396 |
'-- Callback For ZIP32z64.DLL - DLL Comment Function |
| 397 |
Public Function ZDLLComm(ByRef s1 As ZipCBChar) As Integer |
| 398 |
|
| 399 |
Dim comment As String |
| 400 |
Dim xx%, szcomment$ |
| 401 |
|
| 402 |
'-- Always Put This In Callback Routines! |
| 403 |
On Error Resume Next |
| 404 |
|
| 405 |
ZDLLComm = 1 |
| 406 |
If Not IsEmpty(ArchiveCommentText) Then |
| 407 |
' use text given to SetZipOptions |
| 408 |
szcomment = ArchiveCommentText |
| 409 |
Else |
| 410 |
For xx = 0 To 4095 |
| 411 |
szcomment = szcomment & Chr(s1.ch(xx)) |
| 412 |
If s1.ch(xx) = 0 Then |
| 413 |
Exit For |
| 414 |
End If |
| 415 |
Next |
| 416 |
comment = InputBox("Enter or edit the comment", Default:=szcomment) |
| 417 |
If comment = "" Then |
| 418 |
' either empty comment or Cancel button |
| 419 |
If MsgBox("Remove comment?" & Chr(13) & "Hit No to keep existing comment", vbYesNo) = vbYes Then |
| 420 |
szcomment = comment |
| 421 |
Else |
| 422 |
Exit Function |
| 423 |
End If |
| 424 |
End If |
| 425 |
szcomment = comment |
| 426 |
End If |
| 427 |
'If szcomment = "" Then Exit Function |
| 428 |
For xx = 0 To Len(szcomment) - 1 |
| 429 |
s1.ch(xx) = Asc(Mid$(szcomment, xx + 1, 1)) |
| 430 |
Next xx |
| 431 |
s1.ch(xx) = 0 ' Put null terminator for C |
| 432 |
|
| 433 |
End Function |
| 434 |
|
| 435 |
' This function can be used to set options in VB |
| 436 |
Public Function SetZipOptions(ByRef ZipOpts As ZpOpt, _ |
| 437 |
Optional ByVal ZipMode As ZipModeType = Add, _ |
| 438 |
Optional ByVal RootDirToZipFrom As String = "", _ |
| 439 |
Optional ByVal CompressionLevel As CompressionLevelType = c6_Default, _ |
| 440 |
Optional ByVal RecurseSubdirectories As RecurseType = NoRecurse, _ |
| 441 |
Optional ByVal Verboseness As VerbosenessType = Normal, _ |
| 442 |
Optional ByVal i_IncludeFiles As String = "", _ |
| 443 |
Optional ByVal x_ExcludeFiles As String = "", _ |
| 444 |
Optional ByVal UpdateSFXOffsets As Boolean = False, Optional ByVal JunkDirNames As Boolean = False, _ |
| 445 |
Optional ByVal Encrypt As Boolean = False, Optional ByVal Password As String = "", _ |
| 446 |
Optional ByVal Repair As RepairType = NoRepair, Optional ByVal NoDirEntries As Boolean = False, _ |
| 447 |
Optional ByVal GrowExistingArchive As Boolean = False, _ |
| 448 |
Optional ByVal JunkSFXPrefix As Boolean = False, Optional ByVal ForceUseOfDOSNames As Boolean = False, _ |
| 449 |
Optional ByVal Translate_LF As Translate_LF_Type = No_Line_End_Trans, _ |
| 450 |
Optional ByVal Move_DeleteAfterAddedOrUpdated As Boolean = False, _ |
| 451 |
Optional ByVal SetZipTimeToLatestTime As Boolean = False, _ |
| 452 |
Optional ByVal IncludeSystemAndHiddenFiles As Boolean = False, _ |
| 453 |
Optional ByVal ExcludeEarlierThanDate As String = "", _ |
| 454 |
Optional ByVal IncludeEarlierThanDate As String = "", _ |
| 455 |
Optional ByVal IncludeVolumeLabel As Boolean = False, _ |
| 456 |
Optional ByVal ArchiveComment As Boolean = False, _ |
| 457 |
Optional ByVal ArchiveCommentTextString = Empty, _ |
| 458 |
Optional ByVal UsePrivileges As Boolean = False, _ |
| 459 |
Optional ByVal ExcludeExtraAttributes As Boolean = False, Optional ByVal SplitSize As String = "", _ |
| 460 |
Optional ByVal TempDirPath As String = "") As Boolean |
| 461 |
|
| 462 |
Dim SplitNum As Long |
| 463 |
Dim SplitMultS As String |
| 464 |
Dim SplitMult As Long |
| 465 |
|
| 466 |
' set some defaults |
| 467 |
ZipOpts.date = vbNullString |
| 468 |
ZipOpts.szRootDir = vbNullString |
| 469 |
ZipOpts.szTempDir = vbNullString |
| 470 |
ZipOpts.fTemp = 0 |
| 471 |
ZipOpts.fSuffix = 0 |
| 472 |
ZipOpts.fEncrypt = 0 |
| 473 |
ZipOpts.fSystem = 0 |
| 474 |
ZipOpts.fVolume = 0 |
| 475 |
ZipOpts.fExtra = 0 |
| 476 |
ZipOpts.fNoDirEntries = 0 |
| 477 |
ZipOpts.fExcludeDate = 0 |
| 478 |
ZipOpts.fIncludeDate = 0 |
| 479 |
ZipOpts.fVerbose = 0 |
| 480 |
ZipOpts.fQuiet = 0 |
| 481 |
ZipOpts.fCRLF_LF = 0 |
| 482 |
ZipOpts.fLF_CRLF = 0 |
| 483 |
ZipOpts.fJunkDir = 0 |
| 484 |
ZipOpts.fGrow = 0 |
| 485 |
ZipOpts.fForce = 0 |
| 486 |
ZipOpts.fMove = 0 |
| 487 |
ZipOpts.fDeleteEntries = 0 |
| 488 |
ZipOpts.fUpdate = 0 |
| 489 |
ZipOpts.fFreshen = 0 |
| 490 |
ZipOpts.fJunkSFX = 0 |
| 491 |
ZipOpts.fLatestTime = 0 |
| 492 |
ZipOpts.fComment = 0 |
| 493 |
ZipOpts.fOffsets = 0 |
| 494 |
ZipOpts.fPrivilege = 0 |
| 495 |
ZipOpts.szSplitSize = vbNullString |
| 496 |
ZipOpts.IncludeListCount = 0 |
| 497 |
ZipOpts.szIncludeList = vbNullString |
| 498 |
ZipOpts.ExcludeListCount = 0 |
| 499 |
ZipOpts.szExcludeList = vbNullString |
| 500 |
ZipOpts.fRecurse = 0 |
| 501 |
ZipOpts.fRepair = 0 |
| 502 |
ZipOpts.flevel = 0 |
| 503 |
|
| 504 |
If RootDirToZipFrom <> "" Then |
| 505 |
ZipOpts.szRootDir = RootDirToZipFrom |
| 506 |
End If |
| 507 |
ZipOpts.flevel = Asc(CompressionLevel) |
| 508 |
If UpdateSFXOffsets Then ZipOpts.fOffsets = 1 |
| 509 |
|
| 510 |
If i_IncludeFiles <> "" Then |
| 511 |
ZipOpts.szIncludeList = i_IncludeFiles |
| 512 |
End If |
| 513 |
If x_ExcludeFiles <> "" Then |
| 514 |
ZipOpts.szExcludeList = x_ExcludeFiles |
| 515 |
End If |
| 516 |
|
| 517 |
If ZipMode = Add Then |
| 518 |
' default |
| 519 |
ElseIf ZipMode = Delete Then |
| 520 |
ZipOpts.fDeleteEntries = 1 |
| 521 |
ElseIf ZipMode = Update Then |
| 522 |
ZipOpts.fUpdate = 1 |
| 523 |
Else |
| 524 |
ZipOpts.fFreshen = 1 |
| 525 |
End If |
| 526 |
ZipOpts.fRepair = Repair |
| 527 |
If GrowExistingArchive Then ZipOpts.fGrow = 1 |
| 528 |
If Move_DeleteAfterAddedOrUpdated Then ZipOpts.fMove = 1 |
| 529 |
|
| 530 |
If Verboseness = Quiet Then |
| 531 |
ZipOpts.fQuiet = 1 |
| 532 |
ElseIf Verboseness = Verbose Then |
| 533 |
ZipOpts.fVerbose = 1 |
| 534 |
End If |
| 535 |
|
| 536 |
If ArchiveComment = False And Not IsEmpty(ArchiveCommentTextString) Then |
| 537 |
MsgBox "Must set ArchiveComment = True to set ArchiveCommentTextString" |
| 538 |
Exit Function |
| 539 |
End If |
| 540 |
If IsEmpty(ArchiveCommentTextString) Then |
| 541 |
ArchiveCommentText = Empty |
| 542 |
Else |
| 543 |
ArchiveCommentText = ArchiveCommentTextString |
| 544 |
End If |
| 545 |
If ArchiveComment Then ZipOpts.fComment = 1 |
| 546 |
|
| 547 |
If NoDirEntries Then ZipOpts.fNoDirEntries = 1 |
| 548 |
If JunkDirNames Then ZipOpts.fJunkDir = 1 |
| 549 |
If Encrypt Then ZipOpts.fEncrypt = 1 |
| 550 |
EncryptionPassword = Password |
| 551 |
If JunkSFXPrefix Then ZipOpts.fJunkSFX = 1 |
| 552 |
If ForceUseOfDOSNames Then ZipOpts.fForce = 1 |
| 553 |
If Translate_LF = LF_To_CRLF Then ZipOpts.fLF_CRLF = 1 |
| 554 |
If Translate_LF = CRLF_To_LF Then ZipOpts.fCRLF_LF = 1 |
| 555 |
ZipOpts.fRecurse = RecurseSubdirectories |
| 556 |
If IncludeSystemAndHiddenFiles Then ZipOpts.fSystem = 1 |
| 557 |
|
| 558 |
If SetZipTimeToLatestTime Then ZipOpts.fLatestTime = 1 |
| 559 |
If ExcludeEarlierThanDate <> "" And IncludeEarlierThanDate <> "" Then |
| 560 |
MsgBox "Both ExcludeEarlierThanDate and IncludeEarlierThanDate not " & Chr(10) & _ |
| 561 |
"supported at same time" |
| 562 |
Exit Function |
| 563 |
End If |
| 564 |
If ExcludeEarlierThanDate <> "" Then |
| 565 |
ZipOpts.fIncludeDate = 1 |
| 566 |
ZipOpts.date = ExcludeEarlierThanDate |
| 567 |
End If |
| 568 |
If IncludeEarlierThanDate <> "" Then |
| 569 |
ZipOpts.fExcludeDate = 1 |
| 570 |
ZipOpts.date = IncludeEarlierThanDate |
| 571 |
End If |
| 572 |
|
| 573 |
If TempDirPath <> "" Then |
| 574 |
ZipOpts.szTempDir = TempDirPath |
| 575 |
ZipOpts.fTemp = 1 |
| 576 |
End If |
| 577 |
|
| 578 |
If SplitSize <> "" Then |
| 579 |
SplitSize = Trim(SplitSize) |
| 580 |
SplitMultS = Right(SplitSize, 1) |
| 581 |
SplitMultS = UCase(SplitMultS) |
| 582 |
If (SplitMultS = "K") Then |
| 583 |
SplitMult = 1024 |
| 584 |
SplitNum = Val(Left(SplitSize, Len(SplitSize) - 1)) |
| 585 |
ElseIf SplitMultS = "M" Then |
| 586 |
SplitMult = 1024 * 1024& |
| 587 |
SplitNum = Val(Left(SplitSize, Len(SplitSize) - 1)) |
| 588 |
ElseIf SplitMultS = "G" Then |
| 589 |
SplitMult = 1024 * 1024 * 1024& |
| 590 |
SplitNum = Val(Left(SplitSize, Len(SplitSize) - 1)) |
| 591 |
Else |
| 592 |
SplitMult = 1024 * 1024& |
| 593 |
SplitNum = Val(SplitSize) |
| 594 |
End If |
| 595 |
SplitNum = SplitNum * SplitMult |
| 596 |
If SplitNum = 0 Then |
| 597 |
MsgBox "SplitSize of 0 not supported" |
| 598 |
Exit Function |
| 599 |
ElseIf SplitNum < 64 * 1024& Then |
| 600 |
MsgBox "SplitSize must be at least 64k" |
| 601 |
Exit Function |
| 602 |
End If |
| 603 |
ZipOpts.szSplitSize = SplitSize |
| 604 |
End If |
| 605 |
|
| 606 |
If IncludeVolumeLabel Then ZipOpts.fVolume = 1 |
| 607 |
If UsePrivileges Then ZipOpts.fPrivilege = 1 |
| 608 |
If ExcludeExtraAttributes Then ZipOpts.fExtra = 1 |
| 609 |
|
| 610 |
SetZipOptions = True |
| 611 |
|
| 612 |
End Function |
| 613 |
|
| 614 |
Function ChopNulls(ByVal Str) As String |
| 615 |
Dim A As Integer |
| 616 |
Dim C As String |
| 617 |
|
| 618 |
For A = 1 To Len(Str) |
| 619 |
If Mid(Str, A, 1) = Chr(0) Then |
| 620 |
ChopNulls = Left(Str, A - 1) |
| 621 |
Exit Function |
| 622 |
End If |
| 623 |
Next |
| 624 |
ChopNulls = Str |
| 625 |
|
| 626 |
End Function |
| 627 |
Sub DisplayVersion() |
| 628 |
|
| 629 |
' display version of DLL |
| 630 |
Dim Beta As Boolean |
| 631 |
Dim ZLIB As Boolean |
| 632 |
Dim Zip64 As Boolean |
| 633 |
Dim Flags As String |
| 634 |
Dim A As Integer |
| 635 |
|
| 636 |
ZipVersion.structlen = Len(ZipVersion) |
| 637 |
ZpVersion ZipVersion |
| 638 |
' Check flag |
| 639 |
If ZipVersion.flag And 1 Then |
| 640 |
Flags = Flags & " Beta," |
| 641 |
Beta = True |
| 642 |
Else |
| 643 |
Flags = Flags & " No Beta," |
| 644 |
End If |
| 645 |
If ZipVersion.flag And 2 Then |
| 646 |
Flags = Flags & " ZLIB," |
| 647 |
ZLIB = True |
| 648 |
Else |
| 649 |
Flags = Flags & " No ZLIB," |
| 650 |
End If |
| 651 |
If ZipVersion.flag And 4 Then |
| 652 |
Flags = Flags & " Zip64, " |
| 653 |
Zip64 = True |
| 654 |
Else |
| 655 |
Flags = Flags & " No Zip64, " |
| 656 |
End If |
| 657 |
If ZipVersion.encryption Then |
| 658 |
Flags = Flags & "Encryption" |
| 659 |
Else |
| 660 |
Flags = Flags & " No encryption" |
| 661 |
End If |
| 662 |
|
| 663 |
Form1.Caption = "Using Zip32z64.DLL Version " & _ |
| 664 |
ZipVersion.ZipVersion.Major & "." & ZipVersion.ZipVersion.Minor & " " & _ |
| 665 |
ChopNulls(ZipVersion.Beta) & " [" & ChopNulls(ZipVersion.date) & "]" & _ |
| 666 |
" - FLAGS: " & Flags |
| 667 |
|
| 668 |
If Not Zip64 Then |
| 669 |
A = MsgBox("Zip32z64.dll not compiled with Zip64 enabled - continue?", _ |
| 670 |
vbOKCancel, _ |
| 671 |
"Wrong dll") |
| 672 |
If A = vbCancel Then |
| 673 |
End |
| 674 |
End If |
| 675 |
End If |
| 676 |
|
| 677 |
End Sub |
| 678 |
|
| 679 |
'-- Main ZIP32.DLL Subroutine. |
| 680 |
'-- This Is Where It All Happens!!! |
| 681 |
'-- |
| 682 |
'-- (WARNING!) Do Not Change This Function!!! |
| 683 |
'-- |
| 684 |
Public Function VBZip32() As Long |
| 685 |
|
| 686 |
Dim retcode As Long |
| 687 |
Dim FileNotFound As Boolean |
| 688 |
|
| 689 |
' On Error Resume Next '-- Nothing Will Go Wrong :-) |
| 690 |
On Error GoTo ZipError |
| 691 |
|
| 692 |
retcode = 0 |
| 693 |
|
| 694 |
'-- Set Address Of ZIP32.DLL Callback Functions |
| 695 |
'-- (WARNING!) Do Not Change!!! (except as noted below) |
| 696 |
ZUSER.ZDLLPrnt = FnPtr(AddressOf ZDLLPrnt) |
| 697 |
ZUSER.ZDLLPASSWORD = FnPtr(AddressOf ZDLLPass) |
| 698 |
ZUSER.ZDLLCOMMENT = FnPtr(AddressOf ZDLLComm) |
| 699 |
ZUSER.ZDLLSERVICE_NO_INT64 = FnPtr(AddressOf ZDLLServ) |
| 700 |
|
| 701 |
' If you need to set destination of each split set this |
| 702 |
'ZUSER.ZDLLSPLIT = FnPtr(AddressOf ZDLLSplitSelect) |
| 703 |
|
| 704 |
'-- Set ZIP32.DLL Callbacks - return 1 if DLL loaded 0 if not |
| 705 |
retcode = ZpInit(ZUSER) |
| 706 |
If retcode = 0 And FileNotFound Then |
| 707 |
MsgBox "Probably could not find Zip32z64.DLL - have you copied" & Chr(10) & _ |
| 708 |
"it to the System directory, your program directory, " & Chr(10) & _ |
| 709 |
"or a directory on your command PATH?" |
| 710 |
VBZip32 = retcode |
| 711 |
Exit Function |
| 712 |
End If |
| 713 |
|
| 714 |
DisplayVersion |
| 715 |
|
| 716 |
If strZipFileNames = "" Then |
| 717 |
' not using string of names to zip (so using array of names) |
| 718 |
strZipFileNames = vbNullString |
| 719 |
End If |
| 720 |
|
| 721 |
'-- Go Zip It Them Up! |
| 722 |
retcode = ZpArchive(zArgc, zZipArchiveName, zZipFileNames, strZipFileNames, ZOPT) |
| 723 |
|
| 724 |
'-- Return The Function Code |
| 725 |
VBZip32 = retcode |
| 726 |
|
| 727 |
Exit Function |
| 728 |
|
| 729 |
ZipError: |
| 730 |
MsgBox "Error: " & Err.Description |
| 731 |
If Err = 48 Then |
| 732 |
FileNotFound = True |
| 733 |
End If |
| 734 |
Resume Next |
| 735 |
|
| 736 |
End Function |
| 737 |
|