Here are some UDFs I wrote based on what I saw here.
; ======================================================================================
; Zip UDFs based on standared fileOpen()/fileClose() system
; Based on other people's work.
;
; Only the more basic function of XZip are represnted (poorly)
;
; Requires: XZip.dll:
; <a href='http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7' class='bbc_url' title='External link' rel='nofollow external'>http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7</a>
; ======================================================================================
#include-once
#include <array.au3>
#include <file.au3>
Global $oXZip_UDFGlobal, $sZipPath_UDFGlobal, $oComError_UDFGlobal, $sDllLoc_UDFGlobal, $iRegDelay_UDFGlobal
; ============================================================================
; Turned off COM erroring
; I don't think it's needed if the scripter is not directly interacting with
; the object, plus it causes an error with my choosen exit(_ZipClose) method
; ============================================================================
;$oComError_UDFGlobal = ObjEvent("AutoIt.Error", "__XZip_COM_Error")
;===============================================================================
;
; Description: :Open ZIP file, and load XZip.dll as a service
; Parameter(s): :Archive path, (Opt)XZip.dll path (default to @ScriptDir),
; (opt)Delay between regsrv, and objcreate (default 150 ms)
; Requirement: :XZip.dll, XZip.au3
; Return Value(s): :True/False (error #)
; User CallTip: :_ZipOpen(ArchivePath, XZipDllPath, Delay in MS)
;
;===============================================================================
;
Func _ZipOpen($sNewArchivePath, $sDllPath = '', $iDelay = 200)
If $sDllPath = '' Then $sDllPath = @ScriptDir & '\XZip.dll'
;some error checking
If Not FileExists($sDllPath) Then
SetError(1)
Return False
ElseIf Not IsInt($iDelay) Then
SetError(2)
Return False
EndIf
;set the globals
$sZipPath_UDFGlobal = $sNewArchivePath
$sDllLoc_UDFGlobal = $sDllPath
$iRegDelay_UDFGlobal = $iDelay
__DOSStart('regsvr32 /s "' & $sDllLoc_UDFGlobal & '"')
Sleep($iRegDelay_UDFGlobal);needs a sec when loaded silent.
$oXZip_UDFGlobal = ObjCreate('XStandard.Zip')
If IsObj($oXZip_UDFGlobal) Then;make sure it's opened
Return True
Else
SetError(3)
Return False
EndIf
EndFunc ;==>_ZipOpen
;===============================================================================
;
; Description: :List items in given Zip file
; Parameter(s): :None (see _ZipOpen)
; Requirement: :XZip.dll, XZip.au3
; Return Value(s): :Array contaning archive contents
; User CallTip: :_ZipContents()
;
;===============================================================================
;
Func _ZipContents();this func needs some more work
Local $oItem
Local $aRet[1]
If Not IsObj($oXZip_UDFGlobal) Then
SetError(1)
Return False
EndIf
For $oItem In $oXZip_UDFGlobal.Contents ($sZipPath_UDFGlobal)
_ArrayAdd($aRet, $oItem.Path & $oItem.Name)
Next
$aRet[0] = UBound($aRet)
Return $aRet
EndFunc ;==>_ZipContents
;===============================================================================
;
; Description: :Add items to opened Zip file
; Parameter(s): :Array contaning item paths, (opt)Retain dir structure
; Requirement: :XZip.dll, XZip.au3
; Return Value(s): :True/False (error #)
; User CallTip: :_ZipPack(array of item paths, Bool)
;
;===============================================================================
;
Func _ZipPackGroup(ByRef $aItems, $bKeepPath = True);this func needs some more work
If Not IsObj($oXZip_UDFGlobal) Then
SetError(1)
Return False
EndIf
Local $x
For $x = 0 To UBound($aItems) - 1
If Not FileExists($aItems[$x]) Then
SetError(2)
SetExtended($aItems[$x])
Return False
EndIf
$oXZip_UDFGlobal.Pack ($aItems[$x], $sZipPath_UDFGlobal, $bKeepPath)
Next
Return True
EndFunc ;==>_ZipPackGroup
;===============================================================================
;
; Description: :Add all items in a dir to opened Zip file
; Parameter(s): :String dir path
; Requirement: :XZip.dll, XZip.au3
; Return Value(s): :True/False (error #)
; User CallTip: :_ZipPackDir(DirPath)
;
;===============================================================================
;
Func _ZipPackDir($sDirPath);this is the one that I needed, so it works well
Local $aFiles, $x, $i, $aDirs[1], $sStartDir, $sWorkingDir, $sNewDirPath, $iInsert, $sDirInZip
If Not IsObj($oXZip_UDFGlobal) Then
SetError(1)
Return False
ElseIf Not StringInStr(FileGetAttrib($sDirPath), 'D') Then
SetError(2)
Return False
EndIf
$sStartDir = $sDirPath
$aDirs[0] = $sDirPath
$i = 0
; ===========================================================
; This loop might have some unneeded code, because it took a
; lot of trys to get it right. Also some error more checking,
; optimization and clean couldn't hurt. But it works!;)
; ===========================================================
Do
$sWorkingDir = $aDirs[$i] & '\'
$aFiles = _FileListToArray ($aDirs[$i])
For $x = 1 To UBound($aFiles) - 1
If StringInStr(FileGetAttrib($aFiles[$x]), 'D') Then
$sNewDirPath = $sDirPath & '\' & $aFiles[$x]
$iInsert = $i + 1
_ArrayInsert($aDirs, $iInsert, $sNewDirPath)
Else
$sDirInZip = StringReplace($sWorkingDir, $sDirPath, '')
$oXZip_UDFGlobal.Pack ($sWorkingDir & $aFiles[$x], $sZipPath_UDFGlobal, 1, $sDirInZip)
EndIf
Next
$i = $i + 1
$aFiles = ''
Until UBound($aDirs) = $i
Return True
EndFunc ;==>_ZipPackDir
;===============================================================================
;
; Description: :Unpack a zip file
; Parameter(s): :String: Path to extract Zip file to
; Requirement: :XZip.dll, XZip.au3
; Return Value(s): :True/False (error #)
; User CallTip: :_ZipUnpack(ExtractPath)
;
;===============================================================================
;
Func _ZipUnpack($sDestPath)
If Not IsObj($oXZip_UDFGlobal) Then
SetError(1)
Return False
EndIf
If Not FileExists($sDestPath) Then DirCreate($sDestPath)
$oXZip_UDFGlobal.UnPack ($sZipPath_UDFGlobal, $sDestPath)
Return True
EndFunc ;==>_ZipUnpack
;===============================================================================
;
; Description: :Close ZIP file, and unload XZip.dll as a service
; Parameter(s): :None, based on _ZipOpen globals
; Requirement: :XZip.dll, XZip.au3
; Return Value(s): :True/False (error #)
; User CallTip: :_ZipClose(XZipDllPath, Delay in MS)
;
;===============================================================================
;
Func _ZipClose()
;some error checking
If Not FileExists($sDllLoc_UDFGlobal) Then
SetError(1)
Return False
EndIf
__DOSStart('regsvr32 /s /u "' & $sDllLoc_UDFGlobal & '"')
Sleep($iRegDelay_UDFGlobal);needs a sec when unloaded silently.
; =====================================================
; This way of checking will cause a COM error
; but I like to confirm that the object's been closed
; =====================================================
$oXZip_UDFGlobal = ObjCreate('XStandard.Zip')
If Not IsObj($oXZip_UDFGlobal) Then;make sure it's closed
;reset globals, for next call
$sZipPath_UDFGlobal = ''
$sDllLoc_UDFGlobal = ''
$iRegDelay_UDFGlobal = 0
$oXZip_UDFGlobal = ''
Return True
Else
SetError(2)
Return False
EndIf
EndFunc ;==>_ZipClose
;helper functions
Func __XZip_COM_Error()
Local $hNumber = Hex($oComError_UDFGlobal.number, 8)
;blantly stolen from SvenP (We'll call it a 'port')
MsgBox(0, 'XZip Com Error', 'There was COM Error!' & @CRLF & @CRLF & _
'description is: ' & @TAB & $oComError_UDFGlobal.description & @CRLF & _
'windescription:' & @TAB & $oComError_UDFGlobal.windescription & @CRLF & _
'number is: ' & @TAB & $hNumber & @CRLF & _
'lastdllerror is: ' & @TAB & $oComError_UDFGlobal.lastdllerror & @CRLF & _
'scriptline is: ' & @TAB & $oComError_UDFGlobal.scriptline & @CRLF & _
'source is: ' & @TAB & $oComError_UDFGlobal.source & @CRLF & _
'helpfile is: ' & @TAB & $oComError_UDFGlobal.helpfile & @CRLF & _
'helpcontext is: ' & @TAB & $oComError_UDFGlobal.helpcontext _
)
SetError(1)
EndFunc ;==>__XZip_COM_Error
Func __DOSStart($sStart)
Run(@ComSpec & ' /c start ' & $sStart, '', @SW_HIDE)
EndFunc ;==>__DOSStart
#cs UserCalltips
_ZipOpen($sNewArchivePath, $sDllPath = '', $iDelay = 150)
_ZipContents()
_ZipPackGroup(ByRef $aItems, $bKeepPath = True);this func needs some more work
_ZipPackDir(DirPath)
_ZipUnpack($sDestPath)
_ZipClose($sDllPath = '', $iDelay = 150)
#ce