Skip to content

Commit 2517d36

Browse files
committed
unicode check moved into its own function IsUnicodeFileName.
1 parent 512afe8 commit 2517d36

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/Zip/ZipEntryFactory.cs

+26-13
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,33 @@ public bool IsUnicodeText
200200
set { isUnicodeText_ = value; }
201201
}
202202

203-
#endregion
203+
#endregion
204204

205-
#region IEntryFactory Members
205+
#region Private Methods
206206

207-
/// <summary>
208-
/// Make a new <see cref="ZipEntry"/> for a file.
209-
/// </summary>
210-
/// <param name="fileName">The name of the file to create a new entry for.</param>
211-
/// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
212-
public ZipEntry MakeFileEntry(string fileName)
207+
/// <summary>
208+
/// Check whether the file name is unicode encoded or not.
209+
/// </summary>
210+
/// <param name="fileName">The name of the file to check its encoding.</param>
211+
/// <returns></returns>
212+
private bool IsUnicodeFileName(string fileName)
213+
{
214+
Encoding defaultEncoding = Encoding.GetEncoding(ZipConstants.DefaultCodePage);
215+
byte[] unicodeFileNameBytes = defaultEncoding.GetBytes(fileName);
216+
string unicodeFileName = defaultEncoding.GetString(unicodeFileNameBytes);
217+
return unicodeFileName != fileName;
218+
}
219+
220+
#endregion
221+
222+
#region IEntryFactory Members
223+
224+
/// <summary>
225+
/// Make a new <see cref="ZipEntry"/> for a file.
226+
/// </summary>
227+
/// <param name="fileName">The name of the file to create a new entry for.</param>
228+
/// <returns>Returns a new <see cref="ZipEntry"/> based on the <paramref name="fileName"/>.</returns>
229+
public ZipEntry MakeFileEntry(string fileName)
213230
{
214231
return MakeFileEntry(fileName, null, true);
215232
}
@@ -236,15 +253,11 @@ public ZipEntry MakeFileEntry(string fileName, string entryName, bool useFileSys
236253
ZipEntry result = new ZipEntry(nameTransform_.TransformFile(entryName != null && entryName.Length > 0 ? entryName : fileName));
237254
result.IsUnicodeText = isUnicodeText_;
238255

239-
Encoding defaultEncoding = Encoding.GetEncoding(ZipConstants.DefaultCodePage);
240-
byte[] unicodeFileNameBytes = defaultEncoding.GetBytes(result.Name);
241-
string unicodeFileName = defaultEncoding.GetString(unicodeFileNameBytes);
242-
if (unicodeFileName != result.Name)
256+
if (IsUnicodeFileName(result.Name))
243257
{
244258
result.IsUnicodeText = true;
245259
}
246260

247-
248261
int externalAttributes = 0;
249262
bool useAttributes = (setAttributes_ != 0);
250263

0 commit comments

Comments
 (0)