1

I'm trying to solve the issue where InnoSetup doesn't delete no-longer-used files on upgrade. That is, you install version v1.0 of your application which installs a file that is not used v1.1. During the upgrade to v1.1, the unused files is left behind. Meanwhile, the uninstaller for version v1.0 will remove all of 1.0s files and the uninstaller for 1.1 removes all of 1.1s files. A suggested fix is to programmatically launch the uninstaller for v1.0 during the upgrade.

There's a couple of ways of doing this. One is to use a procedure named CurStepChanged(CurStep: TSetupStep). In the procedure you can watch for the ssInstall step and start the uninstaller there during upgrades. I was having some problems with this, and instead tried using the the BeforeInstall parameter to launch the uninstaller if an upgrade is detected.

Unfortunately, whenever I try this, the installer fails at the very end with a generic

Setup cannot find the specified file

Anyone experienced this and know the cause or have suggestions for further troubleshooting?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
bobpaul
  • 361
  • 3
  • 12
  • So why are you asking about your unusual way with `BeforeInstall`, rather than asking about your problems with the better `CurStepChanged(ssInstall)`? See [Inno Setup: How to automatically uninstall previous installed version?](https://stackoverflow.com/q/2000296/850848). + Though still, the correct way is to delete the unused files, rather then uninstalling the previous version. + Also note that the uninstaller of 1.1 installed over 1.0 will delete everything, not just 1.1. files. – Martin Prikryl Jul 12 '21 at 14:15
  • `CurStepChange(ssInstall)` has the unfortunate behavior that it is injected AFTER the restart manager dialog but BEFORE the restart manager kills the application. So if you use `CurStepChange(ssInstall)`, then the user is told "The following applications are using files; would you like to close them?" The user then clicks next and the Uninstaller launches (but fails because files are locked) and then the Installer continues, killing the applications responsible for the locks and continues copying the files. – bobpaul Jul 12 '21 at 21:27
  • 1
    Try using UninsIS.dll (see my answer) and use `PrepareToInstall` (rather than `CurStepChange(ssInstall)`. – Bill_Stewart Jul 12 '21 at 21:28
  • @Bill_Stewart if I use `PrepareToInstall` then the `UninsIS` plugin will run before the installer's restart manager checks for locked files, is that correct? – bobpaul Jul 13 '21 at 19:36
  • Per the docs: "You can use this event function to detect and install missing prerequisites and/or to shutdown any application which is about to be updated" and "This function is called before Setup checks for files being in-use if `CloseApplications` is set to `yes`". – Bill_Stewart Jul 13 '21 at 20:08
  • One of the reasons I was trying to use `BeforeInstall` was to take advantage of the installer's Restart Manager killing applications with open files. I do have code that I wrote to kill things before uninstalling, but the Restart Manager is more precise. I'll use your suggestion to use `PrepareToInstall` since at least that won't mislead the user. – bobpaul Jul 15 '21 at 00:57

1 Answers1

2

You are correct that IS does not automatically delete files no longer needed by a previous version when upgrading and that you must do so yourself, and as you noted, one way to handle this issue is to automatically uninstall the previous version before upgrading.

If you are certain you really want to uninstall before upgrading (and/or downgrading), you can use a DLL I wrote for this purpose (requires IS 6.0 or newer):

https://github.com/Bill-Stewart/UninsIS

The Sample Inno Setup Usage section in the documentation on that page explains how to use the DLL in an Inno Setup project. You can decide whether you want to uninstall the existing installed version when either upgrading or downgrading.

Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62