Inno Setup Pascal脚本-读取UTF-16文件 [英] Inno Setup Pascal Script - Reading UTF-16 file

查看:100
本文介绍了Inno Setup Pascal脚本-读取UTF-16文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从Resource Hacker导出的.inf文件.该文件采用UTF-16 LE编码.

I have an .inf file exported from Resource Hacker. The file is in UTF-16 LE encoding.

EXTRALARGELEGENDSII_INI TEXTFILE "Data.bin"

LARGEFONTSLEGENDSII_INI TEXTFILE "Data_2.bin"

NORMALLEGENDSII_INI TEXTFILE "Data_3.bin"

THEMES_INI TEXTFILE "Data_4.bin" 

当我使用 LoadStringFromFile函数加载时:

procedure LoadResources;
var
  RESOURCE_INFO: AnsiString;
begin
  LoadStringFromFile(ExpandConstant('{tmp}\SKINRESOURCE - INFO.inf'), RESOURCE_INFO);
  Log(String(RESOURCE_INFO));
end;

我在 Debug Output 中得到了这一点:

I am getting this in the Debug Output:

E

请告诉我如何解决此问题.

Please tell me how to fix this issue.

谢谢.

推荐答案

似乎您要记录的文件是Windows Unicode(UTF-16LE)编码的文本文件.

It seems the file you are trying to log is a Windows Unicode (UTF-16LE) Encoded text file.

您可以使用 iConv 命令行并转换文件Windows UTF-8编码文件.

You can use iConv Command Line and convert your file to Windows UTF-8 Encoded File.

LoadStringFromFile支持功能无法加载Unicode字符串好,它仅支持加载ANSI和UTF-8编码文本文件.

The LoadStringFromFile Support Function does not load Unicode Strings well and it only supports loading ANSI and UTF-8 Encoded Text Files.

Inno Setup编译器调试输出停止记录文本文件,因为它找到了无法加载的字符(NULL),这就是为什么即使LoadStringFromFile完全加载文本文件也只能在编译器调试输出中获得"E"的原因

Inno Setup Compiler Debug Output stops logging the Text File because it finds a Character it can't load (NULL) and that's why you're getting only "E" in Compiler Debug Output even LoadStringFromFile loads the text file completely.

您需要下载iConv的安装程序,如下所示,以获取iConv可执行文件和一些用于在字符编码之间进行转换的DLL.

You need to download the Setup Program of the iConv as shown below to get iConv Executable File and some DLLs used to convert between character encoding.

下载后,安装GnuWin32(适用于Windows的LibIconv)并转到安装文件夹.

After downloaded, install GnuWin32 (LibIconv for Windows) and go to the installation folder.

将以下四个文件复制到安装文件夹"bin"中的子目录中.

Copy following four files inside the sub directory in installation folder called "bin".

它们是:

libcharset1.dll

libiconv2.dll

iconv.exe

libintl3.dll

将这些文件复制到您存储Inno Setup Project文件的目录中.

copy these files to the directory where you store files of your Inno Setup Project.

然后使用以下代码进行转换.

Then use following code to do the Conversion.

[Files]
Source: "libcharset1.dll"; Flags: dontcopy
Source: "iconv.exe"; Flags: dontcopy
Source: "libiconv2.dll"; Flags: dontcopy
Source: "libintl3.dll"; Flags: dontcopy

[Code]
function InitializeSetup(): Boolean
var
  ErrorCode: Integer;
begin
  ExtractTemporaryFile('iconv.exe');
  ExtractTemporaryFile('libcharset1.dll');
  ExtractTemporaryFile('libintl3.dll');
  ExtractTemporaryFile('libiconv2.dll');
  ShellExec('Open', ExpandConstant('CMD.exe'), ExpandConstant('/C iConv -f UTF-16LE -t UTF-8 < SKINRESOURCE-INFO.inf > SKINRESOURCE-INFO-ANSI.inf'), ExpandConstant('{tmp}'), SW_HIDE, ewWaitUntilTerminated, ErrorCode); 
  DeleteFile(ExpandConstant('{tmp}\SKINRESOURCE-INFO.inf')); 

现在LoadStringFromFile应该可以正确加载文本文件,因为它具有Windows UTF-8编码.

Now LoadStringFromFile should load the text file correctly as now it has the Windows UTF-8 Encoding.

如果使用的是Unicode Inno Setup,也可以在将其转换为Unicode字符串(如Log(String(RESOURCE_INFO)))后将其记录下来.

You may also log it after converting it into a Unicode String like Log(String(RESOURCE_INFO)), if you are using Unicode Inno Setup.

这篇关于Inno Setup Pascal脚本-读取UTF-16文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆