VBZipBas.bas 24 KB

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