(EncodingSetting): fallback to CP932.

This commit is contained in:
morkt 2018-03-17 12:16:53 +04:00
parent a7241004f5
commit 44e74d68b3
2 changed files with 16 additions and 11 deletions

View File

@ -186,18 +186,9 @@ namespace GameRes.Formats.PkWare
public override ResourceOptions GetDefaultOptions () public override ResourceOptions GetDefaultOptions ()
{ {
Encoding enc;
try
{
enc = ZipEncoding.Get<Encoding>();
}
catch
{
enc = Encodings.cp932;
}
return new ZipOptions { return new ZipOptions {
CompressionLevel = Properties.Settings.Default.ZIPCompression, CompressionLevel = Properties.Settings.Default.ZIPCompression,
FileNameEncoding = enc, FileNameEncoding = ZipEncoding.Get<Encoding>(),
Password = Properties.Settings.Default.ZIPPassword, Password = Properties.Settings.Default.ZIPPassword,
}; };
} }

View File

@ -3,7 +3,9 @@
//! \brief Persistent resource settings implementation. //! \brief Persistent resource settings implementation.
// //
using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Text; using System.Text;
using GameRes.Formats.Strings; using GameRes.Formats.Strings;
@ -27,8 +29,20 @@ namespace GameRes.Formats
internal class EncodingSetting : LocalResourceSetting internal class EncodingSetting : LocalResourceSetting
{ {
static readonly Encoding DefaultEncoding = Encodings.cp932;
public override object Value { public override object Value {
get { return Encoding.GetEncoding ((int)base.Value); } get {
try
{
return Encoding.GetEncoding ((int)base.Value);
}
catch // fallback to CP932
{
Trace.WriteLine (string.Format ("Unknown encoding code page {0}", base.Value));
return DefaultEncoding;
}
}
set { base.Value = ((Encoding)value).CodePage; } set { base.Value = ((Encoding)value).CodePage; }
} }