|
|
#include-once
#Tidy_Parameters=/sort_funcs /reel
; #AutoIt3Wrapper_Run_Debug_Mode=Y
OnAutoItExitRegister("_XZIP_Shutdown") ; in case the script exit without calling _XZIP_Shutdown()
#Region XZIP Include
#include-once
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <String.au3>
#include <WinAPIFiles.au3>
#EndRegion XZIP Include
#Region XZIP Header
; #INDEX# =======================================================================================================================
; Title .........: UDF for "XStandard XZIP Component"
; AutoIt Version : 3.3.10.2++
; Language ......: English
; Description ...: A collection of functions for "XStandard XZIP Component"
; Author(s) .....: mLipok
; Modified ......:
; ===============================================================================================================================
#cs
Title: UDF for "XStandard XZIP Component"
Filename: XZip.au3
Description: A collection of functions for "XStandard XZIP Component"
Author: mLipok
Modified:
Last Update: 2014/06/04
Requirements:
AutoIt 3.3.10.2 or higher
XStandard XZIP Component
Update History:
===================================================
2014/06/04
v0.1 First official version
#CE
#EndRegion XZIP Header
#Region #XZIP Constants#
; #CONSTANTS# ===================================================================================================================
; $__<UDF>_CONSTANT_<NAME>
Global Const $__sXZIP_ClassName = "XStandard.Zip.1"
Global Const $__sXZIP_CLSID = '{13D6BDE3-46AA-4FF2-A622-EBC43110D95C}'
Global Const $__sXZIP_IID = '{0B2D411B-7A91-483A-95C4-53DDC6B17895}'
Global Enum _
$tFolder = 1, _
$tFile
#EndRegion #XZIP Constants#
#Region XZIP Global Variables
; #VARIABLES# ===================================================================================================================
; $__g<VARNAME>_<UDF>
Global $__hDll_XZIP = 0
Global $__oXZIP_ErrorHandler = ''
Global $__fXPDF_Notification = True
Global $__sXZIP_DllFileFullPath = @ScriptDir & '\XZIP.dll'
#EndRegion XZIP Global Variables
#Region EXAMPLES
;~ _XZIP_UseErrorHandler()
;~ _TEST()
;~ _Examples()
Func _Examples()
Local $oXZIP
$sFilePath = @ScriptFullPath
$sArchive = @ScriptFullPath & '.zip'
$fStorePath = 0
$sNewPath = ""
;~ Sleep(1000)
_XZIP_Pack($oXZIP, $sFilePath, $sArchive, $fStorePath, $sNewPath)
;~ _XZIP_ErrorCode($oXZIP)
$output = _XZIP_Contents($oXZIP, $sArchive)
;~ MsgBox(1, 'VarGetType', VarGetType($output))
For $out In $output
ConsoleWrite($out.Path & $out.Name & @CRLF)
Next
_XZIP_UnPack($oXZIP, @ScriptDir & '\xZIP.zip', @ScriptDir & '\TESTING')
$oXZIP = '' ; CleanUp
EndFunc ;==>_Examples
#EndRegion EXAMPLES
#Region #XZIP INTERNAL#
; ===============================================================================================================================
; #INTERNAL# ====================================================================================================================
#EndRegion #XZIP INTERNAL#
#Region #XZIP CURRENT#
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_Contents
; Description ...: Get a list of files and folder in the archive
; Syntax ........: _XZIP_Contents(ByRef $oXZIP, $sArchive)
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; $sArchive - A string value.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_Contents(ByRef $oXZIP, $sArchive)
_XZIP_CreateObject($oXZIP)
If @error Then
Return SetError(1, '', '')
Else
Return $oXZIP.Contents($sArchive)
EndIf
EndFunc ;==>_XZIP_Contents
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_CreateObject
; Description ...: Create Object for XZIP
; Syntax ........: _XZIP_CreateObject(Byref $oXZIP)
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; Return values .: Success: $oXZIP object
; Failure: 0 and set @error to non zero
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_CreateObject(ByRef $oXZIP)
;~ $oXZIP = ObjCreate($__sXZIP_ClassName)
;~ Return
If _XZIP_StartUp() Then
If Not IsObj($oXZIP) Then
$oXZIP = ObjCreate($__sXZIP_CLSID, $__sXZIP_IID, $__hDll_XZIP) ; $__sClassName_XZIP_Commercial
;~ _XZIP_ErrorCode($oXZIP)
Return SetError(@error, 0, $oXZIP)
EndIf
EndIf
EndFunc ;==>_XZIP_CreateObject
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_Delete
; Description ...: Remove a file from an archive.
; Syntax ........: _XZIP_Delete(ByRef $oXZIP, $sFile, $sArchive)
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; $sFile - A string value.
; $sArchive - A string value.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_Delete(ByRef $oXZIP, $sFile, $sArchive)
EndFunc ;==>_XZIP_Delete
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_ErrFunc
; Description ...: AutoIt COM Error Handling Functionality
; Syntax ........: _XZIP_ErrFunc($oError)
; Parameters ....: $oError - An unknown value.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_ErrFunc($oError)
ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
@TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
@TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
@TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
@TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
@TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
@TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
@TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc ;==>_XZIP_ErrFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_ErrorCode
; Description ...: Return the code of last operation.
; Syntax ........: _XZIP_ErrorCode(Byref $oXZIP)
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; Return values .: ErrorCode of last operation.
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: http://www.xstandard.com/en/documentation/XZIP/
; Example .......: No
; ===============================================================================================================================
Func _XZIP_ErrorCode(ByRef $oXZIP)
If IsObj($oXZIP) Then
Local $oXZIP_ErrorCode = $oXZIP.ErrorCode($oXZIP)
Local $oXZIP_ErrorDescription = $oXZIP.ErrorDescription($oXZIP)
ConsoleWrite('! _XZIP_ErrorCode:' & @CRLF)
ConsoleWrite('> $oXZIP_ErrorCode = ' & $oXZIP_ErrorCode & @CRLF)
ConsoleWrite('> $oXZIP_ErrorDescription = ' & $oXZIP_ErrorDescription & @CRLF)
Return SetError(0, $oXZIP_ErrorDescription, $oXZIP_ErrorCode)
Else
ConsoleWrite('! _XZIP_ErrorCode:' & @CRLF)
ConsoleWrite('> $oXZIP is not an object.' & @CRLF)
Return SetError(1, '', 0)
EndIf
EndFunc ;==>_XZIP_ErrorCode
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_ErrorDescription
; Description ...: Return the error code description of last operation.
; Syntax ........: _XZIP_ErrorDescription(Byref $oXZIP)
; Parameters ....: $oXZIP - [in/out] An unknown value.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_ErrorDescription(ByRef $oXZIP)
Return $oXZIP.ErrorDescription()
EndFunc ;==>_XZIP_ErrorDescription
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_Move
; Description ...: Move or rename a file in the archive.
; Syntax ........: _XZIP_Move(ByRef $oXZIP, $sFrom, $sTo, $sArchive)
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; $sFrom - A string value.
; $sTo - A string value.
; $sArchive - A string value.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: http://www.xstandard.com/en/documentation/XZIP/
; Example .......: No
; ===============================================================================================================================
Func _XZIP_Move(ByRef $oXZIP, $sFrom, $sTo, $sArchive)
EndFunc ;==>_XZIP_Move
; #CURRENT# =====================================================================================================================
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_Pack
; Description ...: Add file or folder to an archive.
; Syntax ........: _XZIP_Pack(ByRef $oXZIP, $sFilePath, $sArchive[, $fStorePath = False[, $sNewPath = Default[, $iCompressionLevel = -1]]])
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; $sFilePath - A string value.
; $sArchive - A string value.
; $fStorePath - [optional] A boolean value. Default is False.
; $sNewPath - [optional] A string value. Default is "".
; $iCompressionLevel - [optional] An integer value. Default is -1. Compression level 1 is minimum, level 9 is maximum, all other values default to level 6.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: http://www.xstandard.com/en/documentation/XZIP/
; Example .......: No
; ===============================================================================================================================
Func _XZIP_Pack(ByRef $oXZIP, $sFilePath, $sArchive, $fStorePath = False, $sNewPath = "", $iCompressionLevel = -1)
_XZIP_CreateObject($oXZIP)
If @error Then
Return -1
Else
$oXZIP.Pack($sFilePath, $sArchive, $fStorePath, $sNewPath, $iCompressionLevel)
ConsoleWrite('> $oXZIP.ErrorCode = ' & $oXZIP.ErrorCode() & @CRLF)
ConsoleWrite('> $oXZIP.ErrorDescription = ' & $oXZIP.ErrorDescription() & @CRLF)
ConsoleWrite('! $oXZIP.Version = ' & $oXZIP.Version() & @CRLF)
EndIf
EndFunc ;==>_XZIP_Pack
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_Shutdown
; Description ...: Close the XZip.dll library
; Syntax ........: _XZIP_Shutdown()
; Parameters ....: None
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_Shutdown()
$oXZIP = ''
If $__hDll_XZIP > 0 Then DllClose($__hDll_XZIP)
$__hDll_XZIP = 0
OnAutoItExitUnRegister("_XZIP_Shutdown")
EndFunc ;==>_XZIP_Shutdown
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_StartUp
; Description ...: Open the XZip.dll library
; Syntax ........: _XZIP_StartUp()
; Parameters ....: None
; Return values .: TODO
; Author ........: mLipok
; Modified ......:
; Remarks .......: If you not set $__sLicenseKey_XZIP then DebenuPDFLibraryLite1012.dll will be used (Lite version). SET YOUR LICENSE KEY in your main script using _XZIP_SetLicenseKey()
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_StartUp()
If $__hDll_XZIP = 0 Then
If FileExists($__sXZIP_DllFileFullPath) Then
$__hDll_XZIP = DllOpen($__sXZIP_DllFileFullPath)
If @error = -1 Then
MsgBox($MB_SYSTEMMODAL + $MB_OK, "DllOpen Error", "Can not open: " & @CRLF & $__sXZIP_DllFileFullPath)
Return SetError(2, '', 0)
EndIf
Return 1
Else
MsgBox($MB_SYSTEMMODAL + $MB_OK, "DllOpen Error", "Dll File not exist: " & @CRLF & $__sXZIP_DllFileFullPath)
Return SetError(1, '', 0)
EndIf
Else
EndIf
EndFunc ;==>_XZIP_StartUp
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_UnPack
; Description ...: Extract contents of an archive to a folder.
; Syntax ........: _XZIP_UnPack(ByRef $oXZIP, $sArchive, $sFolderPath[, $sPattern = ""])
; Parameters ....: $oXZIP - [in/out] Reference to xZIP object.
; $sArchive - A string value.
; $sFolderPath - A string value.
; $sPattern - [optional] A string value. Default is "".
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: http://www.wanheta.com/en/documentation/XZIP/
; Example .......: No
; ===============================================================================================================================
Func _XZIP_UnPack(ByRef $oXZIP, $sArchive, $sFolderPath, $sPattern = "")
Return $oXZIP.UnPack($sArchive, $sFolderPath, $sPattern)
EndFunc ;==>_XZIP_UnPack
; #FUNCTION# ====================================================================================================================
; Name ..........: _XZIP_UseErrorHandler
; Description ...: Handles incoming events from the given Object.
; Syntax ........: _XZIP_UseErrorHandler()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......: Use it only if you do not use your own COM Error Handling.
; Related .......: _XZIP_ErrFunc
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _XZIP_UseErrorHandler()
$__oXZIP_ErrorHandler = ObjEvent("AutoIt.Error", "_XZIP_ErrFunc")
EndFunc ;==>_XZIP_UseErrorHandler
#EndRegion #XZIP CURRENT#
#Region TODO
Func _TEST()
$oXZIP = ''
_XZIP_CreateObject($oXZIP)
If Not IsObj($oXZIP) Then
MsgBox(1, 'IsObj ERROR', '')
Else
$sFilePath = @ScriptFullPath
$sArchive = @ScriptFullPath & '.zip'
ConsoleWrite('> $oXZIP.ErrorCode = ' & $oXZIP.ErrorCode() & @CRLF)
ConsoleWrite('> $oXZIP.ErrorDescription = ' & $oXZIP.ErrorDescription() & @CRLF)
ConsoleWrite('! $oXZIP.Version = ' & $oXZIP.Version() & @CRLF)
EndIf
$oXZIP = ''
EndFunc ;==>_TEST
#EndRegion TODO |
|