Page 1 of 3

Unpacking .7z *with* subdirectories - BUG in NextPackEntry()

Posted: Wed May 20, 2020 8:50 pm
by StarWarsFan
Hello friends,

I have read somewhere in the German area of this forum, that PB has native support for UNPACKING .7z files from V5.10
Unfortunately in that thread all links are dead, that is why I could not download it.

In the documentation for "OpenPack()" I was neither able to locate support for .7z
Other threads mention that a Use7zip() command would come (or similar), but I can not find acccurate any current info

Can somebody please shed some CURRENT news-light on this? Much appreciated!

Re: Unpacking and packing .7Z

Posted: Wed May 20, 2020 9:16 pm
by helpy
Have a look at PureBasic help:
History in PureBasic help wrote:16th October 2015 : Version 5.40 LTS
- Added: 7z archive creation
- Removed: #PB_Packer_CompressedSize support for ZIP and 7z archives with PackerEntrySize()

14th February 2013 : Version 5.10
- Added: Fully reworked Packer library with ZIP, BriefLZ, 7z (unpacker only), LZMA and JCALG1 (Windows x86 and UncompressMemory() only) support. JCALG1 support has been dropped. Archives formats for BriefLZ have been changed.
PureBasic help: CreatePack() wrote:Parameter "Plugin" for CreatePack() command:

#PB_PackerPlugin_Lzma : use the Lzma packer to create the pack file (also known as 7z archive). UseLZMAPacker() has to be called to register the plugin.
PureBasic help: UseLZMAPacker() wrote:Syntax
    UseLZMAPacker()

Description
Enable LZMA compress, uncompress and 7z archive support to the packer library. LZMA compression is considered as one of the best available multipurpose compression algorithm. It provides very good compress ratio and fast uncompress. Compressing can be slow.
I think "UseLZMAPacker()" is your friend ;-)

Re: Unpacking and packing .7Z

Posted: Mon Jun 01, 2020 10:40 am
by StarWarsFan
Ah! Nice!

Many thanks to you!

Re: Unpacking and packing .7Z

Posted: Wed Jun 03, 2020 12:33 pm
by StarWarsFan
Can somebody from the admins please mark this thread [SOLVED] ?

Re: Unpacking and packing .7Z

Posted: Wed Jun 03, 2020 12:52 pm
by Derren
You can edit your first post's title on your own.

Re: Unpacking and packing .7Z

Posted: Thu Jun 04, 2020 11:43 am
by StarWarsFan
Ah! Okay, done!

And thanks!

Re: Unpacking and packing .7Z

Posted: Mon Jan 17, 2022 5:14 pm
by StarWarsFan
Okay, I got one more question. Unpacking works so far, beside subdirectories, those are not created, those are apparently ignored.

What am I doing wrong?

My short code:

Code: Select all

UseLZMAPacker()
If OpenPack(0,"file.7z") And ExaminePack(0)
  While NextPackEntry(0) : 
    UncompressPackFile(0,path$+ReplaceString(PackEntryName(0),"/","\"))
  Wend
EndIf
ClosePack(0)

Re: Unpacking and packing .7Z ---> see newest message

Posted: Tue Jan 18, 2022 12:00 pm
by Marc56us
Unpacking works so far, beside subdirectories, those are not created, those are apparently ignored.
Yes and No,
UncompressPackFile() can use sub directory if exists, but can't create it if not exists.
So you need to create a recurisve function for create each directory. (split full name in archive)
Use something like If PackEntryType(hPack) = #PB_Packer_Directory ... CreateDirectory ...
There are samples in this forum. I don't know what is the best code.
:wink:

Re: Unpacking and packing .7Z ---> see newest message

Posted: Tue Jan 18, 2022 4:48 pm
by Marc56us
To my great surprise, this seems to work (?)
(Without recursive function). The directories are created as you go along.

Code: Select all

; Uncompress archive With sud dir creation
; Marc56us 2022-01-18
UseLZMAPacker()
If OpenPack(0,"file.7z") And ExaminePack(0)
    While NextPackEntry(0) 
        Debug PackEntryName(0)
        If PackEntryType(0) = #PB_Packer_Directory
            CreateDirectory(PackEntryName(0))
        Else
            UncompressPackFile(0, "" + PackEntryName(0), PackEntryName(0))
        EndIf
    Wend
EndIf
ClosePack(0)
This may be a special case of some archives ?
It's too simple, I must have forgotten something ?
Tested with a zip archive and a 7z archive (replacing only the Use... call)

Edit: Yes, this works with many archives (Almost all the ones I tried). I'm trying to identify which features have the ones that don't work.
All the ones I created (zip or 7z) with TC or 7zip and most of the others also decompress without problem with this simple code.
I will look for the difference with the others.

Re: Unpacking and packing .7Z ---> see newest message

Posted: Tue Jan 18, 2022 10:38 pm
by StarWarsFan
Ha! My code looks almost exactly the same and as long as I unpack to the current working directory things seem to work:

Code: Select all

UseLZMAPacker()
OpenPack(0,"file.7z") : ExaminePack(0)
While NextPackEntry(0) : Debug PackEntryName(0)
  If PackEntryType(0)= #PB_Packer_Directory : CreateDirectory(PackEntryName(0))
  Else                                      : UncompressPackFile(0,PackEntryName(0),PackEntryName(0))
  EndIf
Wend
ClosePack(0)
But as soon as I want to unpack to a different destination path, things get out of order...

Re: Unpacking and packing .7Z ---> see newest message

Posted: Wed Jan 19, 2022 7:02 am
by Marc56us
StarWarsFan wrote: Tue Jan 18, 2022 10:38 pm Ha! My code looks almost exactly the same and as long as I unpack to the current working directory things seem to work:
...
But as soon as I want to unpack to a different destination path, things get out of order...
Hi StarWarsFan,

Yes, same for me and I don't understand too why the destination doesn't support a full path.
In the meantime I solved by putting a temporary SetCurrendDirectoy() to the destination folder.
I'm still looking for that and still why some archives don't work.

:wink:

Re: Unpacking .7z *with* subdirectories

Posted: Wed Jan 19, 2022 10:59 am
by StarWarsFan
No toy, it's a directory :)

SetCurrentDirectory()

Re: Unpacking .7z *with* subdirectories

Posted: Sat Jun 18, 2022 1:28 pm
by StarWarsFan
Returning to this, bringing some update.

I seem to have found why some 7z-archives work and some do not.
What I have encountered is that if a 7z-archive has got a subdirectory as its VERY FIRST ENTRY,
it will not work, that entry is NOT recognized by "While NextPackEntry(0)" and consequently the loop is not even executed.

The code that I am using right now is:

Code: Select all

UseLZMAPacker()
If OpenPack(0,"pathandfile.7z") And ExaminePack(0)
    While NextPackEntry(0) 
        Debug PackEntryName(0)
        If PackEntryType(0) = #PB_Packer_Directory
            CreateDirectory(PackEntryName(0))
        Else
            UncompressPackFile(0, "" + PackEntryName(0), PackEntryName(0))
        EndIf
    Wend
EndIf
ClosePack(0)
Any ideas to circumvent this problem?
Is there a fix that I have probably overlooked?
Or what am I doing wrong?

Re: Unpacking .7z *with* subdirectories

Posted: Sat Jun 18, 2022 9:38 pm
by StarWarsFan
Confused.

The more I look at this the less I understand. I have now run two tests.
1)
I created a fresh test archive with some files but NO subdirectories.
Result: The above routine (I use Marc's as mentioned earlier) unpacks the files. No errors

2)
I now took THAT archive and added two subdirectories to that archive.
one of them is empty, one of them has files in it.
Result: Nothing at all is unpacked. NextPackEntry(0) returns 0, so the loop is not started at all.

When I remove those two subfolders from that archive it works again as explained in (1)

How can I get this done? Anybody? Any help?

Re: Unpacking .7z *with* subdirectories

Posted: Sat Jun 18, 2022 9:45 pm
by StarWarsFan
Really weird!