Inno Setup - How to read the INF file during installation

I need to know how to read a value from an INF file [.inf] during installation. I want the installer to check the version of the program that I am going to update. This version of the program is not saved in the registry or any other file, it is only in the .inf file. Then you need to get the version.

I got your answers, @Tlama, and I cannot use the DLL to get the software version. This program saves only the current version in the INF file.

What I want to do is make the installer check the current version of the software I'm working with and display that version in the text of the shortcut.

File Information:

NetVersion=1.1.1.1
PatchVersion=2.0.1
ProductName=SoftwareX

I just need PatchVersion to appear after it says version: ####:

enter image description here

this is the code I'm trying to fix:

function GetInfsam: String;
var
  sVersion : String;
Begin
  sVersion := '';
  GetIniString('', 'PatchVersion', 'sVersion', '{app}\Sam.inf');
  Result := sVersion;
end;

Procedure InitializeWizard7();
var
  L2Ver1 : Tlabel;
  L2Ver2 : Tlabel;
Begin
  L2Ver1:=  TLabel.Create(WizardForm);
  L2Ver1.Transparent:= True;
  L2Ver1.AutoSize:= False;
  L2Ver1.WordWrap:= True;
  L2Ver1.Font.name:= 'Agency FB';
  L2Ver1.Font.Size:= 12;
  L2Ver1.Font.Color:= clwhite;
  L2Ver1.Caption:= 'Version:';
  L2Ver1.Parent:= WizardForm.SelectdirPage;
  L2Ver1.Left := 5;
  L2Ver1.top := 260;
  L2Ver1.Width := 150;
  L2Ver1.Height := 40;

  L2Ver2:=  TLabel.Create(WizardForm);
  L2Ver2.Transparent:= True;
  L2Ver2.AutoSize:= False;
  L2Ver2.WordWrap:= True;
  L2Ver2.Font.name:= 'Agency FB';
  L2Ver2.Font.Size:= 12;
  L2Ver2.Font.Color:= clwhite;
  L2Ver2.Caption:= GetInfsam;
  L2Ver2.Parent:= WizardForm.SelectdirPage;
  L2Ver2.Left := L2Ver1.Width + L2Ver1.Left + 8;
  L2Ver2.top := 260;
  L2Ver2.Width := 100;
  L2Ver2.Height := 40;
End;

, , .

+5
2

INF?

INF - INI specified syntax. INF INI. , INF :

[Add.Code]
File.dll=File.dll

[File.dll]
File=http://www.code.com/file.dll
FileVersion=1,0,0,143

FileVersion , GetIniString :

procedure InitializeWizard;
var
  Version: string;
begin
  Version := GetIniString('File.dll', 'FileVersion', '', 'c:\File.inf');
  if Version <> '' then
    MsgBox('File version: ' + Version, mbInformation, MB_OK);
end;

:

1. Malformed INF file

, INF :

NetVersion=1.1.1.1
PatchVersion=2.0.1
ProductName=SoftwareX

INF , , INF. INF [] , .

2. GetIniString

GetIniString Section, GetPrivateProfileString , , . , , , Section :

GetIniString('', 'KeyName', 'Default', 'c:\File.xxx');

3. ?

, . TStringList , , Delphi. , InnoSetup TStringList , , . . =. AKeyName AFileName ADefault :

function GetKeyValue(const AKeyName, AFileName, ADefault: string): string;
var  
  I: Integer;
  KeyPos: Integer;
  KeyFull: string;
  FileLines: TArrayOfString;
begin
  Result := ADefault;
  if LoadStringsFromFile(AFileName, FileLines) then
  begin
    KeyFull := AKeyName + '=';
    for I := 0 to GetArrayLength(FileLines) - 1 do
    begin
      FileLines[I] := TrimLeft(FileLines[I]);
      KeyPos := Pos(KeyFull, FileLines[I]);
      if KeyPos > 0 then
      begin
        Result := Copy(FileLines[I], KeyPos + Length(AKeyName) + 1, MaxInt);
        Break;
      end;
    end;
  end;
end;

PatchVersion Sam.inf, , - . script , :

var
  // target version label must be declared globally
  L2Ver2: TLabel;

procedure DirEditChange(Sender: TObject);
var
  FilePath: string;
begin
  // assign the expected INF file path
  FilePath := AddBackslash(WizardForm.DirEdit.Text) + 'Sam.inf';
  // read the PatchVersion key value, return N/A if not found
  L2Ver2.Caption := GetKeyValue('PatchVersion', FilePath, 'N/A');
end;

procedure InitializeWizard;
begin
  // create the target label as before
  L2Ver2 := TLabel.Create(WizardForm);
  ...
  // bind the DirEditChange method to the directory edit OnChange event
  WizardForm.DirEdit.OnChange := @DirEditChange;  
end;

procedure CurPageChanged(CurPageID: Integer);
begin
  // if the page has been turned to the select directory page, update the
  // label caption by firing the assigned OnChange event method manually
  if (CurPageID = wpSelectDir) then
    DirEditChange(nil);
end;
+10

INF , INI. , INF, INI, ( TLama)

:

function GetIniInt(const Section, Key: String; const Default, Min, Max: Longint; const Filename: String): Longint;
function GetIniString(const Section, Key, Default, Filename: String): String;

:

str ReadIni(str 1, str 2, str 3, str? 4)

( Inno Setup)

INI . 1 INI , 2 - INI , - . , , , .

+3

All Articles