Inno Setup Pascal Script - Reading a UTF-16 File

I have a file .infexported from Resource Hacker. The file is encoded in UTF-16 LE.

EXTRALARGELEGENDSII_INI TEXTFILE "Data.bin"

LARGEFONTSLEGENDSII_INI TEXTFILE "Data_2.bin"

NORMALLEGENDSII_INI TEXTFILE "Data_3.bin"

THEMES_INI TEXTFILE "Data_4.bin" 

When I load it using the function LoadStringFromFile:

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

I get this in the output of Debug:

E

Please tell me how to solve this problem.

Thanks in advance.

+4
source share
2 answers

The file you are trying to write seems to be a Windows encoded Unicode (UTF-16LE) text file.

You can use the iConv command line and convert the file to a Windows UTF-8 encoded file.

LoadStringFromFile Unicode ANSI UTF-8.

Inno Setup , , (NULL), "E" LoadStringFromFile .


iConv, , iConv DLL, .

enter image description here

GnuWin32 (LibIconv Windows) .

"bin".

:

libcharset1.dll

libiconv2.dll

iconv.exe

libintl3.dll

, Inno.

.

[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.

Unicode, Log(String(RESOURCE_INFO)), Unicode Inno Setup.

0

LE UTF-16.

LoadStringFromFile Unicode. , (AnsiString ).

Unicode string UTF-16 LE, , , - (Unicode) string. UTF-16 LE BOM (FEFF).

procedure RtlMoveMemory(Dest: string; Source: PAnsiChar; Len: Integer);
  external 'RtlMoveMemory@kernel32.dll stdcall';

function LoadStringFromUTF16LEFile(FileName: string; var S: string): Boolean;
var
  A: AnsiString;
begin
  Result := LoadStringFromFile(FileName, A);
  if Result then
  begin
    SetLength(S, Length(A) div 2);
    RtlMoveMemory(S, A, Length(S) * 2);
    { Trim BOM, if any }
    if (Length(S) >= 1) and (Ord(S[1]) = $FEFF) then
      Delete(S, 1, 1);
  end;
end;

. Inno Setup Ansi Unicode.

+3

Source: https://habr.com/ru/post/1651374/


All Articles