PureZIP library : ZIP / UNZIP files

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

User avatar
AL90
Enthusiast
Enthusiast
Posts: 217
Joined: Fri Sep 16, 2005 7:47 pm
Location: Germany
Contact:

Post by AL90 »

gnozal wrote: If you wish more control when using PureZIP, please use the PureZIP_Archive_* functions. Then you can decide what file to add or not, what error message display etc...
Ok I will read more over it in your Docs and test it.
gnozal wrote: Probably not, because there is no ZLIB function for this. You have to unpack/repack the archive to do this.
Hmm I think its very complex because the Archive must complete
extracted in a Temporary Directory. Ok I will make some test with it
and see which solution is possible.

BTW:

I use AddFiles with wildcards because I want copy files direct in a specified
ZIP-Folder. e.g.

C:\MyFolder1_in_ZIP\MyFolder2_in_ZIP\MyFile.xyz

so I can add with AddFiles() e.g. as start with Folder2.

C:\MyFolder1_in_ZIP\*.*

so I become the required result I want.

ZIP:\MyFolder2_in_ZIP\MyFile.xyz

Therefore I requested for a optional DestPath$ params because I think
its a better way as my example on top, but it is very sad
that it is not possible to create. :cry:
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

AL90 wrote:Therefore I requested for a optional DestPath$ params because I think its a better way as my example on top, but it is very sad that it is not possible to create. :cry:
I use ZLIB's zipOpenNewFileInZip() function.
zipOpenNewFileInZip() wrote:int ZEXPORT zipOpenNewFileInZip OF ((zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level))
I don't see how to do what you ask : there is only the *filename, no optional DestPath$ parameter.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
AL90
Enthusiast
Enthusiast
Posts: 217
Joined: Fri Sep 16, 2005 7:47 pm
Location: Germany
Contact:

Post by AL90 »

gnozal wrote:I don't see how to do what you ask : there is only the *filename, no optional DestPath$ parameter.
Ok here an other example:

In my current project I have two File-Explorers:

e.g. Left = "C:\Program Files" | Right = "ZIP:\AnyFolder"

Now I want copy (Pack) Files from left to right.

for example I want copy a folder named Test\ (available in C:\Program Files\)

Now I create a TempDir with following name...

C:\Windows\Temp\MyOwnTempDir\AnyFolder\Test\

...and copy the contains from C:\Program Files\Test\ to the TempDir on top.
Now I can add files to zip with the C:\Windows\Temp\MyOwnTempDir\*.* wildcard
withit the subfolder AnyFolder\ is also in ZIP-File. (as result so ZIP:\AnyFolder\Test\)

What I mean is a DestPath$ param for IN-ZIP-FILE (Not for HD) Sorry when
I have not correct explained. :oops:
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

AL90 wrote:...and copy the contains from C:\Program Files\Test\ to the TempDir on top.
Now I can add files to zip with the C:\Windows\Temp\MyOwnTempDir\*.* wildcard
withit the subfolder AnyFolder\ is also in ZIP-File. (as result so ZIP:\AnyFolder\Test\)
It should work if you use #PureZIP_StorePathRelative, like this : PureZIP_AddFiles(MyZIP$, "C:\Windows\Temp\MyOwnTempDir\*.*", #PureZIP_StorePathRelative, #PureZIP_Recursive). The files will be added in the zip file in "AnyFolder\Test".
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
AL90
Enthusiast
Enthusiast
Posts: 217
Joined: Fri Sep 16, 2005 7:47 pm
Location: Germany
Contact:

Post by AL90 »

gnozal wrote: It should work if you use #PureZIP_StorePathRelative, like this : PureZIP_AddFiles(MyZIP$, "C:\Windows\Temp\MyOwnTempDir\*.*", #PureZIP_StorePathRelative, #PureZIP_Recursive). The files will be added in the zip file in "AnyFolder\Test".
Yes. This is my current way to do. But this all is not possible without Copy to Temp before AddFiles to zip
because the Folder AnyFolder\ will not apply in ZIP:

Example:
an direct copy to ZIP with e.g. PureZIP_AddFiles(MyZIP$, "C:\Program Files\MyProg\*.*", #PureZIP_StorePathRelative, #PureZIP_Recursive)

will not apply the Folder MyProg\ in zip. With C:\Program Files\*.* it is possible but all
the other Files will also copied in zip. It is so no solution for me. Therefore my idea with an optional
path. But you mean it is not possible. ?!
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

AL90 wrote:But you mean it is not possible. ?!
That's what I explained in my previous post :
gnozal wrote:I use ZLIB's zipOpenNewFileInZip() function.
zipOpenNewFileInZip() wrote:int ZEXPORT zipOpenNewFileInZip OF ((zipFile file, const char *filename, const zip_fileinfo *zipfi, const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global, uInt size_extrafield_global, const char *comment, int method, int level))
I don't see how to do what you ask : there is only the *filename, no optional DestPath$ parameter.
AFAIK, when adding a file to an archive, there is no optional parameter to do what you request in the ZLIB version I use.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
AL90
Enthusiast
Enthusiast
Posts: 217
Joined: Fri Sep 16, 2005 7:47 pm
Location: Germany
Contact:

Post by AL90 »

gnozal wrote:That's what I explained in my previous post :
Yes you right. Sorry! - Now I have no more questions.
I will now myself see what I can do and find some solutions.

Thanks for help. :wink:
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

I have a small problem:
My ZIP file contains after compressing some 0 Byte files. I don't know why.

All files are OK, if I use this:

Code: Select all

PureZIP_AddFiles(PackDatei$, SourceDir$+"*.*", #PureZIP_StorePathRelative, #PureZIP_RecursiveZeroDirs)
The ZIP contains some 0 Byte Files, if I use this:

Code: Select all

If PureZIP_Archive_Create(PackDatei$, #APPEND_STATUS_CREATE)
  PureZIP_Archive_Compress(SourceDir$+"readme.rtf", #True)
  ; .....
PureZIP_Archive_Close()
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Thorsten1867 wrote:I have a small problem:
My ZIP file contains after compressing some 0 Byte files. I don't know why.
About 0 byte files and #PureZIP_RecursiveZeroDirs, have a look at this post : http://www.purebasic.fr/english/viewtop ... &start=185
Thorsten1867 wrote:The ZIP contains some 0 Byte Files, if I use this:

Code: Select all

If PureZIP_Archive_Create(PackDatei$, #APPEND_STATUS_CREATE)
  PureZIP_Archive_Compress(SourceDir$+"readme.rtf", #True)
  ; .....
PureZIP_Archive_Close()
You mean the packed 'readme.rtf' has 0 bytes length in archive ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

gnozal wrote:You mean the packed 'readme.rtf' has 0 bytes length in archive ?
Yes. Some files have after compressing 0 Byte, other files are compressed correct.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Thorsten1867 wrote:
gnozal wrote:You mean the packed 'readme.rtf' has 0 bytes length in archive ?
Yes. Some files have after compressing 0 Byte, other files are compressed correct.
Could you post a link to this rtf file (or any other file wich is compressed to zero length) ?
Do you compile in ANSI or UNICODE mode ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

I used no unicode Exe.

Take a look to 'InstProgs' or 'Scripts'.
http://thorsten-hoeppner.de/download/EasySetup.zip

The correct files you find:
http://thorsten-hoeppner.de/download/Ea ... nstall.exe
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

I have installed your files.
My test program (compressing some files with zero length in your zip) :

Code: Select all

If PureZIP_Archive_Create("c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP", #APPEND_STATUS_CREATE)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\License.rtf", #False)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\CallURL.exe", #False)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\CheckPC.exe", #False)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\DemoVersion.exe", #False)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\PlayMusic.exe", #False)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\ShowHTML.exe", #False)
  PureZIP_Archive_Close()
EndIf

If PureZIP_Archive_Create("c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP", #APPEND_STATUS_CREATE)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\License.rtf", #True)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\CallURL.exe", #True)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\CheckPC.exe", #True)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\DemoVersion.exe", #True)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\PlayMusic.exe", #True)
  Debug PureZIP_Archive_Compress("c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\ShowHTML.exe", #True)
  PureZIP_Archive_Close()
EndIf
TEST1.ZIP

Code: Select all

c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP\CallURL.exe	6 656	11/11/2006 00:45	----
c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP\CheckPC.exe	6 656	11/11/2006 00:46	----
c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP\DemoVersion.exe	7 168	11/11/2006 16:32	----
c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP\License.rtf	1 319	13/11/2006 17:10	----
c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP\PlayMusic.exe	10 752	11/11/2006 00:46	----
c:\PureBasic400\Program\PureZIP-Problem\TEST1.ZIP\ShowHTML.exe	12 800	11/11/2006 00:46	----
TEST2.ZIP

Code: Select all

c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP\c:\PureBasic400\Program\PureZIP-Problem\EasySetup\License.rtf	1 319	13/11/2006 17:10	----
c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP\c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\CallURL.exe	6 656	11/11/2006 00:45	----
c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP\c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\CheckPC.exe	6 656	11/11/2006 00:46	----
c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP\c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\DemoVersion.exe	7 168	11/11/2006 16:32	----
c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP\c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\PlayMusic.exe	10 752	11/11/2006 00:46	----
c:\PureBasic400\Program\PureZIP-Problem\TEST2.ZIP\c:\PureBasic400\Program\PureZIP-Problem\EasySetup\InstProgs\ShowHTML.exe	12 800	11/11/2006 00:46	----
No problem here !
Using PB4.02 (and all beta libs) + PureZIP 1.70
Maybe you could post the code you are using ?


EDIT : Install.exe and Uninstall.exe are crashing at exit under WinNT4.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

Code: Select all

Procedure Add2ZIP(Path.s, SrcPart.s, exclude.s)
  Protected dir.l, entry.s, copy.b, exts.b
  If Not Right(Path, 1) = "\" : Path+"\" : EndIf
  If Not Right(SrcPart, 1) = "\" : SrcPart+"\" : EndIf 
  exts =  CountString(exclude,"|")
  dir = ExamineDirectory(#PB_Any, Path, "")
  If dir 
    While NextDirectoryEntry(dir) 
      entry = DirectoryEntryName(dir)  
      If entry = "." Or entry = ".."
        Continue
      ElseIf DirectoryEntryType(dir) = #PB_DirectoryEntry_File
        If exclude ;{ don't write files with extension
          copy = #True
          For i = 1 To exts
            If GetExtensionPart(entry) = StringField(exclude,i,"|")
              copy = #False
              Break
            EndIf
          Next
        EndIf ;}
        If copy
          PureZIP_Archive_Compress(RemoveString(Path+entry, SrcPart), #True)
          Debug "ZIP: "+RemoveString(Path+entry, SrcPart)+" ("+Str(FileSize(Path+entry))+")"
        EndIf
      Else
        Add2ZIP(Path+entry+"\", SrcPart, exclude)
      EndIf 
    Wend 
    FinishDirectory(dir) 
  EndIf 
EndProcedure

nocopy$="ini|cfg|"
If PureZIP_Archive_Create(PackDatei$, #APPEND_STATUS_CREATE)
  Add2ZIP(SourceDir$, SourceDir$, nocopy$)
  PureZIP_Archive_Close()
EndIf
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

No problem with PureZIP !

There is a bug in your code. If you use a path relative to a base directory, you need to set the base directory with SetCurrentDirectory_().
So it works :

Code: Select all

Procedure Add2ZIP(Path.s, SrcPart.s, exclude.s) 
  Protected dir.l, entry.s, copy.b, exts.b 
  If Not Right(Path, 1) = "\" : Path+"\" : EndIf 
  If Not Right(SrcPart, 1) = "\" : SrcPart+"\" : EndIf 
  exts =  CountString(exclude,"|") 
  dir = ExamineDirectory(#PB_Any, Path, "") 
  If dir 
    While NextDirectoryEntry(dir) 
      entry = DirectoryEntryName(dir)  
      If entry = "." Or entry = ".." 
        Continue 
      ElseIf DirectoryEntryType(dir) = #PB_DirectoryEntry_File 
        If exclude ;{ don't write files with extension 
          copy = #True 
          For i = 1 To exts 
            If GetExtensionPart(entry) = StringField(exclude,i,"|") 
              copy = #False 
              Break 
            EndIf 
          Next 
        EndIf ;} 
        If copy 
          PureZIP_Archive_Compress(RemoveString(Path+entry, SrcPart), #True) 
          Debug "ZIP: "+RemoveString(Path+entry, SrcPart)+" ("+Str(FileSize(Path+entry))+")" 
        EndIf 
      Else 
        Add2ZIP(Path+entry+"\", SrcPart, exclude) 
      EndIf 
    Wend 
    FinishDirectory(dir) 
  EndIf 
EndProcedure 

nocopy$="ini|cfg|" 

PackDatei$ = "c:\PureBasic400\Program\PureZIP-Problem\TEST3.ZIP"
SourceDir$ = "c:\PureBasic400\Program\PureZIP-Problem\EasySetup\"
; /////////// SET BASE DIRECTORY ////////////////
SetCurrentDirectory_(@SourceDir$)
; ///////////////////////////////////////////////
If PureZIP_Archive_Create(PackDatei$, #APPEND_STATUS_CREATE) 
  Add2ZIP(SourceDir$, SourceDir$, nocopy$) 
  PureZIP_Archive_Close() 
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply