From 4449fcc5b8d104817c67135229682c66c3d892ca Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 2 Apr 2021 14:41:49 -0700 Subject: Enable codepages and languages to be set via .wxl files Fixes wixtoolset/issues#5801 --- .../Bind/CreateIdtFileCommand.cs | 42 +++++++++++++--------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateIdtFileCommand.cs') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateIdtFileCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateIdtFileCommand.cs index f09a2e47..ff03413c 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateIdtFileCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateIdtFileCommand.cs @@ -36,23 +36,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind public void Execute() { // write out the table to an IDT file - Encoding encoding; - - // If UTF8 encoding, use the UTF8-specific constructor to avoid writing - // the byte order mark at the beginning of the file - if (this.Codepage == Encoding.UTF8.CodePage) - { - encoding = new UTF8Encoding(false, true); - } - else - { - if (this.Codepage == 0) - { - this.Codepage = Encoding.ASCII.CodePage; - } - - encoding = Encoding.GetEncoding(this.Codepage, new EncoderExceptionFallback(), new DecoderExceptionFallback()); - } + var encoding = GetCodepageEncoding(this.Codepage); this.IdtPath = Path.Combine(this.IntermediateFolder, String.Concat(this.Table.Name, ".idt")); @@ -209,6 +193,30 @@ namespace WixToolset.Core.WindowsInstaller.Bind .Replace('\n', '\x19'); } + private static Encoding GetCodepageEncoding(int codepage) + { + Encoding encoding; + + // If UTF8 encoding, use the UTF8-specific constructor to avoid writing + // the byte order mark at the beginning of the file + if (codepage == Encoding.UTF8.CodePage) + { + encoding = new UTF8Encoding(false, true); + } + else + { + if (codepage == 0) + { + codepage = Encoding.ASCII.CodePage; + } + + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + + encoding = Encoding.GetEncoding(codepage, new EncoderExceptionFallback(), new DecoderExceptionFallback()); + } + + return encoding; + } /// /// Gets the type of the column in IDT format. -- cgit v1.2.3-55-g6feb