Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions src/Zip/ZipEntryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using System.IO;

using ICSharpCode.SharpZipLib.Core;
using System.Text;

namespace ICSharpCode.SharpZipLib.Zip
{
Expand Down Expand Up @@ -199,16 +200,33 @@ public bool IsUnicodeText
set { isUnicodeText_ = value; }
}

#endregion

#region IEntryFactory Members

/// <summary>
/// Make a new <see cref="ZipEntry"/> for a file.
/// </summary>
/// <param name="fileName">The name of the file to create a new entry for.</param>
/// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
public ZipEntry MakeFileEntry(string fileName)
#endregion

#region Private Methods

/// <summary>
/// Check whether the file name is unicode encoded or not.
/// </summary>
/// <param name="fileName">The name of the file to check its encoding.</param>
/// <returns></returns>
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

/// <summary>
/// Make a new <see cref="ZipEntry"/> for a file.
/// </summary>
/// <param name="fileName">The name of the file to create a new entry for.</param>
/// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
public ZipEntry MakeFileEntry(string fileName)
{
return MakeFileEntry(fileName, null, true);
}
Expand All @@ -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;
Expand Down