diff --git a/src/Zip/ZipEntryFactory.cs b/src/Zip/ZipEntryFactory.cs index 2affbd97e..c6dbc1b96 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 { @@ -199,16 +200,33 @@ public bool IsUnicodeText set { isUnicodeText_ = value; } } - #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) + #endregion + + #region Private Methods + + /// + /// 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); } @@ -235,7 +253,12 @@ 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; + if (IsUnicodeFileName(result.Name)) + { + result.IsUnicodeText = true; + } + + int externalAttributes = 0; bool useAttributes = (setAttributes_ != 0); FileInfo fi = null;