NORIO
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Код: ; ====================================================================================== ; 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: ; http://xstandard.com/printer-friendly.asp?id=C9891D8A-5390-44ED-BC60-2267ED6763A7 ; ====================================================================================== #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) WHILE 1 IF RegRead ( 'HKEY_CLASSES_ROOT\CLSID\{13D6BDE3-46AA-4FF2-A622-EBC43110D95C}', "" ) <> "" THEN ExitLoop Sleep(10) WEnd 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 |
| Всего записей: 875 | Зарегистр. 18-12-2004 | Отправлено: 19:32 18-12-2008 | Исправлено: NORIO, 20:12 18-12-2008 |
|