0

I have a Inno script that read a text file "Version.txt" from folders and show the content in a radio format like in the picture below. The problem is instead of showing : "Version 1.0" & "Version 2.0" . It shows a text like "yBC" & "yBC" Which is incomprehensible. How can I correct the code to read the unicode format from the text file ?

Picture

  if ((FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY) <> 0) and
     (FindRec.Name <> '.') and
     (FindRec.Name <> '..') then
  begin
    Path := RootPath + '\' + FindRec.Name;
    { LoadStringFromFile can handle only ascii/ansi files, no Unicode }
    if LoadStringFromFile(Path + '\' + 'Version.txt', Name) then
    begin
      Dirs.Add(Path);
      DirCheckListBox.AddRadioButton(Name, '', 0, False, True, nil);
      { If already installed, check the path that was selected previously, }
      { otherwise check the first one }
      if (DirCheckListBox.Items.Count = 1) or
         (CompareText(WizardForm.DirEdit.Text, Path) = 0) then
      begin
        DirCheckListBox.ItemIndex := DirCheckListBox.Items.Count - 1;
        DirCheckListBox.Checked[DirCheckListBox.ItemIndex] := True;
      end;
    end;
  end;
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • Where's nothing like *"unicode format"*. Unicode is **character set**. We need to know what **encoding** does your file have. If the file uses Unicode character set, it may have UTF-8, UTF-16LE or UTF-16BE encodings (or even yet another). UTF-8 can be with and without BOM. – Martin Prikryl Jun 28 '18 at 19:01
  • If you do not know, try to open the file in Windows Notepad using various encodings. Windows Notepad uses a wrong terminology, so there "Unicode" = UTF-16LE, "Unicode big endian" = UTF-16BE. – Martin Prikryl Jun 28 '18 at 19:05
  • I opened the text tile and clicked on Save As, in the "Encoding" there was "unicode" alone – John Turing Jun 28 '18 at 19:19
  • I mean in the Open dialog: So, if you select "Unicode" there, the file opens correctly? While if you select "Unicode big endian" or UTF-8 it probably opens incorrectly, right? – Martin Prikryl Jun 28 '18 at 19:22
  • The file opens correctly in all options (ANSI, unicode ...) options – John Turing Jun 28 '18 at 19:32
  • I do not think that's actually possible. – Martin Prikryl Jun 28 '18 at 19:35
  • Can you ZIP the file and upload it somewhere for us to check? – Martin Prikryl Jun 28 '18 at 19:35
  • Yeah sure. Here is one the files: https://files.fm/u/w692fwfr – John Turing Jun 28 '18 at 20:39
  • It's UTF-16LE. And I have no problem reading it using `LoadStringFromUTF16LEFile` function from https://stackoverflow.com/a/39845057/850848 – Martin Prikryl Jun 29 '18 at 05:21
  • This is what I get if I put your file to the folders and replace `LoadStringFromFile` call with `LoadStringFromUTF16LEFile` and change `Name` variable type from `AnsiString` to `string`: https://i.stack.imgur.com/cYwVH.png - All assuming you are using Unicode version of Inno Setup. – Martin Prikryl Jun 29 '18 at 05:24
  • Thank you Martin, – John Turing Jun 29 '18 at 13:06
  • So did you resolve it? – Martin Prikryl Jun 29 '18 at 13:08
  • Unfortunately No, that solution didn't work for me and I still get a text like "ybV1" instead of 1.0 – John Turing Jun 29 '18 at 13:14
  • Is there any other solution to this problem? – John Turing Jun 29 '18 at 13:17
  • The problem is defining the problem. I do not know what your problem is. For me everything works. Do you have Unicode version of Inno Setup? – Martin Prikryl Jun 29 '18 at 14:11
  • I don't know what do you mean by Unicode version of Inno Setup ? Are there multiple versions of Inno Setup ? I downloaded Inno Setup from jrsoftware org. I didn't see any other version there. – John Turing Jun 29 '18 at 14:14
  • You are right, the problem is in defining the problem. I am still very new to Inno script but not new to programming in general. I am still struggling to understand some parts.. – John Turing Jun 29 '18 at 14:15
  • Yes, there are two versions: Legacy Ansi version and Unicode version. See http://jrsoftware.org/isdl.php – Martin Prikryl Jun 29 '18 at 14:16
  • lol that was there the whole time!! but I didn't see it ! Sorry Martin for the trouble. You wee and are very helpful and patient. Thank you. I will check it out and then reply. – John Turing Jun 29 '18 at 14:19

0 Answers0