[
  {
    "Id": "827723",
    "ThreadId": "353330",
    "Html": "\r\n<p>Hello!</p>\r\n<p>I has been resolved a problem with russians filenames and comments in Zip-archives under OS Windows.&nbsp; Let's see:</p>\r\n<div style=\"color:black; background-color:white\">\r\n<pre>      <span style=\"color:blue\">private</span> <span style=\"color:blue\">void</span> ZipAdd(<span style=\"color:blue\">string</span> archName, <span style=\"color:blue\">bool</span> update = <span style=\"color:blue\">false</span>)\r\n        {\r\n            <span style=\"color:blue\">try</span>\r\n            {\r\n                <span style=\"color:blue\">if</span> (!update)\r\n                {\r\n                    <span style=\"color:blue\">using</span> (ZipFile zip = <span style=\"color:blue\">new</span> ZipFile(archName, Encoding.GetEncoding(<span style=\"color:#a31515\">&quot;cp866&quot;</span>)))\r\n                    {\r\n                        zip.AddDirectory(textBoxSrcDir.Text);\r\n                        zip.AlternateEncoding = Encoding.Default;\r\n                        zip.Comment = textBoxArchComments.Text;\r\n                        zip.Save();\r\n                    }\r\n                    AppUpdateStatus(<span style=\"color:#a31515\">&quot;Creating &quot;</span> &#43; archName &#43; <span style=\"color:#a31515\">&quot; succsessful&quot;</span>, Color.DarkGreen);\r\n                }\r\n                <span style=\"color:blue\">else</span>\r\n                {\r\n                    <span style=\"color:blue\">using</span> (ZipFile zip = ZipFile.Read(archName, <span style=\"color:blue\">new</span> ReadOptions { Encoding = Encoding.GetEncoding(<span style=\"color:#a31515\">&quot;cp866&quot;</span>)}))\r\n                    {\r\n                        zip.UpdateDirectory(textBoxSrcDir.Text);\r\n                        zip.AlternateEncoding = Encoding.Default;\r\n                        zip.Comment = textBoxArchComments.Text;\r\n                        zip.Save();\r\n                    }\r\n                    AppUpdateStatus(<span style=\"color:#a31515\">&quot;Updating &quot;</span> &#43; archName &#43; <span style=\"color:#a31515\">&quot; succsessful&quot;</span>, Color.DarkGreen);\r\n                }\r\n            }\r\n\r\n            <span style=\"color:blue\">catch</span> (Exception exc)\r\n            {\r\n                AppUpdateStatus(exc.Message, Color.Red);\r\n            }\r\n        }\r\n\r\n        <span style=\"color:blue\">private</span> <span style=\"color:blue\">void</span> ZipGetComment(<span style=\"color:blue\">string</span> archName)\r\n        {\r\n            <span style=\"color:blue\">try</span>\r\n            {\r\n                    <span style=\"color:blue\">using</span> (ZipFile zip = ZipFile.Read(archName, <span style=\"color:blue\">new</span> ReadOptions{Encoding = Encoding.Default}))\r\n                    {\r\n\r\n                        textBoxArchComments.Text = zip.Comment;\r\n                    }\r\n                    AppUpdateStatus(<span style=\"color:#a31515\">&quot;Reading &quot;</span> &#43; archName &#43; <span style=\"color:#a31515\">&quot; succsessful&quot;</span>, Color.DarkGreen);\r\n            }\r\n            <span style=\"color:blue\">catch</span> (Exception exc)\r\n            {\r\n                AppUpdateStatus(exc.Message, Color.Red);\r\n            }\r\n        }\r\n\r\n        <span style=\"color:blue\">private</span> <span style=\"color:blue\">void</span> ZipExt(<span style=\"color:blue\">string</span> archName)\r\n        {\r\n            <span style=\"color:blue\">try</span>\r\n            {\r\n                <span style=\"color:blue\">using</span> (ZipFile zip = ZipFile.Read(archName, <span style=\"color:blue\">new</span> ReadOptions { Encoding = Encoding.GetEncoding(<span style=\"color:#a31515\">&quot;cp866&quot;</span>) }))\r\n                {\r\n                    <span style=\"color:blue\">foreach</span> (ZipEntry e <span style=\"color:blue\">in</span> zip)\r\n                    {\r\n                        e.Extract(textBoxSrcDir.Text, ExtractExistingFileAction.OverwriteSilently);\r\n                    }\r\n                    AppUpdateStatus(<span style=\"color:#a31515\">&quot;Rollback from &quot;</span> &#43; archName &#43; <span style=\"color:#a31515\">&quot; succsessful&quot;</span>, Color.DarkGreen);\r\n                }\r\n            }\r\n            <span style=\"color:blue\">catch</span> (Exception exc)\r\n            {\r\n                AppUpdateStatus(exc.Message, Color.Red);\r\n            }\r\n        }\r\n</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>So, you must use <span style=\"text-decoration:underline\">different</span> encodings for filenames (cp866) and archive comment (default) for perfect result.\r\n<span>I hope</span> <span>this helps</span> <span>other developers. Thanks.</span></p>\r\n<div id=\"_mcePaste\" style=\"width:1px; height:1px; overflow:hidden; top:0px; left:-10000px\">\r\n&#65279;</div>\r\n",
    "PostedDate": "2012-04-24T00:48:21.077-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]