DigDeep

Unzip CAB files without windows progressbar

4 posts in this topic

#1 ·  Posted

I am able to unzip Zip files using both the examples (_Zip_UnzipAll and _ExtractZip)

But both the examples are not able to unzip any of the .CAB files without getting the Windows Progressbar even after using 4 during Copyhere

Can someone please help in getting the .CAB files extracted without the windows Progressbar?

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 629, 431, 1095, 325)
$Run = GUICtrlCreateButton("Run", 270, 260, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Run
            _Zip_UnzipAll('C:\Temp\test.cab', 'C:\Temp', 4) ; 1st Example

            ;   _ExtractZip('C:\Temp\test.cab', 'C:\Temp') ; 2nd Example

    EndSwitch
WEnd


#cs
 ; 1st Example

    ; #FUNCTION# ====================================================================================================
    ; Name...........:  _Zip_UnzipAll
    ; Description....:  Extract all files contained in a ZIP archive
    ; Syntax.........:  _Zip_UnzipAll($sZipFile, $sDestPath[, $iFlag = 20])
    ; Parameters.....:  $sZipFile   - Full path to ZIP file
    ;                   $sDestPath  - Full path to the destination
    ;                   $iFlag      - [Optional] File copy flags (Default = 4+16)
    ;                               |   4 - No progress box
    ;                               |   8 - Rename the file if a file of the same name already exists
    ;                               |  16 - Respond "Yes to All" for any dialog that is displayed
    ;                               |  64 - Preserve undo information, if possible
    ;                               | 256 - Display a progress dialog box but do not show the file names
    ;                               | 512 - Do not confirm the creation of a new directory if the operation requires one to be created
    ;                               |1024 - Do not display a user interface if an error occurs
    ;                               |2048 - Version 4.71. Do not copy the security attributes of the file
    ;                               |4096 - Only operate in the local directory, don't operate recursively into subdirectories
    ;                               |8192 - Version 5.0. Do not copy connected files as a group, only copy the specified files
    ;
    ; Return values..:  Success     - 1
    ;                   Failure     - 0 and sets @error
    ;                               | 1 - zipfldr.dll does not exist
    ;                               | 2 - Library not installed
    ;                               | 3 - Not a full path
    ;                               | 4 - ZIP file does not exist
    ;                               | 5 - Failed to create destination (if necessary)
    ;                               | 6 - Failed to open destination
    ;                               | 7 - Failed to extract file(s)
    ; Author.........:  wraithdu, torels
    ; Modified.......:
    ; Remarks........:  Overwriting of destination files is controlled solely by the file copy flags (ie $iFlag = 1 is NOT valid).
    ; Related........:
    ; Link...........:
    ; Example........:
    ; ===============================================================================================================
    Func _Zip_UnzipAll($sZipFile, $sDestPath, $iFlag = 20)
    If Not _Zip_DllChk() Then Return SetError(@error, 0, 0)
    If Not _IsFullPath($sZipFile) Or Not _IsFullPath($sDestPath) Then Return SetError(3, 0, 0)
    Local $oApp = ObjCreate("Shell.Application")
    ;Local $
    If Not IsObj($oNS) Then Return SetError(4, 0, 0)
    If StringRight($sDestPath, 1) = "\" Then $sDestPath = StringTrimRight($sDestPath, 1) ; remove trailing \
    If Not FileExists($sDestPath) Then
    DirCreate($sDestPath)
    If @error Then Return SetError(5, 0, 0)
    EndIf
    Local $oNS2 = $oApp.NameSpace($sDestPath)
    If Not IsObj($oNS2) Then Return SetError(6, 0, 0)
    $oNS2.CopyHere($oNS.Items, $iFlag)
    If FileExists($sDestPath & "\" & $oNS.Items.Item($oNS.Items.Count - 1).Name) Then
    ; success... most likely
    ; checks for existence of last item from source in destination
    Return 1
    Else
    ; failure
    Return SetError(7, 0, 0)
    EndIf
    EndFunc   ;==>_Zip_UnzipAll
#ce





#cs ; 2nd Example

    Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

    Local $i
    Do
    $i += 1
    $sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
    Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

    Local $oShell = ObjCreate("Shell.Application")

    If Not IsObj($oShell) Then
    Return SetError(1, 0, 0) ; highly unlikely but could happen
    EndIf

    Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
    If Not IsObj($oDestinationFolder) Then
    DirCreate($sDestinationFolder)
    ;~         Return SetError(2, 0, 0) ; unavailable destionation location
    EndIf

    Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
    If Not IsObj($oOriginFolder) Then
    Return SetError(3, 0, 0) ; unavailable location
    EndIf

    Local $oOriginFile = $oOriginFolder.Items() ;get all items
    If Not IsObj($oOriginFile) Then
    Return SetError(4, 0, 0) ; no such file in ZIP file
    EndIf

    ; copy content of origin to destination
    $oDestinationFolder.CopyHere($oOriginFile, 4) ; 20 means 4 and 16, replaces files if asked... Using 0x4 will be silent extract

    DirRemove($sTempZipFolder, 1) ; clean temp dir

    Return 1 ; All OK!

    EndFunc   ;==>_ExtractZip
#ce

 

I have also checked the below page and hope I have not missed out anything.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you take a more deeper look into the ZIP UDF's thread, you will find that many users report inconsistent behaviour with flags across different version of Windows. I recommend you to find another UDF

P.S This thread should be in the Help and Support forum ;)

Edited by TheDcoder
Added P.S

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks @TheDcoder

I have checked on windows 7, 8 and 10 too and find that using the flag 4 makes the extraction silent for any of the zip files. But none of the flags are identified for .cab extractions. No matter if you use 4, 8, 16, 20, 256...it only does 1 job to extract the files with the windows progressbar showing up.

My script is so big with extraction process used at so many places that I don't want to change the process now. I just want to extract CAB files silently. But if using any other UDF will solve this, I will see how to adjust it.

Can you recomend any UDFs' by the time I am also checking here?

Help appreciated.

Share this post


Link to post
Share on other sites

#4 ·  Posted

I personally use 7z (there is a standalone version available) instead of using UDFs, 7z can manage multiple formats including CAB


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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