Skip to content

Commit c48d1e0

Browse files
committed
Merge branch 'feature/fix-329' into develop
2 parents 4bfacc4 + 7e99b79 commit c48d1e0

File tree

4 files changed

+420
-376
lines changed

4 files changed

+420
-376
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*----------------------------------------------------------
2+
This Source Code Form is subject to the terms of the
3+
Mozilla Public License, v.2.0. If a copy of the MPL
4+
was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
----------------------------------------------------------*/
7+
8+
namespace ScriptEngine.HostedScript.Library.Zip
9+
{
10+
[EnumerationType("КодировкаИменФайловВZipФайле","FileNamesEncodingInZipFile")]
11+
public enum FileNamesEncodingInZipFile
12+
{
13+
[EnumItem("Авто")]
14+
Auto,
15+
16+
[EnumItem("UTF8")]
17+
Utf8,
18+
19+
[EnumItem("КодировкаОСДополнительноUTF8","OSEncodingWithUTF8")]
20+
OsEncodingWithUtf8
21+
}
22+
}

src/ScriptEngine.HostedScript/Library/Zip/ZipReader.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ private void CheckIfOpened()
4444
/// <param name="filename">Имя ZIP файла, который требуется открыть для чтения.</param>
4545
/// <param name="password">Пароль к файлу, если он зашифрован.</param>
4646
[ContextMethod("Открыть","Open")]
47-
public void Open(string filename, string password = null)
47+
public void Open(string filename, string password = null, FileNamesEncodingInZipFile encoding = FileNamesEncodingInZipFile.Auto)
4848
{
49+
ZipFile.DefaultEncoding = Encoding.GetEncoding(866);
4950
// fuck non-russian encodings on non-ascii files
50-
_zip = ZipFile.Read(filename, new ReadOptions() { Encoding = Encoding.GetEncoding(866) });
51+
_zip = ZipFile.Read(filename, new ReadOptions() { Encoding = ChooseEncoding(encoding) });
5152
_zip.Password = password;
5253
}
5354

55+
private Encoding ChooseEncoding(FileNamesEncodingInZipFile encoding)
56+
{
57+
if(encoding != FileNamesEncodingInZipFile.OsEncodingWithUtf8)
58+
return Encoding.UTF8;
59+
60+
return null;
61+
}
62+
5463

5564
/// <summary>
5665
/// Извлечение всех файлов из архива

0 commit comments

Comments
 (0)