From d1332be8ed5ef9fac109a62e5381b266fb715c67 Mon Sep 17 00:00:00 2001 From: Aviran Cohen Date: Fri, 25 Dec 2015 15:29:13 +0200 Subject: [PATCH 1/3] Bugfix for Unicode file names and directory names, previously created corrupted file/directory names. --- src/Zip/ZipEntryFactory.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Zip/ZipEntryFactory.cs b/src/Zip/ZipEntryFactory.cs index 2affbd97e..b765f258d 100644 --- a/src/Zip/ZipEntryFactory.cs +++ b/src/Zip/ZipEntryFactory.cs @@ -42,6 +42,7 @@ using System.IO; using ICSharpCode.SharpZipLib.Core; +using System.Text; namespace ICSharpCode.SharpZipLib.Zip { @@ -235,7 +236,7 @@ public ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSys ZipEntry result = new ZipEntry(nameTransform_.TransformFile(entryName != null && entryName.Length > 0 ? entryName : fileName)); result.IsUnicodeText = isUnicodeText_; - int externalAttributes = 0; + int externalAttributes = 0; bool useAttributes = (setAttributes_ != 0); FileInfo fi = null; From 512afe858a820c75f4ddd9ced04b47b83e4ba71e Mon Sep 17 00:00:00 2001 From: Aviran Cohen Date: Fri, 25 Dec 2015 15:32:51 +0200 Subject: [PATCH 2/3] Bugfix for Unicode file names and directory names, previously created corrupted file/directory names. --- src/Zip/ZipEntryFactory.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Zip/ZipEntryFactory.cs b/src/Zip/ZipEntryFactory.cs index b765f258d..dc6b38de1 100644 --- a/src/Zip/ZipEntryFactory.cs +++ b/src/Zip/ZipEntryFactory.cs @@ -236,6 +236,15 @@ public ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSys ZipEntry result = new ZipEntry(nameTransform_.TransformFile(entryName != null && entryName.Length > 0 ? entryName : fileName)); result.IsUnicodeText = isUnicodeText_; + Encoding defaultEncoding = Encoding.GetEncoding(ZipConstants.DefaultCodePage); + byte[] unicodeFileNameBytes = defaultEncoding.GetBytes(result.Name); + string unicodeFileName = defaultEncoding.GetString(unicodeFileNameBytes); + if (unicodeFileName != result.Name) + { + result.IsUnicodeText = true; + } + + int externalAttributes = 0; bool useAttributes = (setAttributes_ != 0); From 2517d364ff1d5b72bd10389df8247cee551d2d0c Mon Sep 17 00:00:00 2001 From: Aviran Cohen Date: Sun, 27 Dec 2015 23:41:35 +0200 Subject: [PATCH 3/3] unicode check moved into its own function IsUnicodeFileName. --- src/Zip/ZipEntryFactory.cs | 39 +++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Zip/ZipEntryFactory.cs b/src/Zip/ZipEntryFactory.cs index dc6b38de1..c6dbc1b96 100644 --- a/src/Zip/ZipEntryFactory.cs +++ b/src/Zip/ZipEntryFactory.cs @@ -200,16 +200,33 @@ public bool IsUnicodeText set { isUnicodeText_ = value; } } - #endregion + #endregion - #region IEntryFactory Members + #region Private Methods - /// - /// Make a new for a file. - /// - /// The name of the file to create a new entry for. - /// Returns a new based on the . - public ZipEntry MakeFileEntry(string fileName) + /// + /// Check whether the file name is unicode encoded or not. + /// + /// The name of the file to check its encoding. + /// + private bool IsUnicodeFileName(string fileName) + { + Encoding defaultEncoding = Encoding.GetEncoding(ZipConstants.DefaultCodePage); + byte[] unicodeFileNameBytes = defaultEncoding.GetBytes(fileName); + string unicodeFileName = defaultEncoding.GetString(unicodeFileNameBytes); + return unicodeFileName != fileName; + } + + #endregion + + #region IEntryFactory Members + + /// + /// Make a new for a file. + /// + /// The name of the file to create a new entry for. + /// Returns a new based on the . + public ZipEntry MakeFileEntry(string fileName) { return MakeFileEntry(fileName, null, true); } @@ -236,15 +253,11 @@ public ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSys ZipEntry result = new ZipEntry(nameTransform_.TransformFile(entryName != null && entryName.Length > 0 ? entryName : fileName)); result.IsUnicodeText = isUnicodeText_; - Encoding defaultEncoding = Encoding.GetEncoding(ZipConstants.DefaultCodePage); - byte[] unicodeFileNameBytes = defaultEncoding.GetBytes(result.Name); - string unicodeFileName = defaultEncoding.GetString(unicodeFileNameBytes); - if (unicodeFileName != result.Name) + if (IsUnicodeFileName(result.Name)) { result.IsUnicodeText = true; } - int externalAttributes = 0; bool useAttributes = (setAttributes_ != 0);