0

I'm trying to create a setup using Inno Setup which should autoupdate itself if there is a newer version of the installer available. For the download part I want to use the Inno Setup plugin "Inno Download Plugin v1.2" from "Mitrich Software"

update: this is the version check I'm currently using, it works good but has a slight delay when I run the setup

function DownloadFile(const AURL: string; var AResponse: string): Boolean;
var
  WinHttpRequest: Variant;
begin
  Result := True;
  try
    WinHttpRequest := CreateOleObject('WinHttp.WinHttpRequest.5.1');
    WinHttpRequest.Open('GET', AURL, False);
    WinHttpRequest.Send;
    AResponse := WinHttpRequest.ResponseText;
  except
    Result := False;
    AResponse := GetExceptionMessage;
  end;
end;

procedure InitializeWizard;
var
  response: string;
begin
  if DownloadFile('{#MyAppVersionFile}', response) then
  begin
    if CompareStr(response,'{#MyAppVersion}') > 0 then
    begin
      MsgBox('{#MyAppName} v'+ response +' is available!' #13#10 'Please download the latest version!', mbInformation, MB_OK)
    end;
  end else
  begin
    MsgBox('Could not perform version check! Are you connected to the internet?', mbInformation, MB_OK)
  end;
end;
mghie
  • 32,028
  • 6
  • 87
  • 129
  • Ok, and so what is your question ? – TLama May 09 '14 at 11:45
  • I'm trying to find an "example" code somewhere, since it's my first time using Inno Setup and a google search for "inno setup automatic update installer" revealed no results –  May 09 '14 at 11:52
  • Try to search for pieces of code from whose you can build it. You'll surely find a way how to check if there's a newer version, how to download a file and how to execute (that downloaded) file and exit (the old) setup. – TLama May 09 '14 at 11:59
  • @TLama i've already found an example code for the version check [here](https://stackoverflow.com/questions/8863036/how-to-read-a-text-file-from-the-internet-resource), thank you for your input, I will try to find some example code on the download plugin –  May 09 '14 at 12:03
  • i've rewrote the version check a bit but now i got a slight delay if i execute my setup, is this normal? i've updated the initial post –  May 09 '14 at 14:36
  • Yes, the `InitializeWizard` is an event fired when the wizard form is being initialized and that COM object initialization as well as downloading of that file just take some time (even bigger delay you'll get e.g. when there won't be Internet connection available). But that is just a consequence of that check before the wizard form is visible. But anyway, your current question became a mix of two things by your edit. You should always ask about one thing per post... – TLama May 09 '14 at 14:48
  • @TLama ok thank you for all your help on this, next time i'll create a second question, could you help me once more with an if/else statement? i've updated the code in the original post, somehow i wont reach my "could not perform version check" is there something wrong with my if/else statement? –  May 09 '14 at 14:55
  • No, that statement is correct. You'll get that message when downloading of the file fails for some reason. If you're getting an exception, then you're running the setup from debugger which shows exception messages by default (unless you uncheck "Pause on exception" option in IDE settings, which you shouldn't). – TLama May 09 '14 at 15:00
  • I've built an installer that updates itself and I detailed the process here: https://stackoverflow.com/a/69580127/8133067 – Pedro Gaspar Oct 15 '21 at 05:07

0 Answers0