Code : Tout sélectionner
; #FUNCTION# ====================================================================================================================
; Name...........: _7ZipGetFilesList
; Description ...: Returns an array of files and dir in an archive
; Syntax.........: _7ZipGetFilesList($hWnd, $sArcName)
; Parameters ....: $hWnd - Handle to parent or owner window
; $sArcName - Archive file name
; Return values .: Success - Returns an array of files and dir in an archive
; Failure - Returns 0 and set error
; Related .......: _7ZipOpenArchive, _7ZipCloseArchive, _7ZipGetFileCount, _7ZipFindFirst, _7ZipFindNext,
; _7ZipGetArcOriginalSize, _7ZipGetDate, _7ZipGetTime,
; _Get7zipStringAttribute, _OEMToAnsi, _7ZipDateTimeToStr
; Author ........: Tlem
; ===============================================================================================================================
Func _7ZipGetFilesList($hWnd, $sArcName)
Local $hArc = _7ZipOpenArchive($hWnd, $sArcName)
If $hArc = 0 Then Return SetError(1, 0, 0)
Local $szFileCount = _7ZipGetFileCount($sArcName)
Local $aArcFilesList[$szFileCount + 1][4]
Local $iDosDate, $iDosTime, $iCount = 1
$aArcFilesList[0][0] = $szFileCount
$aArcFilesList[0][1] = "Size"
$aArcFilesList[0][2] = "Attribute"
$aArcFilesList[0][3] = "Date and Time"
Local $tINDIVIDUALINFO = _7ZipFindFirst($hArc, "*")
If $tINDIVIDUALINFO = -1 Then Return SetError(1, 0, 0)
$aArcFilesList[1][0] = _OEMToAnsi(DllStructGetData($tINDIVIDUALINFO, "szFileName"))
$aArcFilesList[1][2] = _Get7zipStringAttribute($hArc)
If Not StringInStr($aArcFilesList[1][2], "D") Then
$aArcFilesList[1][1] = DllStructGetData($tINDIVIDUALINFO, "dwOriginalSize")
EndIf
$iDosDate = _7ZipGetDate($hArc)
$iDosTime = _7ZipGetTime($hArc)
$aArcFilesList[1][3] = _7ZipDateTimeToStr($iDosDate, $iDosTime)
While 1
$iCount += 1
$tINDIVIDUALINFO = _7ZipFindNext($hArc, $tINDIVIDUALINFO)
If $tINDIVIDUALINFO = 0 Then ExitLoop
$aArcFilesList[$iCount][0] = _OEMToAnsi(DllStructGetData($tINDIVIDUALINFO, "szFileName"))
$aArcFilesList[$iCount][2] = _Get7zipStringAttribute($hArc)
If Not StringInStr($aArcFilesList[$iCount][2], "D") Then
$aArcFilesList[$iCount][1] = DllStructGetData($tINDIVIDUALINFO, "dwOriginalSize")
EndIf
$iDosDate = _7ZipGetDate($hArc)
$iDosTime = _7ZipGetTime($hArc)
$aArcFilesList[$iCount][3] = _7ZipDateTimeToStr($iDosDate, $iDosTime)
WEnd
_7ZipCloseArchive($hArc)
Return $aArcFilesList
EndFunc ;==>_7ZipGetFilesList
; #FUNCTIONS FOR INTERNAL USE# ==================================================================================================
Func _OEMToAnsi($sOEM)
Local $a_AnsiFName = DllCall('user32.dll', 'Int', 'OemToChar', 'str', $sOEM, 'str', '')
If @error = 0 Then $sAnsi = $a_AnsiFName[2]
Return $sAnsi
EndFunc ;==>_OEMToAnsi
Func _Get7zipStringAttribute($ArcHandle)
Local $sAttrib
Local $iAttrib = _7ZipGetAttribute($ArcHandle)
If BitAND($iAttrib, 0X01) Then $sAttrib &= 'R'
If BitAND($iAttrib, 0X02) Then $sAttrib &= 'H'
If BitAND($iAttrib, 0X04) Then $sAttrib &= 'S'
If BitAND($iAttrib, 0X08) Then $sAttrib &= 'L'
If BitAND($iAttrib, 0X10) Then $sAttrib &= 'D'
If BitAND($iAttrib, 0X20) Then $sAttrib &= 'A'
If BitAND($iAttrib, 0X40) Then $sAttrib &= 'E'
Return $sAttrib
EndFunc ;==>_Get7zipStringAttribute
; This function is identical from _Date_Time_DOSDateTimeToStr function.
Func _7ZipDateTimeToStr($iDosDate, $iDosTime)
Local $aDate[6]
$aDate[0] = BitAND($iDosDate, 0x1F)
$aDate[1] = BitAND(BitShift($iDosDate, 5), 0x0F)
$aDate[2] = BitAND(BitShift($iDosDate, 9), 0x3F) + 1980
$aDate[5] = BitAND($iDosTime, 0x1F) * 2
$aDate[4] = BitAND(BitShift($iDosTime, 5), 0x3F)
$aDate[3] = BitAND(BitShift($iDosTime, 11), 0x1F)
Return StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aDate[0], $aDate[1], $aDate[2], $aDate[3], $aDate[4], $aDate[5])
EndFunc