Page 2 of 3
Re: Unpacking .7z *with* subdirectories
Posted: Sun Jun 19, 2022 7:21 am
by Bisonte
In my case I use this routine with ZIP but it should work with 7z...
Code: Select all
Procedure.i CreateDirectoryEx(DirectoryName.s, FileAttribute = #PB_Default)
Protected i, c, tmp.s
If Right(DirectoryName, 1) = #PS$
DirectoryName = Left(DirectoryName, Len(DirectoryName) -1)
EndIf
c = CountString(DirectoryName, #PS$) + 1
For i = 1 To c
tmp + StringField(DirectoryName, i, #PS$)
If FileSize(tmp) <> -2
CreateDirectory(tmp)
EndIf
tmp + #PS$
Next
If FileAttribute <> #PB_Default
SetFileAttributes_(DirectoryName, FileAttribute)
EndIf
If FileSize(DirectoryName) = -2
ProcedureReturn #True
EndIf
EndProcedure
UseLZMAPacker()
Define ID, DestinationPath.s, Archive.s, File.s
Archive = "pathandfile.7z"
DestinationPath = "PathTo"
ID = OpenPack(#PB_Any, Archive, #PB_PackerPlugin_Lzma)
If ID
If ExaminePack(ID)
While NextPackEntry(ID)
File = DestinationPath + PackEntryName(ID)
CreateDirectoryEx(GetPathPart(File))
UncompressPackFile(ID, File)
Wend
EndIf
ClosePack(ID)
EndIf
Re: Unpacking .7z *with* subdirectories
Posted: Sun Jun 19, 2022 4:23 pm
by Marc56us
The is a new version of
7-zip (v22.00) since 2022-06-15 with bugfix.
https://www.7-zip.org/history.txt
Maybe update in the next beta? (PB6B10 is 2022/06/09)
Re: Unpacking .7z *with* subdirectories
Posted: Sun Jun 19, 2022 9:52 pm
by StarWarsFan
NextPackEntry(ID) is the problem. It gives NULL = FALSE in the described circumstances
Re: Unpacking .7z *with* subdirectories
Posted: Thu Jun 23, 2022 6:09 am
by StarWarsFan
@Bisonte: Nice code, thank you.
BUT: Same issue there.
This happens when the archive includes at least one empty subdirectory:
Both OpenPack() and ExaminePack() return #TRUE, so up to there it is good, but: NextPackEntry() returns 0!
Result: So the loop is not started at all. Nothing *at all* is unpacked.
So the more I look at this I clearly see this is not an issue of 7zip.
There is a problem with how PureBasic's NextPackEntry() handles the contents of the archive.
There are apparently yet more circumstances where NextPackEntry() returns 0.
(yet to be investigated)
I have just found another 7z archive (without any subdirs) that cannot be unpacked either.
How to reproduce this bug:
STEP 1
Create a new 7z archive and put 1 textfile with some short text in
Result: Unpacks fine.
STEP 2
Now create an empty subdirectory and add that to the 7z-archive that you have just successfully unpacked.
Result: Nothing is unpacked suddenly. Nothing AT ALL, so not even the file that was just successfully unpacked in step 1
Re: Unpacking .7z *with* subdirectories
Posted: Thu Jun 23, 2022 9:04 am
by BarryG
(Post and code deleted because it doesn't work with ChrisR's "test.7z" archive below).
Re: Unpacking .7z *with* subdirectories
Posted: Thu Jun 23, 2022 9:24 am
by Marc56us
With me, full or empty folder, created before or after; it works without problem.
(Windows 10 x64, 7Zip 22.00 x64 (or via Total Commander 10.00))
It may (maybe) depend on how you created the archive? Normal or
solid archive?
A solid archive is not organized in the same way as soon as you modify it. It may not be read in the same way.
"
New versions of 7-Zip (starting from version 15.06) use another file sorting order by default for solid 7z archives."
https://www.7-zip.org/faq.html
Re: Unpacking .7z *with* subdirectories
Posted: Thu Jun 23, 2022 12:12 pm
by ChrisR
I did not reproduce with the 2 steps written above
But I've reproduced the error on NextPackEntry() with just 2 files, one Ansi and the other Utf8 with Bom.
I put the archive here for testing:
test.7z (1ko)
Tested with Marc's code:
Code: Select all
; Uncompress archive With sud dir creation
; Marc56us 2022-01-18
File7z.s = "E:\Temp\test\test.7z"
SetCurrentDirectory(GetPathPart(File7z))
UseLZMAPacker()
If OpenPack(0,file7z)
If 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
EndIf
ClosePack(0)
Re: Unpacking and packing .7Z ---> see newest message
Posted: Sat Jun 25, 2022 11:45 am
by StarWarsFan
Many thanks again, Marc, you yourself have posted the following on page one of this topic, I quote because I find this to be true:
Marc56us wrote: Tue Jan 18, 2022 4:48 pm
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.
So there
are archives that can be unpacked using what we are discussing here and there are obviously archives that cannot be unpacked this way.
The discussion how I create the archive is irrelevant, that would be leading into the wrong direction, because I can not know nor influence on how OTHER users create their archive ---> The aim of this discussion is solely to find a way to unpack ANY 7z-archive, no matter how it is created or where it comes from.
Obviously some archives collide with the way NextPackEntry() is conducted. => on some archives it returns #false (0) here and the loop is not executed. What causes this I would like to understand so I can find a way that works with ANY 7z archive
Hope I am clearer now. Apologies, English is not my first language, I am really giving my best, guys!
Re: Unpacking .7z *with* subdirectories
Posted: Sat Jun 25, 2022 4:57 pm
by tester
StarWarsFan wrote: Sat Jun 25, 2022 11:45 am...Obviously some archives collide with the way NextPackEntry() is conducted. => on some archives it returns #false (0) here and the loop is not executed...
Can you provide a sample of such an "incorrect" archive?
Re: Unpacking .7z *with* subdirectories
Posted: Sun Jun 26, 2022 8:43 pm
by ChrisR
tester wrote: Sat Jun 25, 2022 4:57 pm
Can you provide a sample of such an "incorrect" archive?
I uploaded an example 3 post above.
Not an incorrect 7z archive, but an example to reproduce the bug on NextPackEntry()
Re: Unpacking .7z *with* subdirectories
Posted: Fri Jul 08, 2022 8:43 am
by StarWarsFan
Right, Chris.
I also ask myself if this is a bug in PureBasic v5.71 (the version I am still using)
Chris, which version have you used to reproduce that bug?
Re: Unpacking .7z *with* subdirectories
Posted: Sat Jul 09, 2022 7:47 am
by Jeromyal
I have noticed that files without an extension causes the loop to fail as well.
So empty folders, and files with no extensions, as well as files with zero size?
Am I right?
Re: Unpacking .7z *with* subdirectories
Posted: Sun Jul 10, 2022 8:35 am
by BarryG
@StarWarsFan: What about using Kenmo's 7zip module? ->
https://github.com/kenmo-pb/includes
Re: Unpacking .7z *with* subdirectories
Posted: Sat Jul 16, 2022 6:23 am
by StarWarsFan
@Barry: Nothing against that. Did not know it existed. But I thought we would have a short and working version after I created this thread and everybody came and said it works.
Jeromyal wrote: Sat Jul 09, 2022 7:47 am
I have noticed that files without an extension causes the loop to fail as well.
So empty folders, and files with no extensions, as well as files with zero size?
Am I right?
Yes, Jeromy, looks like it.
And definitely: It is not the issue how you create that archive or any like that. It is a bug in NextPackEntry() that creates this problem we discuss here. NextPackEntry() simply does not handle the above listed situations right and exits with #FALSE as if there were no entries left at all to be worked on.
Is this reported as a bug yet?
Re: Unpacking .7z *with* subdirectories - BUG in NextPackEntry()
Posted: Mon Jul 18, 2022 6:21 pm
by puchna8