Jump to content

ZIP.au3 UDF in pure AutoIt


torels
 Share

Recommended Posts

Hi there,

I Just posted the New Zip file with the new functions

I removed _Zip_IsCompressed()(see previous post) and integrated it in _Zip_AddFile & _Zip_AddFolder

Hope you like the new version

Change Log is in the first Post :)

I can understand some mistakes that could happend while you were writting these functions the first time you did, but this is ... (actually, cannot find words).

I would not recommend using these functions till new update.

This is very, very, very bad job. Sorry torels.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Why ?

Anyway The only things I actually changed (not including bugs) are the _Zip_Add functions

and a minor thing in _Zip_Count

and btw the _Zip_Add funcs needed those changes so to let users wait to get there files zipped (thing that was very messy before)... And the UDF now works fine (completely)

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Why ?

Anyway The only things I actually changed (not including bugs) are the _Zip_Add functions

and a minor thing in _Zip_Count

and btw the _Zip_Add funcs needed those changes so to let users wait to get there files zipped (thing that was very messy before)... And the UDF now works fine (completely)

This why:

1. _Zip_Create()

Func _Zip_Create($hFilename)
    $hFp = FileOpen($hFilename, 26)
    $sString = Chr(80) & Chr(75) & Chr(5) & Chr(6) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0) & Chr(0)
    FileWrite($hFp, $sString)
    FileClose($hFp)
    
    If Not FileExists($hFilename) Then
        Return SetError(1, 0, 0)
    Else
        Return $hFilename
    EndIf
EndFunc ;==>_Zip_Create

- you are not checking if zip file already exist before creating one

- if it's open in mode 26 then there is no need calling Chr()

2. _Zip_AddFile()

Func _Zip_AddFile($hZipFile, $hFile2Add, $flag = 4)
    Local $DLLChk = _Zip_DllChk()
    Local $files = _Zip_Count($hZipFile)
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll
    If Not FileExists($hZipFile) Then Return SetError(1, 0, 0);no zip file
    
    $oApp = ObjCreate("Shell.Application")
    $copy = $oApp.NameSpace($hZipFile).CopyHere($hFile2Add, $flag)

    While 1
        If _Zip_Count($hZipFile) = ($files+1) Then ExitLoop
    WEnd
    
    Return SetError(0,0,1)
EndFunc ;==>_Zip_AddFile

- you are not checking if file with the same name that you are adding already exists inside archive

- While... WEnd is too tight and in combination with line above will ride CPU up to 100%

- flags are not working with autoit?

3. _Zip_AddFolder()

Func _Zip_AddFolder($hZipFile, $hFolder, $flag = 4)
    Local $DLLChk = _Zip_DllChk()
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll
    If Not FileExists($hZipFile) Then Return SetError(1, 0, 0);no zip file
    
    If StringRight($hFolder, 1) <> "\" Then $hFolder &= "\"
    
    $files = _Zip_Count($hZipFile)
    $oApp = ObjCreate("Shell.Application")
    $oFolder = $oApp.NameSpace($hFolder)
    $oCopy = $oApp.NameSpace($hZipFile).CopyHere($oFolder.Items, $flag)
    $oFC = $oApp.NameSpace($hFolder).items.count

    While 1
        If _Zip_Count($hZipFile) = ($files+$oFC) Then ExitLoop
    WEnd
    
    Return SetError(0,0,1)
EndFunc ;==>_Zip_AddFolder

- this is adding folder's content, not folder

- same as for _Zip_AddFile()

4. _Zip_UnzipAll()

Func _Zip_UnzipAll($hZipFile, $hDestPath, $flag = 4)
    Local $DLLChk = _Zip_DllChk()
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll
    If Not FileExists($hZipFile) Then Return SetError(2, 0, 0);no zip file
    
    If Not FileExists($hDestPath) Then DirCreate($hDestPath)
    
    Local $aArray[1]
    $oApp = ObjCreate("Shell.Application")
    $oApp.Namespace($hDestPath).CopyHere($oApp.Namespace($hZipFile).Items, $flag)
    
    For $item In $oApp.Namespace($hZipFile).Items
        _ArrayAdd($aArray, $item)
    Next
    
    While 1
        Sleep(500)
        If FileExists($hDestPath & "\" & $aArray[UBound($aArray) - 1]) Then Return SetError(0, 0, 1)
        ExitLoop
    WEnd
    
EndFunc ;==>_Zip_UnzipAll

- you are leaving garbage in @TempDir

- not cheking if folder/file already exists

- unzipping is done by zipfldr.dll and that process is not asynchronous as zipping, therefore you don't need While.. WEnd and Sleep(500) to verify if extracted exists.

- If FileExists($hDestPath & "\" & $aArray[uBound($aArray) - 1]) means what???

5. _Zip_Unzip()

Func _Zip_Unzip($hZipFile, $hFilename, $hDestPath, $flag = 4)
    Local $DLLChk = _Zip_DllChk()
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0);no dll
    If Not FileExists($hZipFile) Then Return SetError(1, 0, 0);no zip file
    
    If Not FileExists($hDestPath) Then DirCreate($hDestPath)
    
    $oApp = ObjCreate("Shell.Application")
    $hFolderitem = $oApp.NameSpace($hZipFile).Parsename($hFilename)
    
    $oApp.NameSpace($hDestPath).Copyhere($hFolderitem, $flag)
    
    While 1
        Sleep(500)
        If FileExists($hDestPath & "\" & $hFilename) Then
            return SetError(0, 0, 1)
            ExitLoop
        EndIf
    WEnd
    
    
EndFunc ;==>_Zip_Unzip

- not checking if file to extrace exists

- not asynchronous. sleeping 500 not needed

- garbage in @TempDir

6. _Zip_Count()

- ok, but take look to the Zip.au3 and you say what is wrong

7. _Zip_List()

- same as above

8. _Zip_Search()

Func _Zip_Search($hZipFile, $sSearchString)
    local $aArray
    $list = _Zip_List($hZipFile)
    for $i = 0 to UBound($list) - 1
        if StringInStr($list[$i],$sSearchstring) > 0 Then
            _ArrayAdd($aArray, $list[$i])
        EndIf
    Next
    if UBound($aArray) - 1 = 0 Then
        Return SetError(1,0,0)
    Else
        Return $aArray
    EndIf
EndFunc;==> _Zip_Search

- not checking if archive exists

- no way this will work anyway (local $aArray is not the way to create an array)

9. _Zip_SearchInFile()

Func _Zip_SearchInFile($hZipFile, $sSearchString)
    local $aArray
    $list = _Zip_List($hZipFile)
    for $i = 1 to UBound($list) - 1
        _Zip_Unzip($hZipFile, $list[$i], @TempDir & "\tmp_zip.file")
        $file = FileOpen (@TempDir & "\tmp_zip.file", 0)
        $read = FileRead($file)
        if StringInStr($read,$sSearchstring) > 0 Then
            _ArrayAdd($aArray, $list[$i])
        EndIf
    Next
    if UBound($aArray) - 1 = 0 Then
        Return SetError(1,0,1)
    Else
        Return $aArray
    EndIf
EndFunc;==> _Zip_Search

- same as above

- omg (this represents everything else)

And you ask "why?"

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

- you are not checking if zip file already exist before creating one (what do I do if I want to replace a file ?)

- if it's open in mode 26 then there is no need calling Chr() (It's the only way I know to add nul chars... XD)

- While... WEnd is too tight and in combination with line above will ride CPU up to 100% (it doesn't on a Pc with 256 MB of RAM... Should be working)

- flags are not working with autoit? (nope... Don't know why)

- this is adding folder's content, not folder (It's done intetionally)

- you are leaving garbage in @TempDir (depends from the shell)

- not cheking if folder/file already exists (can't care less... Eventually returns an error)

- If FileExists($hDestPath & "\" & $aArray[uBound($aArray) - 1]) means what??? (means check if the last file has been copied... meaning: have all files been copied in the folder ?)

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

anyway... any other comments/suggestions are welcome :)

hope you enjoy the new version

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Looks like a great UDF and hope it makes it into the official release

But I get this error

D:\AutoIt v3.2.12.1\Include\Zip.au3 (239) : ==> Object referenced outside a "With" statement.:

return $oApp.Namespace($hZipFile).Items.count

return $oApp.Namespace($hZipFile)^ ERROR

AutoViewer first public AutoIt script
Link to comment
Share on other sites

Looks like a great UDF and hope it makes it into the official release

But I get this error

D:\AutoIt v3.2.12.1\Include\Zip.au3 (239) : ==> Object referenced outside a "With" statement.:

return $oApp.Namespace($hZipFile).Items.count

return $oApp.Namespace($hZipFile)^ ERROR

DVHRLD, i had the same issue, try this suggestion here, it worked for me.

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Link to comment
Share on other sites

I'm having a similar problem with it, I can't get it to add a file to a zip archive. The error I get is:

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "\\.host\Shared Folders\My Documents\AutoItScripts\TestZip.au3"

C:\Program Files\AutoIt3\Include\Zip.au3 (239) : ==> Object referenced outside a "With" statement.:

return $oApp.Namespace($hZipFile).Items.count

return $oApp.Namespace($hZipFile)^ ERROR

->12:08:54 AutoIT3.exe ended.rc:1

Line 239 of Zip.au3 reads:

return $oApp.Namespace($hZipFile).Items.count

I'm just testing this with a very basic script:

#include <Zip.au3>
Dim $Zip, $myfile
$myfile = "C:\Test\BigFile.bin"
$Zip = _Zip_Create("C:\Test\TestZIP.zip")
_Zip_AddFile($Zip,$myfile)

I've copied the newest Zip.au3 from the first page to my include directory so should be using the latest version.

Any help would be much appreciated.

TIA :P

Link to comment
Share on other sites

solved:

For the moment this is the fix:

Func _Zip_Count($hZipFile)
    Local $DLLChk = _Zip_DllChk()
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0) ;no dll
    If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file
    
    $items = _Zip_List($hZipFile)
    Return UBound($items) - 1
EndFunc   ;==>_Zip_Count

a new update will be on the forum on a short time with some new functions and fixes

cheers =P

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

solved:

For the moment this is the fix:

Func _Zip_Count($hZipFile)
    Local $DLLChk = _Zip_DllChk()
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0) ;no dll
    If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file
    
    $items = _Zip_List($hZipFile)
    Return UBound($items) - 1
EndFunc   ;==>_Zip_Count

a new update will be on the forum on a short time with some new functions and fixes

cheers =P

Nice, Thanks Torels

I look forward to the release.

AutoViewer first public AutoIt script
Link to comment
Share on other sites

New Zip UDF Update uploaded on the forum !

Hope you like it

Deatails in the first post!

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

New Zip UDF Update uploaded on the forum !

Hope you like it

Deatails in the first post!

I've updated Auto It and downloaded the latest UDF, and now I'm getting an error.

Line 300 (File "C:\Program Files\AutoIt3\Beta\Include\Zip.au3"):
$hList = $oApp.Namespace($hZipFile).Items
$hList = $oApp.Namespace($hZipFile)^ERROR

Error: Object referenced outside a "With" statement.

Anyone resolve this yet? I tried the suggestion previously in the thread and could not for the life of me get it to work.

Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

I've updated Auto It and downloaded the latest UDF, and now I'm getting an error.

Line 300 (File "C:\Program Files\AutoIt3\Beta\Include\Zip.au3"):
$hList = $oApp.Namespace($hZipFile).Items
$hList = $oApp.Namespace($hZipFile)^ERROR

Error: Object referenced outside a "With" statement.

Anyone resolve this yet? I tried the suggestion previously in the thread and could not for the life of me get it to work.

Hi RagnarocktA, can you please post your code ?

thanks :P

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Hi RagnarocktA, can you please post your code ?

thanks :P

Sure thing. It's a pretty massive script, so I'll only post what is needed.

#Region --- Includes ---
;----- Standard Includes -----
        #include <Constants.au3>
        #include <ButtonConstants.au3>
        #include <EditConstants.au3>
        #include <WindowsConstants.au3>
        #include <GUIConstants.au3>
        #include <GUIConstantsEx.au3>
        #include <GUIListView.au3>
        #include <Misc.au3>
        #include <Array.au3>
        #include <File.au3>

;----- Non-Standard Includes -----
        #include <Zip.au3>
        #include <ModernMenuRaw.au3>
        #include <String.au3>
#EndRegion --- Includes ---

        Global $sWoWGameDirectory   = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft", "InstallPath")

        $sDate = @MON & "-" & @MDAY & "-" & @YEAR
        $sUIArchive     = $sWoWGameDirectory & '\WoW UI Backup\WoW UI Backup - ' & $sDate & '.zip'
        $fUICache       = $sWoWGameDirectory & '\Cache'
        $fUIInterface   = $sWoWGameDirectory & '\Interface'
        $fUIWTF         = $sWoWGameDirectory & '\Interface'

        $zArchive = _Zip_Create($sUIArchive)

        _Zip_AddFolder($zArchive, $fUICache, 4)
        _Zip_AddFolder($zArchive, $fUIInterface, 4)
        _Zip_AddFolder($zArchive, $fUIWTF, 4)
Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

Don't know why... It's working fine for me... (Using different paths from yours)

Anyway... just replace this

Func _Zip_List($hZipFile)
    local $aArray[1]
    Local $DLLChk = _Zip_DllChk()
    If $DLLChk <> 0 Then Return SetError($DLLChk, 0, 0) ;no dll
    If Not FileExists($hZipFile) Then Return SetError(1, 0, 0) ;no zip file
    
    $oApp = ObjCreate("Shell.Application")
    $hList = $oApp.Namespace($hZipFile).Items
    
    For $item in $hList
        _ArrayAdd($aArray,$item.name)
    Next
    $aArray[0] = UBound($aArray) - 1
    Return $aArray
EndFunc   ;==>_Zip_ListoÝ÷ Û­Øb±«­¢+ÙÕ¹}i¥Á}1¥ÍÐ ÀÌØí¡i¥Á¥±¤(%±½°ÀÌØíÉÉålÅt(%1½°ÀÌØí11
¡¬ô}i¥Á}±±
¡¬ ¤(%%ÀÌØí11
¡¬±ÐìÐìÀQ¡¸IÑÕɸMÑÉÉ½È ÀÌØí11
¡¬°À°À¤í¹¼±°(%%9½Ð¥±á¥ÍÑÌ ÀÌØí¡i¥Á¥±¤Q¡¸IÑÕɸMÑÉÉ½È Ä°À°À¤í¹¼é¥À¥±($($ÀÌØí½ÁÀô=©
ÉÑ ÅÕ½ÐíM¡±°¹ÁÁ±¥Ñ¥½¸ÅÕ½Ðì¤(]¥Ñ ÀÌØí½ÁÀ($ÀÌØí¡1¥ÍÐô¹9µÍÁ ÀÌØí¡i¥Á¥±¤¹%ѵÌ(¹]¥Ñ ($(%½ÈÀÌØí¥Ñ´¥¸ÀÌØí¡1¥ÍÐ($%}ÉÉå ÀÌØíÉÉä°ÀÌØí¥Ñ´¹¹µ¤(%9áÐ($ÀÌØíÉÉålÁtôU   ½Õ¹ ÀÌØíÉÉ䤴Ä(%IÑÕɸÀÌØíÉÉä)¹Õ¹ìôôÐí}i¥Á}1¥ÍÐ

should work :P

cheers

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Link to comment
Share on other sites

Done and done. Now that error has passed, but I'm getting the following error on the same line.

Line 301 (File "C:\Program Files\AutoIt3\Beta\Include\Zip.au3"):
$hList = $oApp.Namespace($hZipFile).Items
$hList = $oApp.Namespace($hZipFile).Items^ ERROR

Error: Error in expression
Edited by RagnaroktA
Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki
Link to comment
Share on other sites

excuse me... what OS are you using ?

on XP SP 3 with autoit 2.12.0.1 it works fine in both ways

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

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...