CodePrepareToInstall.iss 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ; -- CodePrepareToInstall.iss --
  2. ;
  3. ; This script shows how the PrepareToInstall event function can be used to
  4. ; install prerequisites and handle any reboots in between, while remembering
  5. ; user selections across reboots.
  6. [Setup]
  7. AppName=My Program
  8. AppVersion=1.5
  9. DefaultDirName={pf}\My Program
  10. DefaultGroupName=My Program
  11. UninstallDisplayIcon={app}\MyProg.exe
  12. OutputDir=userdocs:Inno Setup Examples Output
  13. [Files]
  14. Source: "MyProg.exe"; DestDir: "{app}";
  15. Source: "MyProg.chm"; DestDir: "{app}";
  16. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme;
  17. [Icons]
  18. Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
  19. [Code]
  20. const
  21. (*** Customize the following to your own name. ***)
  22. RunOnceName = 'My Program Setup restart';
  23. QuitMessageReboot = 'The installation of a prerequisite program was not completed. You will need to restart your computer to complete that installation.'#13#13'After restarting your computer, Setup will continue next time an administrator logs in.';
  24. QuitMessageError = 'Error. Cannot continue.';
  25. var
  26. Restarted: Boolean;
  27. function InitializeSetup(): Boolean;
  28. begin
  29. Restarted := ExpandConstant('{param:restart|0}') = '1';
  30. if not Restarted then begin
  31. Result := not RegValueExists(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce', RunOnceName);
  32. if not Result then
  33. MsgBox(QuitMessageReboot, mbError, mb_Ok);
  34. end else
  35. Result := True;
  36. end;
  37. function DetectAndInstallPrerequisites: Boolean;
  38. begin
  39. (*** Place your prerequisite detection and installation code below. ***)
  40. (*** Return False if missing prerequisites were detected but their installation failed, else return True. ***)
  41. //<your code here>
  42. Result := True;
  43. (*** Remove the following block! Used by this demo to simulate a prerequisite install requiring a reboot. ***)
  44. if not Restarted then
  45. RestartReplace(ParamStr(0), '');
  46. end;
  47. function Quote(const S: String): String;
  48. begin
  49. Result := '"' + S + '"';
  50. end;
  51. function AddParam(const S, P, V: String): String;
  52. begin
  53. if V <> '""' then
  54. Result := S + ' /' + P + '=' + V;
  55. end;
  56. function AddSimpleParam(const S, P: String): String;
  57. begin
  58. Result := S + ' /' + P;
  59. end;
  60. procedure CreateRunOnceEntry;
  61. var
  62. RunOnceData: String;
  63. begin
  64. RunOnceData := Quote(ExpandConstant('{srcexe}')) + ' /restart=1';
  65. RunOnceData := AddParam(RunOnceData, 'LANG', ExpandConstant('{language}'));
  66. RunOnceData := AddParam(RunOnceData, 'DIR', Quote(WizardDirValue));
  67. RunOnceData := AddParam(RunOnceData, 'GROUP', Quote(WizardGroupValue));
  68. if WizardNoIcons then
  69. RunOnceData := AddSimpleParam(RunOnceData, 'NOICONS');
  70. RunOnceData := AddParam(RunOnceData, 'TYPE', Quote(WizardSetupType(False)));
  71. RunOnceData := AddParam(RunOnceData, 'COMPONENTS', Quote(WizardSelectedComponents(False)));
  72. RunOnceData := AddParam(RunOnceData, 'TASKS', Quote(WizardSelectedTasks(False)));
  73. (*** Place any custom user selection you want to remember below. ***)
  74. //<your code here>
  75. RegWriteStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce', RunOnceName, RunOnceData);
  76. end;
  77. function PrepareToInstall(var NeedsRestart: Boolean): String;
  78. var
  79. ChecksumBefore, ChecksumAfter: String;
  80. begin
  81. ChecksumBefore := MakePendingFileRenameOperationsChecksum;
  82. if DetectAndInstallPrerequisites then begin
  83. ChecksumAfter := MakePendingFileRenameOperationsChecksum;
  84. if ChecksumBefore <> ChecksumAfter then begin
  85. CreateRunOnceEntry;
  86. NeedsRestart := True;
  87. Result := QuitMessageReboot;
  88. end;
  89. end else
  90. Result := QuitMessageError;
  91. end;
  92. function ShouldSkipPage(PageID: Integer): Boolean;
  93. begin
  94. Result := Restarted;
  95. end;