Skip to content
Advertisement

Inno Setup: Removing files installed by previous version

I’m using Inno Setup to package a Java application for Windows; the application tree is like this:

JavaScript

I use Ant to prepare the whole tree (all the files and folders) beforehand, including the lib directory (using *.jar wildcard to copy the dependencies), then I simply call ISCC with:

JavaScript

Now, I need to cleanup the lib directory everytime the user upgrades the application because I want to remove any obsolete dependencies. I could add the following section to my .iss file:

JavaScript

but I’m not feeling safe because if a user decides to install the application in an existing folder that contains a not-empty lib subfolder (rare but not impossible), there is a chance that some user files are deleted on upgrade.

Is there any best practice to avoid this kind of troubles? Do other installers take care of these headaches? Thanks.

Advertisement

Answer

You can uninstall the previous version before the installation:


If you cannot do a complete uninstallation, you would have to implement a partial uninstallation.

Ideal would be to reverse-engineer the uninstaller log (unins000.dat), extract only installations to the lib subfolder and process (undo) them. But as that is an undocumented binary file, it can be difficult to do.


If you maintain an explicit list of files to be installed in the [Files] section, like

JavaScript

then whenever a dependency changes, move the previous version to the [InstallDelete] section:

JavaScript

If you install the dependencies using a wildcard,

JavaScript

and you cannot reverse-engineer the uninstaller log, you would have to replicate its functionality by your own means.

You can use a preprocessor to generate a file with installed dependencies. Install that file to the {app} folder and process the file before installation.

JavaScript
JavaScript

Another approach is to delete all files in the installation folder that is not installed by the latest installer.

The easiest solution is to delete all files in the installation folder before the installation.

You can use [InstallDelete] section for that. But if you have some folder/files with configuration in the installation folder, it won’t allow you to exclude them.

You can code that Pascal Scripting instead. See Inno Setup – Delete whole application folder except for data subdirectory. You can call the DelTreeExceptSavesDir function from my answer to the that question from CurStepChanged(ssInstall) event function:

JavaScript

If you really want to delete only obsolete files, to avoid deleting and re-creating existing files, you can use preprocessor to generate a list of files to be installed for the Pascal Scripting and use that to delete only really obsolete files.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement