Jump to content

Scripting WinZip


Recommended Posts

Ohhh, I searched for 7z in this thread before posting. :"> I was not aware of the enterprise licensing restriction :P I take it you know about info-zip's dll's. It claims to be free to but I have not read the license :D . And I'm not sure it supports the latest compression techniques used by winzip and others (as the ultra level in 7-zip). The zip format is supposed to be a standard but you know...

Yeah, Info-ZIP's license is on a BSD model and very much free-as-in-speech as well as free-as-in-beer. That means you could include it with FileInstall() in your script.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I've hit a glitch in my _UnZip() function (relisted below). One of my zip files is 1.6GB, because it contains a 1.3GB SQL dump file. The file opens, unzips a couple of the other files in the archive, then silently exits without extracting the big file or anything after it in the file list. The _UnZip() function returns 1 and it gets logged as a successfull extraction. Two issues from that:

1. Can I get it to handle the big file?

2. Failing (1.), can I get it to properly report the failure?

:D

;----------------------------------
; Function _UnZip($sZip, $sDest)
;    Uncompress items from a .zip file a destination folder.
;    Where:
;        $sZip is the .zip file
;        $sDest is the folder to uncompress to (without trailing '\')
;    Returns 1 on success, 0 for fail
;   On fail, @Error is:
;        1 = Source zip file did not exist
;        2 = Error creating destination folder
;      3 = Shell ObjCreate error
;      4 = Zip file namespace object error
;        5 = Error creating item list object
;        6 = Destination folder namespace object error
;        7 = Error copying data
;----------------------------------
Func _UnZip($sZip, $sDest)
; Test zip file
    If FileExists($sZip) Then
   ; Test destination folder
        If Not FileExists($sDest & "\") Then
            If Not DirCreate($sDest) Then Return SetError(2, 0, 0)
        EndIf
   ; Create shell object
        Local $oShell = ObjCreate('Shell.Application')
        If Not @error And IsObj($oShell) Then
       ; Get zip file namespace object
            Local $oFolder = $oShell.NameSpace ($sZip)
            If Not @error And IsObj($oFolder) Then
           ; Get list of items in zip file
                Local $oItems = $oFolder.Items ()
                If Not @error And IsObj($oItems) Then
               ; Get destination folder namespace object
                    $oDest = $oShell.NameSpace ($sDest & "\")
                    If Not @error And IsObj($oDest) Then
                   ; Copy the files
                        $oDest.CopyHere ($oItems)
                        Sleep(500)
                        If @error = 0 Then
                            Return 1
                        Else
                            Return SetError(7, 0, 0)
                        EndIf
                    Else
                        Return SetError(6, 0, 0)
                    EndIf
                Else
                    Return SetError(5, 0, 0)
                EndIf
            Else
                Return SetError(4, 0, 0)
            EndIf
        Else
            Return SetError(3, 0, 0)
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc ;==>_UnZip
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I would still like to make the native compressed file manager in XP work for this, but my earlier posts on using 7-zip have been edited with the following:

Update: I went back to download 7-zip to a USB stick for a friends laptop and the 7-zip site says it is lincensed under LGPL! Way cool! :D

From 7-zip.org FAQ page:

Can I use the source code of 7-Zip in a commercial application?

Since 7-Zip is licensed under the GNU LGPL you must follow the rules of that license. In brief, it means that any LGPL'ed code must remain licensed under the LGPL. For instance, you can change the code from 7-Zip or write a wrapper for some code from 7-Zip and compile it into a DLL but the source code of that DLL (including your modifications / additions / wrapper) must be licensed under the LGPL or GPL. Other code of your application can be licensed as you wish. This scheme allows users and developers to change LGPL'ed code and recompile that DLL. That is idea of free software. Read more here: http://www.gnu.org/. You can also read about the LZMA SDK, which is available under a more liberal license.

My appologies to a great project for mis-reporting their lincense status. 7-zip rocks, and rocks freely! :D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 1 year later...

The _ZipCreate function failed to create a valid zip file header under AutoIt V3.2.6.0. It turns out you must specify the binary option when you create the archive file.

Func _ZipCreate($sZip, $iFlag = 0)

; Create empty zip file

$hFile = FileOpen($sZip, 8 + 2 + 16); Mode = Create folder, Overwrite, binary <<==== add 16(binary)

If $hFile <> - 1 Then

Link to comment
Share on other sites

The _ZipCreate function failed to create a valid zip file header under AutoIt V3.2.6.0. It turns out you must specify the binary option when you create the archive file.

Func _ZipCreate($sZip, $iFlag = 0)

; Create empty zip file

$hFile = FileOpen($sZip, 8 + 2 + 16); Mode = Create folder, Overwrite, binary <<==== add 16(binary)

If $hFile <> - 1 Then

Thanks for pointing that out. Code tweaked in post #19.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...