Russian language [resolved]

Apr 24, 2012 at 8:48 AM

Hello!

I has been resolved a problem with russians filenames and comments in Zip-archives under OS Windows.  Let's see:

      private void ZipAdd(string archName, bool update = false)
        {
            try
            {
                if (!update)
                {
                    using (ZipFile zip = new ZipFile(archName, Encoding.GetEncoding("cp866")))
                    {
                        zip.AddDirectory(textBoxSrcDir.Text);
                        zip.AlternateEncoding = Encoding.Default;
                        zip.Comment = textBoxArchComments.Text;
                        zip.Save();
                    }
                    AppUpdateStatus("Creating " + archName + " succsessful", Color.DarkGreen);
                }
                else
                {
                    using (ZipFile zip = ZipFile.Read(archName, new ReadOptions { Encoding = Encoding.GetEncoding("cp866")}))
                    {
                        zip.UpdateDirectory(textBoxSrcDir.Text);
                        zip.AlternateEncoding = Encoding.Default;
                        zip.Comment = textBoxArchComments.Text;
                        zip.Save();
                    }
                    AppUpdateStatus("Updating " + archName + " succsessful", Color.DarkGreen);
                }
            }

            catch (Exception exc)
            {
                AppUpdateStatus(exc.Message, Color.Red);
            }
        }

        private void ZipGetComment(string archName)
        {
            try
            {
                    using (ZipFile zip = ZipFile.Read(archName, new ReadOptions{Encoding = Encoding.Default}))
                    {

                        textBoxArchComments.Text = zip.Comment;
                    }
                    AppUpdateStatus("Reading " + archName + " succsessful", Color.DarkGreen);
            }
            catch (Exception exc)
            {
                AppUpdateStatus(exc.Message, Color.Red);
            }
        }

        private void ZipExt(string archName)
        {
            try
            {
                using (ZipFile zip = ZipFile.Read(archName, new ReadOptions { Encoding = Encoding.GetEncoding("cp866") }))
                {
                    foreach (ZipEntry e in zip)
                    {
                        e.Extract(textBoxSrcDir.Text, ExtractExistingFileAction.OverwriteSilently);
                    }
                    AppUpdateStatus("Rollback from " + archName + " succsessful", Color.DarkGreen);
                }
            }
            catch (Exception exc)
            {
                AppUpdateStatus(exc.Message, Color.Red);
            }
        }

 

So, you must use different encodings for filenames (cp866) and archive comment (default) for perfect result. I hope this helps other developers. Thanks.