Updating a file creates duplicate entries?

Jun 3, 2010 at 11:30 PM

I have been trying to get this to work for some time now. I just upgraded to the newest version 1.9.5.2 to try to fix my error, but it is still not working. I am using Visual Basic in Visual Studio 2010.

What I'm doing is updating a file in a large zip archive. Then I am extracting the whole archive and doing a few other things. I use this code to update the file within the archive.

 Try
    Dim output = (directory.ToString() & "\HeroPak_client.zip")
    Using zip As ZipFile = ZipFile.Read(output)
        zip.UpdateFile(My.Computer.FileSystem.CurrentDirectory & "\" & character_names_list.Text.ToString() & ".inibin", "\DATA\Characters\" & character_names_list.Text.ToString() & "\")
        zip.Save()
    End Using
Catch ex As Exception
    MessageBox.Show(ex.ToString)
End Try

Then I run this code after that has finished.

Try
    Dim ZipToUnpack As String = (directory & "\HeroPak_client.zip")
    Dim UnpackDirectory As String = (My.Computer.FileSystem.SpecialDirectories.Desktop & "\test\")
    Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
        zip1.ExtractAll(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test")
    End Using
Catch ex As Exception
    MessageBox.Show(ex.ToString)
End Try

While trying to do the extracting (second code) I get an error at the line that starts with Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack). This is the error.

System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Ionic.Zip.ZipFile.ReadCentralDirectory(ZipFile zf)
   at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
   at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)
   at Ionic.Zip.ZipFile.Read(String fileName)
   at LoL_Item_Changer.main.Button1_Click(Object sender, EventArgs e) in C:\Users\USER\Documents\Visual Studio 2010\Projects\PROGRAM\PROGRAM\main.vb:line 459 

Am I doing something wrong with updating the file, or is there some kind of bug here. Any help is appreciated. Thanks in advance!

Coordinator
Jun 3, 2010 at 11:54 PM

it sure seems like a bug to me. 

can you provide a test case that reproduces the problem repeatedly?  If so,  I'll be able to fix it quickly.

 

Jun 4, 2010 at 12:20 AM
Edited Jun 4, 2010 at 6:29 AM

I just wrote a quick test program and I am having the same issues. Here is a link to the test app i made. If you go to the debug folder and run the test app.exe it should give the error.

First update the zip file then extract the contents. An error is given.

Here is the link to the zip download with the application and source code in it.

Coordinator
Jun 4, 2010 at 6:17 AM

Ah, I don't want your app.

I just want 20 lines of code that will reproduce the problem.  If it's as simple as you say, then you should be able to give me the code that causes it, right?

A simple console application.  Or just one method, if you like, that does whatever it needs to do, to cause the problem.

 

 

Jun 4, 2010 at 6:29 AM

I've been testing it out some more and found that the problem seems to lie in my zip file. My code works with other files fine. Any suggestions on how to fix the zip file, or how to see whats wrong with it?

Coordinator
Jun 4, 2010 at 9:05 AM

well you could try the ZIpInputStream - it does not build a list of entries, so you might avoid the problem entirely.   you could unzip/extract each file in turn then examine the contents.

There is a checkzip method on the ZipFile - see the documentation for info.  It may help.

There is a -t (tesT) and -r (repair) option on the command-line unzip.exe tool that ships with DotNetZip. Those may help.

good luck.

 

Jun 4, 2010 at 9:31 AM

Thanks, I will try those out. Thanks for the help. Great work on it too. :)