Change Inno Setup messages from Pascal code

2019-06-03 05:23发布

问题:

I need to change ConfirmUninstall, UninstalledMost (just in case), and UninstalledAll specifically from script to set a condition. Something like this:

if FileExists(ExpandConstant('{app}\Slash.exe')) then
  SetupMessage(msgConfirmUninstall) := FmtMessage(SetupMessage(msgConfirmUninstall), ['Dagon Slasher'])
else if FileExists(ExpandConstant('{app}\Frank.exe')) then
  SetupMessage(msgConfirmUninstall) := FmtMessage(SetupMessage(msgConfirmUninstall), ['Dagon Frankenstein'])
else
  SetupMessage(msgConfirmUninstall) := FmtMessage(SetupMessage(msgConfirmUninstall), ['Dagon Video Tools']);

But this doesn't work. These messages are used in MsgBoxes, so I can't think of any other way. Running in silent mode is not really suitable for me, since setup will run uninstall if the programs (or one of them) has already been installed, so I don't want the user to accidentally uninstall the program by running the setup.

回答1:

You cannot change these. Maybe except for implementing some DLL that watches for new message boxes and updates them as they appear.


Regarding the silent uninstall solution: I do not understand your problem with "setup will run uninstall if the programs (or one of them) has already been installed".

I assume you run the uninstaller only after the user confirms (s)he wants to install the new version, so you actually want to run the uninstaller silently, right?

And anyway, there's nothing that prevents you from running the uninstaller non-silently from your installer, even if the entry in "Add/Remove programs" refers to "silent" installation.


You can use generic messages that covers all setup types:

[Messages]
ConfirmUninstall=Are you sure you want to completely remove this game?

As your uninstall messages depend on a type of the installed application, you can modify the installer to:

  • Create custom "type" page (like a menu) as the very first one.
  • Once the user selects the "type", restart the installer with a custom switch (e.g. /APPTYPE=slasher) and exit.
  • Once the installer is (re-)run with the /APPTYPE, you know from the beginning, what component/type you are installing and hence you can set the AppName accordingly (using a scripted constant).
  • Of course, you skip the custom "type" page.

This is actually not difficult to implement. The only drawback is that the setup window is "recreated" after the user selects the "type".

I've sketched this solution already in my answer to Inno Setup Change AppName based on component(s) selected.