开发者

InnoSetup Uninstall Ask Message - Pascal Coding

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?

Th开发者_StackOverflowank 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.


Possibly related to your question, if you just want to change the uninstall message from "Are you sure you want to completely remove %1 and all of its components?" to something else, you can do this by modifying its message, like

[Messages]
ConfirmUninstall=Are you really really sure you want to remove %1?

ref: http://www.jrsoftware.org/ishelp/index.php?topic=messagessection

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜