I have created an installer for some of my games and I want the uninstaller to ask me if I want to save my game files. Something like this: when I execute the uninstall.exe to ask me 'Do you want to keep all saved games?' YES or NO. If I hit YES my save files remain and my program files are uninstalled and if I hit NO my program files inclusive save files to be uninstalled. What is the PASCAL code for InnoSetup to do this?
Thank you very much!
You can do something like:
; -- UninstallCodeExample1.iss -- ; ; This script shows various things you can achieve using a [Code] section for Uninstall [Setup] AppName=My Program AppVerName=My Program version 1.5 DefaultDirName={pf}\My Program DefaultGroupName=My Program UninstallDisplayIcon={app}\MyProg.exe OutputDir=userdocs:Inno Setup Examples Output
[Files] Source: "MyProg.exe"; DestDir: "{app}" Source: "MyProg.chm"; DestDir: "{app}" Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
[Code] function InitializeUninstall(): Boolean; begin Result := MsgBox('InitializeUninstall:' #13#13 'Uninstall is initializing. Do you really want to start Uninstall?', mbConfirmation, MB_YESNO) = idYes; if Result = False then MsgBox('InitializeUninstall:' #13#13 'Ok, bye bye.', mbInformation, MB_OK); end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); var mRes : integer; begin case CurUninstallStep of usUninstall: begin mRes := MsgBox('Do you want to remove all files?', mbConfirmation, MB_YESNO or MB_DEFBUTTON2) if mRes = IDYES then begin MsgBox ('Really remove the files', mbInformation, MB_OK) DeleteFile('path\filename.ext'); End else MsgBox ('Don''t remove the game files', mbInformation, MB_OK); // ...insert code to perform pre-uninstall tasks here... end; end; end;
You would want to use the latest version of InnoSetup as that's what I tested with. The sample above is based on the UninstallCodeExample.iss included with the InnoSetup compiler.
I added a line of code to show how to delete a file. It calls the DeleteFile function. You would need to add a DeleteFile for each file you want to remove at uninstall that isn't in your [Files] section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With