Jump to content
Decipher

7-Zip UDF using MemoryDLL UDF

Recommended Posts

Decipher

I updated the UDF by Patric Pendelin to use the MemoryDLL UDF.

There are only two new functions: _SevenZip_Load & _SevenZip_Free

The first function must be called before using any other functions included in the UDF and the other should be called to free memory when the UDF is no longer needed!

The size of binary from the module was excessive so I used the ZLMA UDF to compress it. It will be decompressed at run time before its loaded into memory.

The only advantage of using this UDF is that it removes the need to included any DLLs in your script.

A lot of functions haven't been added yet! :(

For those that dare: The API for the 7-Zip32.dll module is included in the attachment.

These functions work in the same way you would you use the standalone 7za.exe executable so the Help.chm file applies to these functions aswell.

Thats it, Enjoy! ;)

The code below is a sneak peak at the actually UDF, meaning it dosen't work without the other includes and the embed binary. - Download the attachment. :idea:

#include-once
#include "MemoryDLL.au3"
#include "LZMA.au3"
Global $__7ZIPDLL = Default, $__7ZIPINIT = False

#cs ===============================================================================
    Name:       7-Zip.au3
    Version:    1.0
    Datum:      08.07.2008

    Author: Patric Pendelin eMail: <patric.pendelin (a) gmx.de>
    Modified By: Decipher

    Script Function:

     _SevenZip_Load()
     _SevenZip_Extract($s_Archive, $s_Out="", $s_Pass="", $szCmdLine="", $s_Overwrite="", $hwnd=0, $szOutput="NULL", $dwSize=0) Extracts files from an archive
     _SevenZip_Add($s_Archive, $s_Out = "", $s_Typ = "7z32", $i_Comp = 5, $s_Pass = "", $szCmdLine = "", $hwnd = 0, $szOutput = "NULL", $dwSize = 0) Add files to an archive
     _SevenZip_GetVersion() Get 7_zip32.dll Version
     _SevenZip_GetRunning()
     _SevenZip_CheckArchive($s_Archive, $i_iMode = 0)
     _SevenZip_GetArchiveType($s_Archive)
     _SevenZip_GetFileCount($s_Archive)
     _SevenZip_GetUDFVersion() Returns UDF version number
     _SevenZip_Free()
#ce ===============================================================================

Func _SevenZip_Load()
    If Not $__7ZIPINIT Then
        $__7ZIPDLL = MemoryDllOpen(__7ZIPBIN())
        $__7ZIPINIT = True
    EndIf
EndFunc

Func _SevenZip_Free()
    If $__7ZIPINIT Then
        MemoryDllClose($__7ZIPDLL)
        $__7ZIPINIT = False
        $__7ZIPDLL = Default
    EndIf
EndFunc

;===============================================================================
; Function Name:     _SevenZip_Extract
; Description:      Extracts files from an archive
;
; Parameter(s):     $s_Archive:     Fullpath to Archive-File
;                   $s_Out:         Specifies a destination directory where files are to be extracted. (Def. "")
;                   $s_Pass:        Specifies password. (Def. "")
;                   $szCmdLine:     Command Line Commands. (Def. "")
;                   $s_Overwrite:   Specifies the overwrite mode during extraction, to overwrite files already present on disk. (Def. "")
;                               -1: Overwrite All existing files without prompt.
;                               -2: Skip extracting of existing files.
;                               -3: aUto rename extracting file (for example, name.txt will be renamed to name_1.txt).
;                               -4: auto rename existing file (for example, name.txt will be renamed to name_1.txt).
;                   $hwnd:          The window handle of the application which calls 7-zip32.dll. (Def. 0)
;                   $szOutput:      The buffer because 7-zip32.dll returns the result. (Def. "NULL")
;                   $dwSize:        Größe des Puffers. When the result exceeds designated size, it is economized in this size.
;                                   If size is 1 or more, always NULL letter is added lastly.   (Def. 0)
;
; Syntax:            _SevenZip_Extract($s_Archive, $s_Out="", $s_Pass="", $szCmdLine="", $s_Overwrite="", $hwnd=0, $szOutput="NULL", $dwSize=0)
; Return Value(s):      On Success -Return 1
;                                   On Failure -@error
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_Extract($s_Archive, $s_Out = "", $s_Pass = "", $szCmdLine = "", $s_Overwrite = "", $hwnd = 0, $szOutput = "NULL", $dwSize = 0)
    ; Set Output directory
    If $s_Out = "" Then
        Local $as_Res = StringSplit($s_Archive, "\")
        For $i = 1 To $as_Res[0] - 1
            $s_Out &= $as_Res[$i] & "\"
        Next
    EndIf
    ; (Overwrite mode) switch:
    If $s_Overwrite = 1 Then
        $s_Overwrite = "-aoa"; Overwrite All existing files without prompt.
    ElseIf $s_Overwrite = 2 Then
        $s_Overwrite = "-aos"; Skip extracting of existing files.
    ElseIf $s_Overwrite = 3 Then
        $s_Overwrite = "-aou"; Auto rename extracting file (for example, name.txt will be renamed to name_1.txt).
    ElseIf $s_Overwrite = 4 Then
        $s_Overwrite = "-aot"; Auto rename existing file (for example, name.txt will be renamed to name_1.txt).
    EndIf
    If $szCmdLine = "" Then $szCmdLine = ' x "' & $s_Archive & '" ' & $s_Overwrite & ' -o"' & $s_Out & '" -p"' & $s_Pass & '"'
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZip", "hwnd", $hwnd, "str", $szCmdLine, "str", $szOutput, "int", $dwSize)
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_Extract

;===============================================================================
; Function Name:     _SevenZip_Add
; Description:      Extracts files from an archive
;
; Parameter(s):     $s_Archive:     Fullpath to Archive-File
;                   $s_Out:         Specifies a destination directory where files are to be extracted. (Def. "")
;                   $s_Typ:         Specifies the type of archive.
;                   $i_Comp:        Sets level of compression. [0 | 1 | 3 | 5 | 7 | 9 ]
;                   $s_Pass:        Specifies password. (Def. "")
;                   $szCmdLine:     Command Line Commands. (Def. "")
;                   $hwnd:          The window handle of the application which calls 7-zip32.dll. (Def. 0)
;                   $szOutput:      The buffer because 7-zip32.dll returns the result. (Def. "NULL")
;                   $dwSize:        Größe des Puffers. When the result exceeds designated size, it is economized in this size.
;                                   If size is 1 or more, always NULL letter is added lastly.   (Def. 0)
;
; Syntax:            _SevenZip_Add($s_Archive, $s_Out = "", $s_Typ = "7z32", $i_Comp = 5, $s_Pass = "", $szCmdLine = "", $hwnd = 0, $szOutput = "NULL", $dwSize = 0)
; Return Value(s):      On Success -Return 1
;                                   On Failure -@error
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_Add($s_Archive, $s_Out = "", $s_Typ = "7z32", $i_Comp = 5, $s_Pass = "", $szCmdLine = "", $hwnd = 0, $szOutput = "NULL", $dwSize = 0)
    If $szCmdLine = "" Then
        If $s_Pass = "" Then
            $szCmdLine = '-t' & $s_Typ & ' a "' & $s_Archive & '" "' & $s_Out & '" -mx=' & $i_Comp
        Else
            $szCmdLine = '-t' & $s_Typ & ' a "' & $s_Archive & '" "' & $s_Out & '" -p"' & $s_Pass & '" -mhe=on -mx=' & $i_Comp
        EndIf
    EndIf
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZip", "hwnd", $hwnd, "str", $szCmdLine, "str", $szOutput, "int", $dwSize)
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_Add

;===============================================================================
; Function Name:     _SevenZip_GetVersion
; Description:      The version of 7-zip32.dll is returned.
;
; Parameter(s):     None.
;
; Syntax:            _SevenZip_GetVersion()
; Return Value(s):      On Success -Return File Version
;                                   On Failure -@error
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_GetVersion()
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZipGetVersion")
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_GetVersion

;===============================================================================
; Function Name:     _SevenZip_GetRunning
; Description:      Whether or not presently 7-zip32.dll while operating, you obtain.
;                   Application side before executing API which by all means accompanies file access such as compressing/thawing,
;                   it is necessary to check whether because of this feasibility.
;
; Parameter(s):     None.
;
; Syntax:            _SevenZip_GetRunning()
; Return Value(s):      On Success -Return 1(It is in the midst of executing.)
;                                   Return 0(Is not in the midst of executing, (feasibility).)
;                                   On Failure -@error
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_GetRunning()
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZipGetRunning")
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_GetRunning

;===============================================================================
; Function Name:     _SevenZip_CheckArchive
; Description:      Whether or not presently 7-zip32.dll while operating, you obtain.
;                   As the archive file which the designated file supports
;                   It returns whether or not it is correct.
;
; Parameter(s):     $s_Archive:     Fullpath to Archive file
;
; Syntax:            _SevenZip_CheckArchive($s_Archive)
; Return Value(s):      On Success -Return 1 (At the time of correct archive file.)
;                                   Return 0 (When the file is illegitimate.)
;                                   On Failure -@error
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_CheckArchive($s_Archive, $i_iMode = 0)
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZipCheckArchive", "str", $s_Archive, "int", $i_iMode)
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_CheckArchive

;===============================================================================
; Function Name:     _SevenZip_GetArchiveType
; Description:      Type of the archive file
;
; Parameter(s):     $s_Archive:     Fullpath to Archive file
;
; Syntax:            _SevenZip_GetArchiveType($s_Archive)
; Return Value(s):      On Success -Return 1 (ZIP type)
;                                   Return 2 (7z32 type)
;                                   On Failure -@error
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_GetArchiveType($s_Archive)
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZipGetArchiveType", "str", $s_Archive)
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_GetArchiveType

;===============================================================================
; Function Name:     _SevenZip_GetFileCount
; Description:      Type of the archive file
;
; Parameter(s):     $s_Archive:     The number of files in the Archive file.
;
; Syntax:            _SevenZip_GetFileCount($s_Archive)
; Return Value(s):  On Success -Return Numer of files
;                   On Failure -@error 1:   Can´t opens a DLL file for use in MemoryDllCall.
;                               @error 2:   Error in MemoryDllCall
;
; Author(s):        Patric Pendelin <patric.pendelin (a) gmx.de>
;===============================================================================
Func  _SevenZip_GetFileCount($s_Archive)
    Local $aRet = MemoryDllCall($__7ZIPDLL, "int", "SevenZipGetFileCount", "str", $s_Archive)
    Return SetError(@error, "", $aRet[0])
EndFunc   ;==> _SevenZip_GetFileCount

#region ### BINARY ###
Func __7ZIPBIN()
        #cs
    Name:   7-ZIP32 BINARY Version 9.20.00.02
    Requirements:   Windows9x/Me/NT/200x/XP/Vista/7
    Author:     Akita Minoru ( Http://Akky.Xrea.Jp/support.Html )

Download the Library: 7-Zip-Library.7z

Basic Usage:

#include "7-Zip.au3"

_SevenZip_Load()

Dim $sCommandLine = "Accepts Switches and etc"
_SevenZip_Exec($sCommandLine) ; See the included 7-Zip.chm documentation

_SevenZip_Free()

Exit

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites
iHonda

Just a few questions... the _7zip_Exec that you reference in your example does not exist.  So I figured "ok I'll just use _7zip_Add" but when I was reading the documentation for it it says its for extracting files from the archive rather than creating an archive..... is this just a documentation error or am I crazy?


A great place to start Autoit 1-2-3

Share this post


Link to post
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

  • Similar Content

    • marcoauto
      By marcoauto
      Ciao
      I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.
      The instructions say to follow this sequence:
      and to connectTo with C++ is:
      string address = "192.168.1.240"; _BMDSwitcherConnectToFailure failureReason = 0; IBMDSwitcher switcher = null; var discovery = new CBMDSwitcherDiscovery(); discovery.ConnectTo(address, out switcher, out failureReason); From Blackmagic SDK:
      IBMDSwitcherDiscovery::ConnectTo method
      The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.
      Syntax HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason); Parameters: deviceAddress in Network hostname or IP address of switcher to connect to. switcherDevice out IBMDSwitcher object interface for the connected switcher. failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value. So, I have I tried these solutions but with non success:
      $DllName =@ScriptDir&"\BMDSwitcherAPI.dll" $result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF) ConsoleWrite("DLLCall Result: " & $result & @CRLF) and I have tried also create an Object (That I think is the best way solution):
      #include <MsgBoxConstants.au3> $oSwitcher=ObjCreate("IBMDSwitcher") If IsObj($oSwitcher) Then MsgBox(64, "", "Object $oSwitcher created successfully") EndIf $oAtem=ObjCreate("IBMDSwitcherDiscovery") If IsObj($oAtem) Then MsgBox(64, "", "Object $oAtem created successfully") EndIf $failureReason =ObjCreate("_BMDSwitcherConnectToFailure") If IsObj($failureReason) Then MsgBox(64, "", "Object $failureReason created successfully") EndIf $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler Global $errore,$oSwitcher1 $oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason); ; This is the custom error handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription & @CRLF & _ "Source is: " & $oMyError.source & @CRLF & _ "Description is: " & $oMyError.description & @CRLF & _ "Helpfile is: " & $oMyError.helpfile & @CRLF & _ "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _ "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _ "Scriptline is: " & $oMyError.scriptline) EndFunc ;==>MyErrFunc But the result is:
      We intercepted a COM Error !
      Number is: 000000A9
      Windescription is: Variable must be of type 'Object'.
      Source is: 
      Description is: 
      Helpfile is: 
      Helpcontext is: 
      Lastdllerror is: 0
      Scriptline is: 17
      The BMDSwitcherAPI.dll is registered in system. Can someone help me?
      Grazie
      Marco
    • xtcislove
      By xtcislove
      Hello,
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Title
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 
      -Transparency

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

       
       
      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")  
      ScalingMessageBox.au3
    • Gowrisankar
      By Gowrisankar
      Dear members, 
      I am working on a project where, emails from outlook are to be read and moved to various folders within the mailbox, based on the content of the emails.
      I used the below code for moving mails. It works fine when I run it against individual mail ids. But when I run it on Shared mailbox, the mails are not moved to respective folders.
      _OL_ItemMove($oOutlook, $sEntryId, Default, $sDestinationFolder) The value of $sEntryId is saved in an excel report initially. The current process reads the $sEntryId from the excel and passes it to "_OL_ItemMove" statement.
      Requesting the guidance of the forum members in this issue.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
    • ScriptJunky
      By ScriptJunky
      I noticed a lack of a constants file for _WinAPI_GetSystemMetrics() so I made this for anyone who wants to add it to their library. Enjoy!  (file attached below)
      #include-once ; #INDEX# ======================================================================================================================= ; Title .........: WinAPI GetSystemMetrics Constants ; AutoIt Version : 3.3.14.5 ; Language ......: English ; Description ...: Constants for _WinAPI_GetSystemMetrics(). ; Author(s) .....: ScriptJunky ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== ; _WinAPI_GetSystemMetrics() Global Const $ARRANGE = 56 Global Const $CLEANBOOT = 67 Global Const $CMONITORS = 80 Global Const $CMOUSEBUTTONS = 43 Global Const $CONVERTIBLESLATEMODE = 0x2003 Global Const $CXBORDER = 5 Global Const $CXCURSOR = 13 Global Const $CXDLGFRAME = 7 Global Const $CXDOUBLECLK = 36 Global Const $CXDRAG = 68 Global Const $CXEDGE = 45 Global Const $CXFIXEDFRAME = 7 Global Const $CXFOCUSBORDER = 83 Global Const $CXFRAME = 32 Global Const $CXFULLSCREEN = 16 Global Const $CXHSCROLL = 21 Global Const $CXHTHUMB = 10 Global Const $CXICON = 11 Global Const $CXICONSPACING = 38 Global Const $CXMAXIMIZED = 61 Global Const $CXMAXTRACK = 59 Global Const $CXMENUCHECK = 71 Global Const $CXMENUSIZE = 54 Global Const $CXMIN = 28 Global Const $CXMINIMIZED = 57 Global Const $CXMINSPACING = 47 Global Const $CXMINTRACK = 34 Global Const $CXPADDEDBORDER = 92 Global Const $CXSCREEN = 0 Global Const $CXSIZE = 30 Global Const $CXSIZEFRAME = 32 Global Const $CXSMICON = 49 Global Const $CXSMSIZE = 52 Global Const $CXVIRTUALSCREEN = 78 Global Const $CXVSCROLL = 2 Global Const $CYBORDER = 6 Global Const $CYCAPTION = 4 Global Const $CYCURSOR = 14 Global Const $CYDLGFRAME = 8 Global Const $CYDOUBLECLK = 37 Global Const $CYDRAG = 69 Global Const $CYEDGE = 46 Global Const $CYFIXEDFRAME = 8 Global Const $CYFOCUSBORDER = 84 Global Const $CYFRAME = 33 Global Const $CYFULLSCREEN = 17 Global Const $CYHSCROLL = 3 Global Const $CYICON = 12 Global Const $CYICONSPACING = 39 Global Const $CYKANJIWINDOW = 18 Global Const $CYMAXIMIZED = 62 Global Const $CYMAXTRACK = 60 Global Const $CYMENU = 15 Global Const $CYMENUCHECK = 72 Global Const $CYMENUSIZE = 55 Global Const $CYMIN = 29 Global Const $CYMINIMIZED = 58 Global Const $CYMINSPACING = 48 Global Const $CYMINTRACK = 35 Global Const $CYSCREEN = 1 Global Const $CYSIZE = 31 Global Const $CYSIZEFRAME = 33 Global Const $CYSMCAPTION = 51 Global Const $CYSMICON = 50 Global Const $CYSMSIZE = 53 Global Const $CYVIRTUALSCREEN = 79 Global Const $CYVSCROLL = 20 Global Const $CYVTHUMB = 9 Global Const $DBCSENABLED = 42 Global Const $DEBUG = 22 Global Const $DIGITIZER = 94 Global Const $IMMENABLED = 82 Global Const $MAXIMUMTOUCHES = 95 Global Const $MEDIACENTER = 87 Global Const $MENUDROPALIGNMENT = 40 Global Const $MIDEASTENABLED = 74 Global Const $MOUSEPRESENT = 19 Global Const $MOUSEHORIZONTALWHEELPRESENT = 91 Global Const $MOUSEWHEELPRESENT = 75 Global Const $NETWORK = 63 Global Const $PENWINDOWS = 41 Global Const $REMOTECONTROL = 0x2001 Global Const $REMOTESESSION = 0x1000 Global Const $SAMEDISPLAYFORMAT = 81 Global Const $SECURE = 44 Global Const $SERVERR = 289 Global Const $SHOWSOUNDS = 70 Global Const $SHUTTINGDOWN = 0x2000 Global Const $SLOWMACHINE = 73 Global Const $STARTER = 88 Global Const $SWAPBUTTON = 23 Global Const $TABLETPC = 86 Global Const $XVIRTUALSCREEN = 76 Global Const $YVIRTUALSCREEN = 77  
      WinAPISystemMetricsConstants.au3
×