Suppose you are using an Inno Setup project to replace existing files. When running the uninstaller it will delete the new files, instead of the expected behavior of restoring the previous ones.
Here is my implementation of a backup & restore mechanism:
1. For each file to be backed up, add a ‘Check’ parameter with the name of your backup function. This function will be called just before installing the file so we can use it to perform the backup.
2. Implement the backup function to perform the backup. Make sure to return True if everything’s OK and the file can be replaced.
3. Implement the restore function by copying all files from backup to the original location.
4. Call the restore function during uninstall (post-uninstall, after the new files have been removed).
Here is a sample Inno Setup script that implements this mechanism. In this example, the backup function supports backing up the entire folder structure, so restoring them to the original location is easy (using xcopy).