corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
global $handle, $zip_loaded, $zipper
func MakeZip($source, $target, $pass="", $raw=0)
local $result, $ret[2]
if not $zip_loaded then $zip_loaded = RegisterZipDLL($zipper, $zip_loaded)
if $zip_loaded < 1 then
$ret[1] = -2
return false
endif
if $pass then
$new_zip = ZipCreate($target, $pass)
else
$new_zip = ZipCreate($target)
endif
if Number($new_zip) == 0 then
$result = -8
SetError(-8)
else
if IsDir($source) then
if StringRight($source, 1) = "\" then $source = StringTrimRight($source, 1)
$result = ZipAddDir($new_zip, $source, 1)
else
$inner = BaseName($source)
$result = ZipAdd($new_zip, $source, $inner)
endif
switch Number($result)
case 512
$result = -6
case 0
$result = 1
endswitch
ZipClose($new_zip)
endif
$ret[0] = $result
$ret[1] = @error
if $raw then return $ret
return ProcessZipCodes($ret)
endfunc
func UnZip($archive, $destination="", $pass="", $raw=0)
local $result, $ret[2]
if not $zip_loaded then $zip_loaded = RegisterZipDLL($zipper, $zip_loaded)
if $zip_loaded < 1 then return false
if not $destination then $destination = GetParent($archive)
$result = ZipUnZip($archive, $destination, $pass)
$ret[0] = $result
$ret[1] = @error
if $raw then return $ret
return ProcessZipCodes($ret)
endfunc
func RegisterZipDLL($zipper, $loaded=0)
if $loaded then return $loaded
if not FileExists($zipper) then return 0
$handle = PluginOpen($zipper)
Sleep(200)
if PluginClose($handle) then
$handle = PluginOpen($zipper)
return 1
endif
return -1
endfunc
func ProcessZipCodes($val_arr, $unz=false)
if not IsArray($val_arr) then return "Not a valid ZipCodes array"
local $code = $val_arr[0]
local $err = $val_arr[1]
local $msg
if not $zip_loaded then
$msg = "there was a problem loading the zipper"
else
switch $code
case 0
if $unz then
$msg = "ok"
else
$msg = "some error"
endif
case -6
$msg = "couldn't add a file to the zip"
case -8
$msg = "couldn't create the zip file"
case else
$msg = "ok"
endswitch
endif
return $msg
endfunc
Func _ZipList2Array($szZipFile)
Local $zCount, $zipItems[1][8]
If FileExists($szZipFile) Then
$zCount = ZipGetCount($szZipFile)
If $zCount Then
ReDim $zipItems[$zCount][8]
For $z_x = 0 To $zCount - 1
Local $zipTemp = _ZipItemInfo2Array($szZipFile, $z_x)
If Not (@error) Then
For $z = 0 To 7
$zipItems[$z_x][$z] = $zipTemp[$z]
Next
EndIf
Next
EndIf
Return $zipItems
EndIf
Return SetError(1, 0, "")
EndFunc
Func _ZipItemInfo2Array($szZipFile, $index)
Local $z_v_ret, $strList, $zipTemp, $zipItems[8]
If FileExists($szZipFile) Then
If $index >= 0 Then
If $index <= ZipGetCount ($szZipFile) Then
$z_v_ret = ZipGetItemInfo ($szZipFile, $index)
If $z_v_ret <> 0 Then
Return _ZipGetInfoFromPtr($z_v_ret)
EndIf
EndIf
EndIf
EndIf
Return SetError(1, 0, 0)
EndFunc
Func _ZipGetInfoFromPtr($zPtr)
;~ { int index;
;~ TCHAR name[MAX_PATH];
;~ DWORD attr;
;~ FILETIME atime,ctime,mtime;
;~ long comp_size;
;~ long unc_size;
If $zPtr <> 0 Then
Local $zipItems[8]
$strList = DllStructCreate("int, $zPtr)
For $z = 1 To 8
Local $zipTemp = DllStructGetData($strList, $z)
If $z > 3 And $z < 7 Then
$zipItems[$z - 1] = _FileTime2SystemTimeZ($zipTemp)
Else
$zipItems[$z - 1] = $zipTemp
EndIf
Next
$strList = 0
Return $zipItems
EndIf
EndFunc
Func _FileTime2SystemTimeZ($file_t)
Local $td, $st, $ft, $vret, $syst, $zone, $hr
$td = "%s/%s/%s %s:%s:%s%s"
If $file_t = "" Then Return
$st = DllStructCreate("short)
$ft = DllStructCreate("dword)
DllStructSetData($ft, 1, _Lo_dWordZ($file_t))
DllStructSetData($ft, 2, _Hi_dWordZ($file_t))
$vret = DllCall("kernel32.dll", "int", "FileTimeToSystemTime", "ptr", DllStructGetPtr($ft), "ptr", DllStructGetPtr($st))
If IsArray($vret) Then
$zone = "AM"
$hr = DllStructGetData($st, 5)
If $hr > 11 Then $zone = "PM"
If $hr > 12 Then $hr -= 12
$syst = StringFormat($td, _ZipPZ(DllStructGetData($st, 2)), _
_ZipPZ(DllStructGetData($st, 4)), _
DllStructGetData($st, 1), _
_ZipPZ($hr), _
_ZipPZ(DllStructGetData($st, 6)), _
_ZipPZ(DllStructGetData($st, 7)), _
$zone)
EndIf
$st = 0
$ft = 0
Return $syst
EndFunc
Func _Hi_dWordZ($file_t)
Return $file_t/ (2 ^ 32)
EndFunc
Func _Lo_dWordZ($file_t)
Return Abs($file_t - ((2 ^ 32) * ($file_t/ (2 ^ 32))))
EndFunc
Func _ZipPZ($Value)
Select
Case $Value < 0
Return "00"
Case $Value < 10
Return "0" & $Value
EndSelect
Return $Value
EndFunc