Unpacking .7z *with* subdirectories - BUG in NextPackEntry()
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Unpacking .7z *with* subdirectories - BUG in NextPackEntry()
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!
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!
Last edited by StarWarsFan on Sat Jul 16, 2022 6:28 am, edited 7 times in total.
Re: Unpacking and packing .7Z
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.
I think "UseLZMAPacker()" is your friendPureBasic 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.
Windows 10 / Windows 7
PB Last Final / Last Beta Testing
PB Last Final / Last Beta Testing
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking and packing .7Z
Ah! Nice!
Many thanks to you!
Many thanks to you!
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking and packing .7Z
Can somebody from the admins please mark this thread [SOLVED] ?
Re: Unpacking and packing .7Z
You can edit your first post's title on your own.
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking and packing .7Z
Ah! Okay, done!
And thanks!
And thanks!
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking and packing .7Z
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:
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
Yes and No,Unpacking works so far, beside subdirectories, those are not created, those are apparently ignored.
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.
Re: Unpacking and packing .7Z ---> see newest message
To my great surprise, this seems to work (?)
(Without recursive function). The directories are created as you go along.
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.
(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)
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.
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking and packing .7Z ---> see newest message
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...
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)
Re: Unpacking and packing .7Z ---> see newest message
Hi StarWarsFan,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...
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.
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking .7z *with* subdirectories
No toy, it's a directory
SetCurrentDirectory()
SetCurrentDirectory()
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking .7z *with* subdirectories
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:
Any ideas to circumvent this problem?
Is there a fix that I have probably overlooked?
Or what am I doing wrong?
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)
Is there a fix that I have probably overlooked?
Or what am I doing wrong?
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking .7z *with* subdirectories
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?
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?
-
- Enthusiast
- Posts: 169
- Joined: Sat Mar 14, 2015 11:53 am
Re: Unpacking .7z *with* subdirectories
Really weird!