|
The last 3 lines of the TUnzip::Open() function (in XUnzip.cpp) are:
uf = unzOpenInternal(f);
return ZR_OK;
}
The unzOpenInternal() function opens the specified ZIP file checks it's validity; as written, it returns a NULL value of there is a problem with the ZIP file:
if (err!=UNZ_OK) {lufclose(fin);return NULL;}
However, the Open() function ignores this return value and returns "all ok" regardless. If you attempt to open a file that is *not* a valid ZIP file, this creates a big problem if one uses the documented OpenZip() function (in the Code Project article:
HZIP hz = OpenZip(z,len,flags); //non-zero if zip archive opened ok, otherwise 0
if (hz) { <some code=""> }
To correct this problem I modified XUnzip.cpp as follows:
#pragma warning(disable : 4702) //(reference line to locate new code below)
ZRESULT zopenerror = ZR_OK; // NEW code
unzFile unzOpenInternal(LUFILE *fin) //(reference line to locate new code below)
{
zopenerror = ZR_OK; //NEW code
.
.
.
// if (err!=UNZ_OK) {lufclose(fin);return NULL;} //OLD code
if (err!=UNZ_OK) {lufclose(fin); zopenerror = err; return NULL;} //NEW code
.
.
.
}
ZRESULT TUnzip::Open(void *z,unsigned int len,DWORD flags) //(reference line to locate new code below)
{
.
.
.
// return ZR_OK; //OLD code
return zopenerror; //NEW code
}
I hope this is useful.
I've only had this a couple of days, and this is the only problem I've found. Otherwise it's great.
|
|
|
|
|
Is there a way to protect the archive by password during creation or later ?
Thanks a lot for reply.
|
|
|
|
|
Thanks a lot, your code was very helpful to me, although a simple wrapper-class would have been even nicer.
PS: "Look at the size of that thing!"
|
|
|
|
|
Is there/will be there any Progress Bar Support ?
|
|
|
|
|
Anyone fancy converting this into a .NET class library / assembly?
Don't worry, nobody lives forever.
|
|
|
|
|
|
I want a progress show during compression, how can I do? May be some function I don't know? Can I solve this question with "Createpipe",but how to do?
maybe someone tell me?
Thanks a lot in advance!
|
|
|
|
|
I really like this application/xzip/xunzip but I think it does not work on Linux. Is there a similar program that does work on linux???
|
|
|
|
|
I know the GUI wont but will the Zip and Unzip functionality work in linux as only a console app? I will try this out tomorrow but if it doesnt I will stop.
Why cant people get along with penguins
|
|
|
|
|
Seems that I'm too stupid to figure it out myself...
How do I set the desired compression level?
Please help, it's kinda urgent...
|
|
|
|
|
The compression level (or ratio) is determined by the configuration_table, which you can see at line 365 of XZip.cpp:
const config configuration_table[10] = {
{0, 0, 0, 0},
{4, 4, 8, 4},
{4, 5, 16, 8},
{4, 6, 32, 32},
{4, 4, 16, 16},
{8, 16, 32, 32},
{8, 16, 128, 128},
{8, 32, 128, 256},
{32, 128, 258, 1024},
{32, 258, 258, 4096}};
There is some explanation of the four values at line 563:
unsigned max_chain_length;
unsigned int max_lazy_match;
unsigned good_match;
int nice_match;
At line 1533 you will find the function lm_init() :
void lm_init (TState &state, int pack_level, ush *flags)
and at line 1556 in lm_init() :
state.ds.max_lazy_match = configuration_table[pack_level].max_lazy;
state.ds.good_match = configuration_table[pack_level].good_length;
state.ds.nice_match = configuration_table[pack_level].nice_length;
state.ds.max_chain_length = configuration_table[pack_level].max_chain;
So your question is answered by finding what the value of pack_level is. At line 2551, we see that lm_init() gets called:
lm_init(state,state.level, &zfi->flg);
and previously state is set up at line 2542:
state.param=this; state.level=8; state.seekable=iseekable; state.err=NULL;
So the answer seems to be 8, the next-to-highest compression level. (There is no external way to change the value of 8, so you will have to implement your own function if you want to do this.) The code does not seem to want to accept level 9, since at line 1537 we see:
Assert(state,pack_level>=1 && pack_level<=8,"bad pack level");
If you do change the compression level, I strongly urge you to test it thoroughly. I have not done much testing in this area myself.
Best wishes,
Hans
|
|
|
|
|
Hey, great, I found the configuration_table myself, but I didn't expect that such an important value would be buried that deep in the code...
Be sure that it gets tested.... alot...
Thanks for your help...
So long
Tom
|
|
|
|
|
Great code.
Perhaps I've missed something but it appears that there is no way to add files to an existing zip, or is there? If not, that would be a great addition.
|
|
|
|
|
HI,
did you solve this problem? I am unable to do it, please let us know if you have succeeded in doing so.
Thanks in advance.
|
|
|
|
|
Hello!
It looks like you know what you are doing, so I want to ask you if you have any clue about how to create a program that compress and compound some files into one single .exe file like a single .exe file setup application?
/ Deeply impressed!
|
|
|
|
|
I have not tried this, but here is something: http://www.codeproject.com/file/self_extractor.asp
Best wishes,
Hans
|
|
|
|
|
That's easy, just store the size of the exe, add the compressed files to the end of the exe and as the last long write the start of the data.
|
|
|
|
|
Deeply,
You are asking about creating SelF-eXtracting executables (SFX). I have used this open-source MakeSFX program with great success. There is a GUI version and a command-line version. It shouldn't be hard to integrate the code into one's project.
|
|
|
|
|
Thank you guys!
That two links gave me what i wanted!
Big thanks!!!
|
|
|
|
|
This is great class, but will you implement feature to open password protected archive?
This will be great improvement.
You got my 5.
|
|
|
|
|
Vanja Bojic wrote:
will you implement feature to open password protected archive
Thank you for your interest. This is one of things I would like to do, too.
Best wishes,
Hans
|
|
|
|
|
I'm also impressed
But the current Zip methods for password protection of zip files is quite weak. If you can come up with a better way it would be great.
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
Warning Link to the minion's animation, do not use.
It's a real shame that people as stupid as you can work out how to use a computer. said by Christian Graus in the Soapbox
|
|
|
|
|
Check Winzip 9 - they've improved the password mechanism, thus
breaking the ZIP format.
WinZip 9.0 supports 128- and 256-bit key AES encryption, which provide much greater cryptographic security than the traditional Zip 2.0 encryption method used in earlier versions of WinZip.
Details on this can be found here
http://www.winzip.com/whatsnew90.htm
and here
http://www.winzip.com/aes_info.htm
|
|
|
|
|
Hi Hans,
Maybe a stupid question but why did you save the project with the setting to 'Win32 Unicode Release' in the first place and not with setting to 'Win32 Release'?
Looks like you are introducing problems on purpose for compiler or OS without Unicode
Maybe It is just me ,
Michel Wassink
We must make user friendly software. Where are friendly users?
|
|
|
|
|
Michel Wassink wrote:
Looks like you are introducing problems on purpose for compiler or OS without Unicode
There is no compiler without unicode, neither is there an OS without it.
Michel Wassink wrote:
Maybe It is just me
Definitely
Off to Brazil in a few days
|
|
|
|
|