UseUnicodeAsNecessary flag not working right?

Dec 8, 2010 at 8:41 PM

I'm attempting to make an encrypted zip file that may need unicode for file entry names in the zip. All the items in my test that I'm trying to compress have English filenames except one file I made that has a mix of Korean characters and ü.

Below is a snippet of the code I'm using the make the zip. I add a bunch of files, then reload the zip and add another file (I have an if above this that checks for the file and creates a new object or calls Read to load an existing one).
zip.Password = password
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
zip.UseUnicodeAsNecessary = true;
zip.AddDirectory(sourceFolder);
zip.Save();

To extract, I'm using the ExtractAll call after loading the zip via Read.

The ExtractAll call is currently failing on the file with the Korean characters with a System.IO.FileStream error "Illegal characters in path". When I output the filenames to the Console, the filename looks like ?box?.dat.

I saw in other posts that I can just force UTF8 and that gets rid of the error, but isn't DotNetZip supposed to autodetect this?

I've posted the zip file created by DotNetZip here. The zip has junk in it and is encrypted and the password is "abc123".

Dec 8, 2010 at 8:49 PM

Oh, not that it's overly important to my problem but the the chars are Chinese/Japanese not Korean.

Dec 8, 2010 at 8:58 PM

I've done a little more digging. The problem seems to happen when I use Read to reload the zip, use the code I gave above to add another folder, and then save the zip. Even though on the second time I again specify the UseUnicodeAsNecessary flag, it seems it gets lost. Is this a known issue? Does a bug need to get logged for this? Am I missing something?

Dec 8, 2010 at 9:08 PM

I found a workaround.

ZipFile zip = ZipFile.Read(path);

// remark the entries to use unicode if needed
foreach(ZipEntry entry in zip)
   entry.UseUnicodeAsNecessary = true;

Personally I would consider this a bug as I would expect at the time of Save() that the ZipFile's flag value would be used for entries that existed from the Read call. A possibly easier way to do this is to have DotNetZip look for filenames/comments that don't fit into IBM437 during Read and autoset the use unicode flag.