开发者

Dotnetzip, Event Handler not Fired after Save

I have a small problem, which might me a stupid mistake on my side.

Here is my code to create a zipfile when needed and the method to add a file to the archive.

Adding a file works without problem but for some reason the Event is not fired after saving.

I set a breakpoint at zipFile_SaveProgress, the event is not fired.


class CoverArchive
{
        private ZipFile zipFile;
        private String coverArchivePath;

        public CoverArchive()
        {        
            coverArchivePath = "Archive\\Covers";

            if (!File.Exists("Archive\\Covers"))
            {
                CreateZipFile();
            }
            using (zipFile = ZipFile.Read(coverArchivePath))
            {
                //zipFile.AddProgress += zipFile_AddProgress;
                //zipFile.ExtractProgress += zipFile_ExtractProgress;
                //zipFile.ZipError += zipFile_ZipError;
                zipFile.SaveProgress += zipFile_SaveProgress;
            }
        }

        private void CreateZipFile()
        {
            zipFile = new ZipFile();
            zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
            zipFile.UseUnicodeAsNecessary = true;
            if (!Directory.Exists("Archive"))
                Directory.CreateDirectory("Archive");
            zipFile.Save(coverArchivePath);
        }

        public void AddCover(List<String> directories, String coverName, Stream fileStream)
        {
            try
            {
                using (zipFile = ZipFile.Read(coverArchivePath))
                {
                    String filePath = createPath(directories, coverName);
                    ZipEntry entry = zipFile.AddEntry(filePath, fileStream);
                    zipFile.Save();
                }
 开发者_StackOverflow中文版           }
            catch (Exception ex)
            {
                Console.WriteLine("Error adding File" + ex);
            }
        }
        private void zipFile_SaveProgress(Object sender, SaveProgressEventArgs e)
        {
            if (e.EventType == ZipProgressEventType.Saving_Completed)
                Console.WriteLine("Save Done");
        }
}

Thanks a lot in advance :)


You're adding the event handling after calling Save().
Therefore, when it raised the SaveProgress event, there weren't any handlers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜