Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating an installer that will perform an update if an older version is already installed

I am trying to configure Inno setup for my software (this is a C# software). I plan to release many versions of my software, I would like to change the Inno setup installer interface if an older version of my application is already installed on the computer. In this case, the user shouldn't be able to change the install directory.

There are four cases:

First case: this is the first installation of my product, Inno setup should proceed normally.

Second case: the product is already installed AND the installer contains a newer version. The user cannot choose the destination folder. He can just run the update.

Third case: If the installer contains an older version than the installed one, the update will be disabled and a message should be displayed.

Fourth case: The installer version is the same than the installed version. The user can repair his actual version if needed.

Is it possible to do that with InnoSetup?

like image 988
Ben Avatar asked Mar 26 '13 13:03

Ben


2 Answers

Inno Setup already handles cases 1, 2, and 4 automatically if your AppID is kept the same for the life of the application.
You can also hide the directory and group pages using the following[Setup] directives:

DisableDirPage=auto
DisableGroupPage=auto

See this ISXKB article for more details.

For case 3, assuming your files are versioned correctly, Inno won't downgrade anything, but it won't actually warn the user. To do that, you will need to add code to check this, most likely in the InitializeSetup() event function.

like image 160
Deanna Avatar answered Oct 22 '22 06:10

Deanna


If you want to have some feedback for user you can try something like that. First of all, your update should have the same AppId name as your Main App. Then you can set some checks, that will display messages to inform user about the state.

#define MyAppVersion "1.2.2.7570"
#define MyAppName "MyApp Update"

[Setup]
AppId=MyApp
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1,InstallLocation}
DisableDirPage=True

[CustomMessages]
MyAppOld=The Setup detected application version 
MyAppRequired=The installation of {#MyAppName} requires MyApp to be installed.%nInstall MyApp before installing this update.%n%n
MyAppTerminated=The setup of update will be terminated.

[Code]
var
InstallLocation: String;

function GetInstallString(): String;
var
InstPath: String;
InstallString: String;
begin
InstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1');
InstallString := '';
if not RegQueryStringValue(HKLM, InstPath, 'InstallLocation', InstallString) then
RegQueryStringValue(HKCU, InstPath, 'InstallLocation', InstallString);
Result := InstallString;
InstallLocation := InstallString;
end;

function InitializeSetup: Boolean;
var
V: Integer;
sUnInstallString: String;
Version: String;
begin
    if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'UninstallString') then begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'DisplayVersion', Version);
      if Version =< ExpandConstant('{#MyAppVersion}') then begin 
          Result := True;
          GetInstallString();
       end
       else begin
MsgBox(ExpandConstant('{cm:MyAppOld}'+Version+'.'+#13#10#13#10+'{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
         Result := False;
  end;
end
else begin
  MsgBox(ExpandConstant('{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
  Result := False;
end;
end;
like image 31
RobeN Avatar answered Oct 22 '22 07:10

RobeN