home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD13332132001.psc / ArZip.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-01-04  |  24.2 KB  |  678 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "ArZip"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. '------------------------------------------------------------------
  15. 'Module     : ArZip Class
  16. 'Description: Ariel Compression Class
  17. 'Release    : 2001 VB6
  18. 'Copyright  : ⌐ T De Lange, 2000
  19. '------------------------------------------------------------------
  20. 'Credits:
  21. 'a) Peter Meier, Planet Source Code for the icon extraction technique
  22. '   in his 'DelRecent' posting
  23. 'b) Recursive folder list: Brad V (Planet Source Code)
  24. '   Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.11429/lngWId.1/qx/vb/scripts/ShowCode.htm
  25. '   for details.
  26. '------------------------------------------------------------------
  27. 'Notes: Add a reference to Microsoft Scripting Runtime dll
  28. '       in the project references box
  29. '------------------------------------------------------------------
  30. Option Base 1
  31. Option Explicit
  32. DefLng A-N, P-Z
  33. DefBool O
  34.  
  35. '----------------------------------------------------------
  36. 'Private Constants
  37. '----------------------------------------------------------
  38. Const ModName = "ArielZip Class"
  39. 'Icon Sizes in pixels
  40. Private Const LARGE_ICON As Integer = 32    'Icon Size, pixels
  41. Private Const SMALL_ICON As Integer = 16    'Icon size
  42. Private Const MAX_PATH = 260                'Max length of path+file name
  43. Private Const ILD_TRANSPARENT = &H1         'Display icon transparent
  44. Private Const BMP_SIZE As Long = 822        'Size in bytes of icon bitmaps
  45. Private Const CHUNK_SIZE As Long = 1048576  'Chunk size 1Mb to write archive file
  46.  
  47. 'ShellInfo Flags
  48. Private Const SHGFI_DISPLAYNAME = &H200
  49. Private Const SHGFI_EXETYPE = &H2000
  50. Private Const SHGFI_SYSICONINDEX = &H4000 'System icon index
  51. Private Const SHGFI_LARGEICON = &H0       'Large icon
  52. Private Const SHGFI_SMALLICON = &H1       'Small icon
  53. Private Const SHGFI_SHELLICONSIZE = &H4
  54. Private Const SHGFI_TYPENAME = &H400
  55.  
  56. Private Const BASIC_SHGFI_FLAGS = SHGFI_TYPENAME _
  57.         Or SHGFI_SHELLICONSIZE Or SHGFI_SYSICONINDEX _
  58.         Or SHGFI_DISPLAYNAME Or SHGFI_EXETYPE
  59.  
  60. '----------------------------------------------------------
  61. 'Public Enums
  62. '----------------------------------------------------------
  63. Public Enum ArZipStatus
  64.   azsEmpty          'Empty
  65.   azsReady          'File & Rootfolder specified
  66.   azsCreated        'Zipfile created (ready for extraction)
  67.   azsBusy
  68. End Enum
  69.  
  70. Public Enum ArSpanOption
  71.   azo1440     '1.44Mb
  72.   azo1400     '1.40Mb
  73.   azo1200     '1.20Mb
  74.   azo1000     '1.00Mb
  75.   azo720      '720kb
  76.   azo700      '700kb
  77.   azo100p     '100% Capacity (Removable drives only)
  78.   azo99p      '99% Capacity     "
  79.   azo98p      '98% Capacity     "
  80.   azo95p      '95% Capacity     "
  81.   azo90p      '90% Capacity     "
  82. End Enum
  83.   
  84. Private Enum ZLibErrors
  85.   'Positive numbers are normal occasions, neg's are errors
  86.   zlOk = 0
  87.   zlStreamEnd = 1
  88.   zlNeedDict = 2
  89.   zlErrNo = -1
  90.   zlStreamError = -2      'Invalid compression level parameter
  91.   zlDataError = -3        'Input data corrupted
  92.   zlMemError = -4         'Not Enough Memory
  93.   zlBufError = -5         'Not enough space in output buffer
  94.   zlVersionError = -6
  95. End Enum
  96.   
  97. '----------------------------------------------------------
  98. 'Private Type Defs
  99. '----------------------------------------------------------
  100. Private Type SHFILEINFO              'As required by ShInfo
  101.   hIcon As Long
  102.   iIcon As Long
  103.   dwAttributes As Long
  104.   szDisplayName As String * MAX_PATH
  105.   szTypeName As String * 80
  106. End Type
  107.  
  108. Private Type ArielFile
  109.   Key As String         'Path\File.ext
  110.   Name As String        'Filename including extension, without path
  111.   Ext As String         'File extension
  112.   Path As String        'Path, eg C:\My Documents (to locate file on HDD)
  113.   RelPath As String     'Relative path in archive e.g. \Memos
  114.   Zipped As Boolean     'Has file been zipped already?
  115.   Size As Long          'Original file size
  116.   ZipSize As Long       'Zip size
  117.   Ratio As Single       'Zip ratio 0 to 1
  118.   Modified As Date
  119.   IconKey As String
  120.   Offset As Long        'Offset of file in CURRENT volume
  121.   ChkSum As Byte        'XOR Checksum from original file back to unzipped file
  122.   ChkSumZip As Byte     'XOR Checksum from zipped file write to read
  123.   Selected As Boolean
  124. End Type
  125.  
  126. Private Type ArHeader
  127.   'Added at the start of each span volume
  128.   'Id As String * 3     'Don't use fixed/variable strings in copymem()
  129.   Major As Integer
  130.   Minor As Integer
  131.   VolNo As Byte         'Span Volume no, starting at 1
  132.   NextVol As Byte       'Indicates another volume follows (1), or not (0)
  133.   ZipSize As Long       'Total zip file size, prior to spanning
  134.   NoFiles As Long       'No of files in archive
  135.   NoIcons As Long       'No of unique icons (bitmaps) in archive
  136.   Offset  As Long       'Offset to start of file list
  137. End Type
  138.  
  139. Private Type ArFileRec
  140.   Offset As Long
  141.   OrigSize As Long
  142.   ZipSize As Long
  143.   Modified As Date
  144.   ChkSum As Byte
  145.   ChkSumZip As Byte
  146. End Type
  147.   
  148. '----------------------------------------------------------
  149. 'Functions & Procedures
  150. '----------------------------------------------------------
  151. 'Functions to extract icons & place them in a picture box
  152. Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _
  153.     (ByVal pszPath As String, _
  154.     ByVal dwFileAttributes As Long, _
  155.     psfi As SHFILEINFO, _
  156.     ByVal cbSizeFileInfo As Long, _
  157.     ByVal uFlags As Long) As Long
  158.  
  159. Private Declare Function ImageList_Draw Lib "comctl32.dll" _
  160.     (ByVal himl&, ByVal i&, ByVal hDCDest&, _
  161.     ByVal x&, ByVal y&, ByVal flags&) As Long
  162.  
  163. 'General Kernel.dll functions
  164. Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  165. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  166.  
  167. 'Sleep & Timer functions - see Wait()
  168. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  169. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
  170.  
  171. 'ZLib 1.1.3 functions
  172. 'Private Declare Function CompressDef Lib "zlib.dll" Alias "compress" (Dest As Any, DestLen As Long, Source As Any, ByVal SourceLen As Long) As Long
  173. Private Declare Function Compress Lib "zlib.dll" Alias "compress2" (Dest As Any, DestLen As Long, Source As Any, ByVal SourceLen As Long, ByVal Level As Long) As Long
  174. Private Declare Function Uncompress Lib "zlib.dll" Alias "uncompress" (Dest As Any, DestLen As Long, Source As Any, ByVal SourceLen As Long) As Long
  175.  
  176. '----------------------------------------------------------
  177. 'Private property variables
  178. '----------------------------------------------------------
  179. Private mRootFolder As String
  180. Private mStatus As ArZipStatus
  181. Private mExist As Boolean         'Does a current zip file exist?
  182. Private mZipFileNew As String     'Zip path & file name
  183. Private mZipFile As String     'Current zip file
  184. Private mTempFolder As String     'Scratch area (used to save icon bitmaps)
  185. Private mTempFile As String       'For use only during disk spanning, placed in tempfolder
  186. Private mBackupFile As String     'Used for storage of existing data, during zipping
  187. Private mUnzipFolder As String
  188. Private mElapsedTime As Single
  189. Private mCompressLevel As Integer
  190. Private mSpanning As Boolean      'Must new zip file be spanned?
  191. Private mSpanned As Boolean       'Has current zip file been spanned?
  192. Private mSpanOption As Long       'Span option for new zip file
  193. Private mSpanSize As Long         'Size of selected span option (new file)
  194. Private mTotalZipSize As Long
  195. Private mCancel As Boolean        'Used to cancel zip/unzip operation
  196.  
  197. '----------------------------------------------------------
  198. 'Events
  199. '----------------------------------------------------------
  200. Public Event StatusChange(NewStatus As ArZipStatus)
  201. Public Event Progress(Value As Single, Info As String)
  202. Public Event ChangeDisk(Drive As Drive, Message As String, File As String)
  203.  
  204. '----------------------------------------------------------
  205. 'Private variables
  206. '----------------------------------------------------------
  207. Private ShInfo As SHFILEINFO
  208. Private mLvwFiles As ListView
  209. Private mIml As ImageList                 'Imagelist containing small icons
  210. Private mPic As PictureBox                'Temporay container for small icon
  211. Private mPicDef As PictureBox             'Default picture for <None> icons
  212. Private mFso As New FileSystemObject      'File system object
  213. Private aFiles() As ArielFile             'Array of files
  214. Private nFiles As Long                    'No of files in array
  215. Private mProgress As Single               'Progress 0 to 1
  216. Private nIcons As Long                    'No of unique icons
  217. Private nPos As Long                      'Temporary posistion in archive file
  218. Private Function AddByte(ByRef Bytes() As Byte, Value As Byte) As Long
  219. '---------------------------------------------------------------------
  220. 'Add a byte value to the byte array
  221. '---------------------------------------------------------------------
  222. Dim ns
  223.  
  224. On Error Resume Next
  225. ns = UBound(Bytes)
  226. If ns = 0 Then
  227.   ReDim Bytes(1) As Byte      'Necessary, to get rid of 0 lower bound
  228. Else
  229.   ReDim Preserve Bytes(ns + 1) As Byte
  230. End If
  231. Call CopyMem(Bytes(ns + 1), Value, 1)
  232. AddByte = UBound(Bytes)
  233.  
  234. End Function
  235.  
  236. Private Function AddFile(ByRef File As File) As Boolean
  237. '---------------------------------------------------------------
  238. 'Adds a file to the array
  239. 'Returns true if successful
  240. '---------------------------------------------------------------
  241. 'Notes
  242. 'a) The file to be included is validated for existence at source
  243. '   and if it is not the current archive file (or spanned volume)
  244. 'b) If it already is in the list (and even in the archive) the
  245. '   file is 'freshened' with the current source info. I.e. by
  246. '   default the source file is to be considered a later/newer
  247. '   version. The zipped flag is set to false to prevent the
  248. '   current zipped version being included in the archive.
  249. '---------------------------------------------------------------
  250. Dim Ok, n
  251.  
  252. Ok = ValidateFile(File)
  253. If Ok Then
  254.   n = FileInList(File)
  255.   If n = 0 Then
  256.     'Add file to the list
  257.     nFiles = nFiles + 1
  258.     ReDim Preserve aFiles(nFiles) As ArielFile
  259.     n = nFiles
  260.     aFiles(n).ZipSize = File.Size       'Keep the same as original size for now
  261.     aFiles(n).Ratio = 1
  262.     aFiles(n).Zipped = False
  263.   Else
  264.     'Freshen file
  265.     aFiles(n).Zipped = False
  266.   End If
  267.   aFiles(n).Name = File.Name
  268.   aFiles(n).Modified = File.DateLastModified
  269.   aFiles(n).Size = File.Size
  270.   aFiles(n).Path = File.ParentFolder
  271.   aFiles(n).RelPath = RelPath(File.ParentFolder, mRootFolder)
  272.   aFiles(n).Ext = FileExtension(File.Name)
  273.   aFiles(n).Key = aFiles(nFiles).RelPath & "\" & aFiles(nFiles).Name
  274.   aFiles(n).IconKey = GetIconKey(File)
  275.   AddFile = True
  276. Else
  277.   AddFile = False
  278. End If
  279.  
  280. End Function
  281. Private Function AddBlankFileRecords(Bytes() As Byte) As Long
  282. '---------------------------------------------------
  283. 'Add an empty file header to the byte array for
  284. 'each file
  285. 'a) This to be updated later
  286. 'b) The string portions are added in a separater sub
  287. '   after the file list has been written
  288. 'Return the ubound() of Bytes()
  289. '---------------------------------------------------
  290. Dim Afr As ArFileRec
  291. Dim ns, n
  292.  
  293. On Error Resume Next
  294. ns = UBound(Bytes)
  295. n = Len(Afr) * nFiles
  296. If ns = 0 Then
  297.   ReDim Bytes(n) As Byte          'Necessary to get rid of a 0 lower bound
  298. Else
  299.   ReDim Preserve Bytes(ns + n) As Byte
  300. End If
  301. AddBlankFileRecords = UBound(Bytes)
  302.  
  303. End Function
  304.  
  305. Private Function AddFileName(Bytes() As Byte, i As Long) As Long
  306. '-----------------------------------------------------------------
  307. 'Add the string portion of a file to the byte array
  308. 'a) The numeric portions are dealt with separately
  309. '   as they need to be updated at the end of the zip file
  310. 'b) All strings are variable length, so add a vbCr at the end
  311. 'Return the ubound() of Bytes()
  312. '-----------------------------------------------------------------
  313. On Error Resume Next
  314.  
  315. AddString Bytes, aFiles(i).Name, True         'File name incl ext
  316. AddString Bytes, aFiles(i).RelPath, True      'Relative path (to rootfolder)
  317. AddString Bytes, aFiles(i).Path, True         'Absolute path
  318. AddString Bytes, aFiles(i).IconKey, True      'Icon key in image list
  319. AddFileName = UBound(Bytes)
  320.  
  321. End Function
  322.  
  323. Public Function AddFiles(FileList() As String) As Long
  324. '------------------------------------------------
  325. 'Add files to the archive list
  326. 'FileList :  Contains the file name(s)
  327. 'Return   :  NoFiles added
  328. '------------------------------------------------
  329. 'Note: if only 1 file was added, the file
  330. '      path & name is given in element 0
  331. '      if multiselection was done, element 0
  332. '      contains the path and the others the
  333. '      file names, excl path
  334. '------------------------------------------------
  335. Dim Path As String      'Path of files
  336. Dim File As File
  337. Dim i, n, m, Ok
  338.  
  339. On Error Resume Next
  340. Screen.MousePointer = vbArrowHourglass
  341. SetStatus azsBusy
  342. 'mlvwfiles.SmallIcons=nothing
  343. n = UBound(FileList)
  344. If n = 0 Then
  345.   'Single File
  346.   Set File = mFso.GetFile(FileList(0))
  347.   Ok = AddFile(File)
  348.   m = IIf(Ok, 1, 0)
  349. Else
  350.   'Multiple Files
  351.   'Get the path (element 0)
  352.   Path = CheckPath(FileList(0))
  353.   For i = 1 To n
  354.     Set File = mFso.GetFile(Path & FileList(i))
  355.     Ok = AddFile(File)
  356.     If Ok Then m = m + 1
  357.     'DoEvents
  358.   Next
  359.   AddFiles = m          'Set the return parameter
  360. End If
  361. mLvwFiles.SmallIcons = mIml       'Set the smallicons imagelist
  362. Screen.MousePointer = vbNormal
  363. SetStatus azsReady
  364.  
  365. End Function
  366.  
  367. Public Function AddFolder(Rootfolder As String, IncludeSubfolders As Boolean) As Long
  368. '---------------------------------------------------------------------------------------------------------------
  369. 'Add a folder (and subfolders) to the archive list
  370. 'Rootfolder         : Path of folder to add
  371. 'IncludeSubfolders  : Include subfolders' contents in the archive
  372. 'Return             : Total NoFiles now in list
  373. '---------------------------------------------------------------------------------------------------------------
  374.  
  375. On Error Resume Next
  376. Screen.MousePointer = vbArrowHourglass
  377. SetStatus azsBusy
  378. ScanTree Rootfolder, IncludeSubfolders    'Recursive tree scan
  379. mLvwFiles.SmallIcons = mIml               'Set the smallicons imagelist
  380. Screen.MousePointer = vbNormal
  381. SetStatus azsReady
  382. AddFolder = nFiles                        'Set the return parameter
  383.  
  384. End Function
  385.  
  386. Private Function AddIconRecord(Bytes() As Byte, Bmp() As Byte, Key As String) As Long
  387. '---------------------------------------------------
  388. 'Add an icon record (key & bmp) to the Byte array
  389. 'Return the ubound() of Bytes()
  390. '---------------------------------------------------
  391. On Error Resume Next
  392.  
  393. AddString Bytes, Key, True      'Icon key (see imglist)
  394. AddBytes Bytes, Bmp
  395. AddIconRecord = UBound(Bytes)
  396.  
  397. End Function
  398.  
  399. Private Function AddInt(ByRef Bytes() As Byte, Value As Integer) As Long
  400. '---------------------------------------------------------------------
  401. 'Add integer value to the byte array
  402. '---------------------------------------------------------------------
  403. Dim ns
  404.  
  405. On Error Resume Next
  406. ns = UBound(Bytes)
  407. If ns = 0 Then
  408.   ReDim Bytes(2) As Byte      'Necessary, to get rid of 0 lower bound
  409. Else
  410.   ReDim Preserve Bytes(ns + 2) As Byte
  411. End If
  412. Call CopyMem(Bytes(ns + 1), Value, 2)
  413. AddInt = UBound(Bytes)
  414.  
  415. End Function
  416.  
  417. Private Function AddLong(ByRef Bytes() As Byte, Value As Long) As Long
  418. '---------------------------------------------------------------------
  419. 'Add long value to the byte array
  420. '---------------------------------------------------------------------
  421. Dim ns
  422.  
  423. On Error Resume Next
  424. ns = UBound(Bytes)
  425. If ns = 0 Then
  426.   ReDim Bytes(4) As Byte      'Necessary, to get rid of 0 lower bound
  427. Else
  428.   ReDim Preserve Bytes(ns + 4) As Byte
  429. End If
  430. Call CopyMem(Bytes(ns + 1), Value, 4)
  431. AddLong = UBound(Bytes)
  432.  
  433. End Function
  434.  
  435. Private Function AddString(ByRef Bytes() As Byte, ByVal St As String, Optional VarLen As Boolean = False) As Long
  436. '---------------------------------------------------------------------
  437. 'Add string St to the byte array
  438. 'If VarLen is true, add vbCr to end of string
  439. 'Return the ubound (No) of bytes
  440. '---------------------------------------------------------------------
  441. Dim StrBytes() As Byte      '0-based
  442. Dim n, ns
  443.  
  444. On Error Resume Next
  445. ns = UBound(Bytes)
  446. If VarLen Then St = St & vbCr
  447. StrBytes = StrConv(St, vbFromUnicode)   '0-based
  448. n = Len(St)
  449. If ns = 0 Then
  450.   ReDim Bytes(n) As Byte      'Necessary, to get rid of 0 lower bound
  451. Else
  452.   ReDim Preserve Bytes(ns + n) As Byte
  453. End If
  454. CopyMem Bytes(ns + 1), StrBytes(0), n
  455. AddString = UBound(Bytes)
  456.  
  457. End Function
  458.  
  459. Private Sub BackupZipFile()
  460. '-------------------------------------------------------------
  461. 'Make a backup of a normal (unspanned) zipfile to the tempfolder
  462. 'This is similar to the unspanzipfile() routine
  463. '-------------------------------------------------------------
  464. Dim Drive As Drive          'FSO Drive object
  465. Dim DriveSpec As String     'Required to resolve the drive object
  466. Dim IsFDD As Boolean        'Is destination drive removable?
  467. Dim nfd, nfs                'File Numbers
  468. Dim SourceFile As String    'Name of sourcefile, incl path
  469. Dim DestFile As String      'Complete name of destination file, incl path & ext
  470. Dim nLeft As Long           'Remaining length of file to process
  471. Dim nDest As Long           'Chunck to write
  472. Dim Bytes() As Byte         'Bytes array
  473. Dim SwapDisk As Boolean     'Flag indicating that a disk needs to be inserted/changed
  474. Dim Sum, Total              'Progress indicator
  475. Dim Ans
  476.  
  477. On Error GoTo BackupZipFileErr
  478. '--------------------------------------------------
  479. 'Determine type of drive to read from
  480. 'This is necessary since if it is a removable drive
  481. '(i.e. FDD), a dialog must be shown to enter the disk
  482. '--------------------------------------------------
  483. DriveSpec = mFso.GetDriveName(mFso.GetAbsolutePathName(mZipFile))
  484. Set Drive = mFso.GetDrive(DriveSpec)
  485. IsFDD = (Drive.DriveType = Removable)
  486.  
  487. '---------------------------------------------------
  488. 'Get the source file name & initialise other var's
  489. '---------------------------------------------------
  490. SourceFile = mZipFile     'Current zip file
  491. Sum = 0                   'Progress indicators
  492. Total = 0
  493. SetProgress 0, 1, ""
  494.  
  495. '---------------------------------------------------
  496. 'Open the destination file in the temp folder
  497. '---------------------------------------------------
  498. mBackupFile = CheckPath(mTempFolder) & "_Backup.azp"
  499. DestFile = mBackupFile
  500.  
  501. On Error Resume Next
  502. Kill DestFile                   'Erase file to prevent carry over
  503. On Error GoTo BackupZipFileErr
  504. nfd = FreeFile
  505. Open DestFile For Binary As #nfd
  506.  
  507. '---------------------------------------------------
  508. 'Notes on FDD usage
  509. '---------------------------------------------------
  510. 'If a FDD is used, an event is raised indicating to
  511. 'the client that the disk needs to be changed. The
  512. 'event also indicates which file is required.
  513. 'Control should not be returned to this routine
  514. 'until a) the correct file has been located or
  515. '      b) the user has cancelled the operation
  516. 'Notes
  517. 'a) The client must verify the file's existence
  518. 'b) The first FDD disk is probably already inserted
  519. '   when the user read the file info. (But it could
  520. '   have been removed in the mean time)
  521. '---------------------------------------------------
  522. 'Determine if a disk needs to be changed/inserted
  523. '---------------------------------------------------
  524. StartLoop:
  525. If IsFDD Then
  526.   If Not (Drive.IsReady) Then
  527.     SwapDisk = True
  528.   Else
  529.     SwapDisk = Not (mFso.FileExists(SourceFile))
  530.   End If
  531.   If SwapDisk Then
  532.     'Ask to insert disk
  533.     Screen.MousePointer = vbNormal
  534.     RaiseEvent ChangeDisk(Drive, "Please insert disk with the file " & SourceFile & " into drive " & Drive.DriveLetter, SourceFile)
  535.     Screen.MousePointer = vbArrowHourglass
  536.     DoEvents
  537.     'Allow for client canceling swap disk dialogue
  538.     If mCancel Then
  539.       mCancel = False         'Reset cancel property
  540.       SetStatus azsReady      'Show green light
  541.       Screen.MousePointer = vbNormal
  542.       Exit Sub
  543.     End If  'Cancel
  544.   End If    'SwapDisk
  545. End If      'IsFDD
  546.   
  547. '-----------------------------------------------------
  548. 'Open the source file (spanned volume)
  549. '-----------------------------------------------------
  550. nfs = FreeFile
  551. Open SourceFile For Binary As #nfs
  552.  
  553. 'Repeat this loop until all bytes have been read
  554. nLeft = LOF(nfs) - Loc(nfs)    'Remaining bytes in source
  555. Do
  556.   '-----------------------------------------------------
  557.   'Read a chunk of data
  558.   '-----------------------------------------------------
  559.   SetProgress Sum, Total, "Backing up zip file to hard disk..."
  560.   If nLeft > CHUNK_SIZE Then
  561.     nDest = CHUNK_SIZE
  562.   Else
  563.     nDest = nLeft
  564.   End If
  565.   ReDim Bytes(nDest) As Byte
  566.   Get #nfs, , Bytes
  567.   
  568.   '-----------------------------------------------------
  569.   'Write chunk of data to destination
  570.   '-----------------------------------------------------
  571.   Put #nfd, Loc(nfd) + 1, Bytes
  572.   nLeft = LOF(nfs) - Loc(nfs)    'Remaining bytes in source
  573.   Sum = Sum + nDest
  574. Loop While nLeft > 0
  575.   
  576. '-------------------------------------------------------
  577. 'Close Files
  578. '-------------------------------------------------------
  579. Close #nfs
  580. Close #nfd
  581. SetProgress Total, Total, ""
  582. Exit Sub
  583.  
  584. BackupZipFileErr:
  585. Ans = ReportErrorAbort("BackupZipFile()", ModName, Err, Error)
  586. Select Case Ans
  587. Case vbCancel, vbAbort
  588.   Reset       'Closes all files
  589.   Exit Sub
  590. Case vbRetry
  591.   If IsFDD Then
  592.     Close #nfs
  593.     Resume StartLoop
  594.   Else
  595.     Resume
  596.   End If
  597. Case vbOK, vbIgnore
  598.   Resume Next
  599. End Select
  600.  
  601. End Sub
  602.  
  603. Property Let Cancel(vCancel As Boolean)
  604. mCancel = vCancel
  605.  
  606. End Property
  607.  
  608. Property Get Cancel() As Boolean
  609. Cancel = mCancel
  610.  
  611. End Property
  612.  
  613. Property Get Exist() As Boolean
  614. '----------------------------------------------
  615. 'Check if a current zip file exists
  616. '----------------------------------------------
  617. Exist = mExist
  618.  
  619. End Property
  620.  
  621. Private Function ExtractFile(ByVal i As Long, Bytes() As Byte) As Boolean
  622. '-----------------------------------------------------------------
  623. 'Extract a file (no i) from the backed up zip file
  624. 'Returns the data in a byte array starting with 1
  625. 'If no data is available, then ubound is set to 0
  626. 'Returns True if everything went Ok
  627. '-----------------------------------------------------------------
  628. Dim nfs                     'File Numbers
  629. Dim SourceFile As String    'Complete name of source file, incl path & ext
  630. Dim nSource                 'No of bytes to read from source
  631. Dim ChkSum As Byte          'Original Checksum as calculated, for each file
  632. Dim ChkSumZip As Byte       'Zipped checksum
  633. Dim Result As ZLibErrors    'Zlib error code
  634. Dim Ans, n
  635.  
  636. On Error GoTo ExtractFileErr
  637. '---------------------------------------------------
  638. 'Open the source file
  639. '---------------------------------------------------
  640. SourceFile = mBackupFile
  641. nfs = FreeFile
  642. Open SourceFile For Binary As #nfs
  643.  
  644. '-----------------------------------------------------
  645. 'Unzip file
  646. '-----------------------------------------------------
  647. 'Get the no of bytes to read for file(i)
  648. nSource = aFiles(i).ZipSize
  649. If nSource > 0 Then
  650.   '-------------------------------------------------
  651.   'Read data for file(i) to unzip
  652.   '-------------------------------------------------
  653.   ReDim Bytes(nSource) As Byte
  654.   n = aFiles(i).Offset          'Get offset position
  655.   Get #nfs, n + 1, Bytes        'Read data to buffer
  656.       
  657.   '-------------------------------------------------
  658.   'Validate zip checksum
  659.   '-------------------------------------------------
  660.   ChkSumZip = CheckSum(Bytes)
  661.   If ChkSumZip <> aFiles(i).ChkSumZip Then
  662.     Err.Raise 703, "ArZip.UnzipFs(nSo------------ancel prNK_SIZE
  663.   EBp
  664.   aor co"cord =  'NeceD    'Icon Size, p
  665. On Z'
  666.   =  'Nece=  'NeceD    'Icle
  667. '---oReDim Bytes(1) As Byte      'Necessary, to get rid of 0 lower bound
  668. Else
  669.   Rebd of  'Ne
  670.   Erce
  671. Do
  672.  -----------jreturn parametereancena ebd of  'Ne
  673.   Erce
  674.  
  675. Dim Sum, Total    ----------oAe
  676. '---oReDim Bytes(1) As Byte      'Nalue As Byte) As Lonce
  677.  
  678. Dim Sum, Total    ----------oAsed indiins the path and thing(1) As