In my Inno Setup project, I download all files from the server and also download a file that has a version number. Now I want to read the version from the file and assign it to [Setup] section AppVersion in the Code section. My question is that possible to set the app version in the Code section?
            Asked
            
        
        
            Active
            
        
            Viewed 187 times
        
    2
            
            
        
        Martin Prikryl
        
- 188,800
 - 56
 - 490
 - 992
 
        sina
        
- 331
 - 4
 - 12
 
1 Answers
2
            Combining these two questions:
- How to set version number from Inno Setup Pascal Script
 - Inno Setup - HTTP request - Get www/web content
 
[Setup]
AppVersion={code:GetAppVersion}
[Code]
var
  Version: string;
function GetAppVersion(Param: string): string;
var
  WinHttpReq: Variant;
begin
  if Version = '' then
  begin
    WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
    WinHttpReq.Open('GET', 'https://www.example.com/version.txt', False);
    WinHttpReq.Send('');
    if WinHttpReq.Status <> 200 then
    begin
      Log('HTTP Error: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText);
      MsgBox('Cannot obtain version', mbError, MB_OK);
      Abort();
    end
      else
    begin
      Version := Trim(WinHttpReq.ResponseText);
      Log('Version: ' + Version);
      // you may want to validate that the value is meaningful here
    end;
  end;
  Result := Version;
end;
        Martin Prikryl
        
- 188,800
 - 56
 - 490
 - 992