Skip to content
Merged
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
42 changes: 32 additions & 10 deletions src/Zip/ZipEntryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,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 @@ -236,6 +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_;

if (IsUnicodeFileName(result.Name))
{
result.IsUnicodeText = true;
}

int externalAttributes = 0;
bool useAttributes = (setAttributes_ != 0);

Expand Down