Thomas S.
Thomas S.

Reputation: 6335

InnoSetup: uninstall/update if install in the previous directory

Different versions of our software should be able to install in parallel by specifying different install directories. But if the user decides to install in the directory where a previous version is installed, it should update that (aka uninstall the previous version in this directory and install the new one).

Using the same AppId as described in the InnoSetup FAQ is no option, because otherwise it is not possible to install in parallel.

Upvotes: 3

Views: 1865

Answers (1)

Miral
Miral

Reputation: 13020

Actually the AppId is exactly the right way to do it. The AppId is allowed to be specified as a {code:...} constant. As described in the help for that value, this will be called multiple times; at least once prior to the wizard starting and once prior to the installation proper beginning.

The first time this is called you should return a known value (either a fixed default [possibly an empty string] or some most-recently-used value retrieved from the registry) to aid in previous-value lookup, especially if the user does decide to only install a single instance. Note that for the best user experience you should try to return a "real" valid value for a previously-installed instance on any subsequent install (eg. the first such install, or the most recent), but this is not essential.

After wpSelectDir has been shown and the user has chosen their destination path, you should return the "real" AppId from subsequent calls to the function. It's up to you what value to use, but you must fulfil the following requirements:

  • It must be unique to your application (no other apps should ever use the same value).
  • It must be unique to a specific instance of your application (side-by-side installations in separate folders must have different values).
  • It must be fixed for a specific instance of your application (if your app is installed into a particular folder, attempting reinstallation into that same folder without an intervening uninstall MUST yield exactly the same value as the previous time; if it was uninstalled first then it CAN yield the same value [as long as it's still unique] but it's not a requirement).

One way of doing this is to use an app-specific fixed prefix followed by an encoded form of the target directory (stripping backslashes at least). Another way is to maintain a list in the registry of existing installations and using a numeric suffix indicating the position within that list of a particular instance (bearing in mind that this may end up noncontiguous if they are uninstalled out of order).

(If you do maintain a list of previously installed instances, then this offers other options to improve the user experience, such as explicitly asking them via a custom wizard page whether they want to upgrade an existing instance or install a new one, and in the former case you can let them pick from the list of instances instead of displaying wpSelectDir. Of course, this way requires quite a bit of code.)

Further note that you should not uninstall if a previous version exists; simply install over the top. Normally you don't need to do anything special for this, but on rare occasions you might want to add [InstallDelete] entries to remove now-redundant files. As long as you maintain the rules above for the AppId, this will function cleanly.

Upvotes: 3

Related Questions