Jump to content

pZip UDF


asdf8
 Share

Recommended Posts

UDF is made on base of the library zLib. The original library zLib does not support removing the files from archive and, accordingly, does not support overwriting the files in archive, at coincidence of the names. In given library is implemented to overwrite files in the archive with the same name by method repacking of the archive, similarly that, as this does, for instance WinRar.

UDF:

Global Const $pZip_dll = @ScriptDir & '\pZip.dll'


; #FUNCTION# =====================================================================
; Name...........: _zip_FileInfo
; Description....: Get file information from all files in current archive.
; Syntax.........: _zip_FileInfo($sFile)
; Parameters.....: $sFile - The path of the archive.
; Return values..: The array that contains the following information.
;
;                      [0][0] = Number of entries
;                      [n][0] - nth Filename.
;                      [n][1] - nth Compressed Size
;                      [n][2] - nth Uncompressed Size
;                      [n][3] - nth Last Modification Date
;                      [n][4] - nth Crc32
;                      [n][5] - nth Compression Method
;
; Author.........: asdf8
; ================================================================================
Func _zip_FileInfo($sFile)
    Local $ret[1][6], $res, $tmp, $i, $j
    If Not $sFile Or Not FileExists($sFile) Then Return SetError(1, 0, $ret)
    $res = DllCall($pZip_dll, 'str', 'pZIP_FileInfo', 'str', $sFile)
    If Not IsArray($res) Then Return SetError(2, 0, $ret)
    If $res[0] Then
        $res = StringRegExp($res[0], '([^|]+)', 3)
        ReDim $ret[UBound($res) + 1][6]
        $ret[0][0] = UBound($res)
        $ret[0][1] = 'Compressed Size'
        $ret[0][2] = 'Uncompressed Size'
        $ret[0][3] = 'Date'
        $ret[0][4] = 'Crc32'
        $ret[0][5] = 'Compression Method'
        For $i = 1 To $ret[0][0]
            $tmp = StringSplit($res[$i - 1], '*', 2)
            For $j = 0 To 5
                $ret[$i][$j] = $tmp[$j]
            Next
        Next
    EndIf
    Return SetError(0, 0, $ret)
EndFunc


; #FUNCTION# =====================================================================
; Name...........: _zip_FindFile
; Description....: Find file in archive.
; Syntax.........: _zip_FindFile($sFile, $FindName[, $IncludingPath = 1])
; Parameters.....: $sFile - The path of the archive.
;                  $FindName - The filename to find.
;                  $IncludingPath - 0  search only for filename.
;                                   1  (default), search for path + filename.
; Return values..: Success    - The array file info.
;
;                      [0] - nth Filename.
;                      [1] - nth Compressed Size
;                      [2] - nth Uncompressed Size
;                      [3] - nth Last Modification Date
;                      [4] - nth Crc32
;                      [5] - nth Compression Method
;
;                  Failure    - (-1) if not found.
; Author.........: asdf8
; ================================================================================
Func _zip_FindFile($sFile, $FindName, $IncludingPath = 1)
    If Not $sFile Or Not FileExists($sFile) Or Not  $FindName Then Return SetError(1, 0, -1)
    Local $res = DllCall($pZip_dll, 'str', 'pZIP_FindFile', 'str', $sFile, 'str', $FindName, 'int', $IncludingPath)
    If Not IsArray($res) Then Return SetError(2, 0, -1)
    If $res[0] Then
        $res = StringSplit($res[0], '*', 2)
        Return SetError(0, 0, $res)
    Else
        Return SetError(0, 0, -1)
    EndIf
EndFunc


; #FUNCTION# =====================================================================
; Name...........: _zip_AddFiles
; Description....: Add files to archive.
; Syntax.........: _zip_AddFiles($sFile, $FilePathMask, $StoreRelPath = 1, $Recursive = 1)
; Parameters.....: $sFile - The path of the archive.
;                  $FilePathMask - File mask supports wildcards.
;                  $StoreRelPath - 0  Store Only filename.
;                                  1  (default), store path relative basedir.
;                  $Recursive    - 0  no recursive search.
;                                  1  (default), recursive file search.
;                                  2  recursive file search and add empty directories (use only if necessary).
; Return values..: Number of added files.
; Author.........: asdf8
; ================================================================================
Func _zip_AddFiles($sFile, $FilePathMask, $StoreRelPath = 1, $Recursive = 1)
    If Not $sFile Or Not $FilePathMask Then Return SetError(1, 0, 0)
    Local $res = DllCall($pZip_dll, 'int', 'pZIP_AddFiles', 'str', $sFile, 'str', $FilePathMask, 'int', $StoreRelPath, 'int', $Recursive)
    If Not IsArray($res) Then Return SetError(2, 0, -1)
    Return SetError(0, 0, $res[0])
EndFunc


; #FUNCTION# =====================================================================
; Name...........: _zip_ExtractFiles
; Description....: Extract files from archive.
; Syntax.........: _zip_ExtractFiles($sFile, $OutputPath[, $FileMask = ""[, $IncludingPath = 1]])
; Parameters.....: $sFile - The path of the archive.
;                  $OutputPath - Output path.
;                  $FileMask - File mask supports wildcards.
;                  $IncludingPath - 0  only filename is extracted.
;                                   1  (default), the complete filename (including path) is extracted.
; Return values..: Number of extracted files.
; Author.........: asdf8
; ================================================================================
Func _zip_ExtractFiles($sFile, $OutputPath, $FileMask = "", $IncludingPath = 1)
    If Not $sFile Or Not FileExists($sFile) Or Not  $OutputPath Then Return SetError(1, 0, 0)
    Local $res = DllCall($pZip_dll, 'int', 'pZIP_ExtractFiles', 'str', $sFile, 'str', $OutputPath, 'str', $FileMask, 'int', $IncludingPath)
    If Not IsArray($res) Then Return SetError(2, 0, -1)
    Return SetError(0, 0, $res[0])
EndFunc

Example:

#Include <Array.au3>; need only for "_ArrayDisplay"

#Include <pZip.au3>

$inFile = @ScriptDir & '\Test.zip'
$OutPath = @DesktopDir & '\Test_zip\123'
$toZip = @ScriptDir

$ret = _zip_AddFiles($inFile, $toZip)

$ar = _zip_FileInfo($inFile)
_ArrayDisplay($ar, '-1-AddFiles->' & $ret & '--error>' & @error)

$ar = _zip_FindFile($inFile, @ScriptName, 1)
If IsArray($ar) Then
    _ArrayDisplay($ar, '-FindFile->' & @ScriptName & '--error>' & @error)
Else
    ConsoleWrite('Not Find File ' & @ScriptName & @CRLF)
EndIf

FileCopy(@ScriptFullPath, @ScriptDir & '\123\_' & @ScriptName, 9)
$ret = _zip_AddFiles($inFile, @ScriptDir & '\_' & @ScriptName, 1, 1)
$ar = _zip_FileInfo($inFile)
_ArrayDisplay($ar, '-2-AddFiles->' & $ret & '--error>' & @error)
$ret = _zip_AddFiles($inFile, @ScriptDir & '\123\_' & @ScriptName, 0, 1)
$ar = _zip_FileInfo($inFile)
_ArrayDisplay($ar, '-3-AddFiles->' & $ret & '--error>' & @error)
$ret = _zip_AddFiles($inFile, @ScriptDir & '\*.au3', 1, 1)
$ar = _zip_FileInfo($inFile)
_ArrayDisplay($ar, '-4-AddFiles->' & $ret & '--error>' & @error)

$ret = _zip_ExtractFiles($inFile, $OutPath);$FileMask = "*.au3"
ConsoleWrite('Extract Files >' & $ret & '--error>' & @error & @CRLF)

ShellExecute($OutPath)
MsgBox(0, '', 'Delete all temp files')
DirRemove(@ScriptDir & '\123', 1)
DirRemove(@DesktopDir & '\Test_zip', 1)
FileDelete($inFile)

Only for x86.

New in version 2:

- added support for working with encrypted files.

- added support for various compression methods.

- added item "Flag Encrypted" for file info.

- enhanced support for masks of files and folders.

New in version 3:

- fixed critical bugs version 2

pZip.rar

pZip_v3.rar

Edited by asdf8
Link to comment
Share on other sites

A file zip has password protected. How do extract it ?

In the current version - impossible. If will be a possibility to continue this subjects, it would be possible to add support for password and compression level.

Link to comment
Share on other sites

Question: this udf supports adding files to specific folder in the archive?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Question: this udf supports adding files to specific folder in the archive?

For want of evident instruction base directory, do this it is difficult

#Include <Array.au3>
#Include <pZip.au3>

$inFile = @ScriptDir & '\Test.zip'
$toZip = @ProgramFilesDir & '\Rar.exe'

$ret = _zip_AddFiles($inFile, $toZip, 1, 1)
$ar = _zip_FileInfo($inFile)
_ArrayDisplay($ar, '-AddFiles->' & $ret & '--error>' & @error)
Link to comment
Share on other sites

Library Update

New:

- added support for working with encrypted files.

- added support for various compression methods.

- added item "Flag Encrypted" for file info.

- enhanced support for masks of files and folders.

Edited by asdf8
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...