CodeExample1.iss 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ; -- CodeExample1.iss --
  2. ;
  3. ; This script shows various things you can achieve using a [Code] section
  4. [Setup]
  5. AppName=My Program
  6. AppVersion=1.5
  7. DisableWelcomePage=no
  8. DefaultDirName={code:MyConst}\My Program
  9. DefaultGroupName=My Program
  10. UninstallDisplayIcon={app}\MyProg.exe
  11. InfoBeforeFile=Readme.txt
  12. OutputDir=userdocs:Inno Setup Examples Output
  13. [Files]
  14. Source: "MyProg.exe"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.exe'); AfterInstall: AfterMyProgInstall('MyProg.exe')
  15. Source: "MyProg.chm"; DestDir: "{app}"; Check: MyProgCheck; BeforeInstall: BeforeMyProgInstall('MyProg.chm'); AfterInstall: AfterMyProgInstall('MyProg.chm')
  16. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  17. [Icons]
  18. Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
  19. [Code]
  20. var
  21. MyProgChecked: Boolean;
  22. MyProgCheckResult: Boolean;
  23. FinishedInstall: Boolean;
  24. function InitializeSetup(): Boolean;
  25. begin
  26. Log('InitializeSetup called');
  27. Result := MsgBox('InitializeSetup:' #13#13 'Setup is initializing. Do you really want to start setup?', mbConfirmation, MB_YESNO) = idYes;
  28. if Result = False then
  29. MsgBox('InitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  30. end;
  31. procedure InitializeWizard;
  32. begin
  33. Log('InitializeWizard called');
  34. end;
  35. <event('InitializeWizard')>
  36. procedure InitializeWizard2;
  37. begin
  38. Log('InitializeWizard2 called');
  39. end;
  40. procedure DeinitializeSetup();
  41. var
  42. FileName: String;
  43. ResultCode: Integer;
  44. begin
  45. Log('DeinitializeSetup called');
  46. if FinishedInstall then begin
  47. if MsgBox('DeinitializeSetup:' #13#13 'The [Code] scripting demo has finished. Do you want to uninstall My Program now?', mbConfirmation, MB_YESNO) = idYes then begin
  48. FileName := ExpandConstant('{uninstallexe}');
  49. if not Exec(FileName, '', '', SW_SHOWNORMAL, ewNoWait, ResultCode) then
  50. MsgBox('DeinitializeSetup:' #13#13 'Execution of ''' + FileName + ''' failed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  51. end else
  52. MsgBox('DeinitializeSetup:' #13#13 'Ok, bye bye.', mbInformation, MB_OK);
  53. end;
  54. end;
  55. procedure CurStepChanged(CurStep: TSetupStep);
  56. begin
  57. Log('CurStepChanged(' + IntToStr(Ord(CurStep)) + ') called');
  58. if CurStep = ssPostInstall then
  59. FinishedInstall := True;
  60. end;
  61. procedure CurInstallProgressChanged(CurProgress, MaxProgress: Integer);
  62. begin
  63. Log('CurInstallProgressChanged(' + IntToStr(CurProgress) + ', ' + IntToStr(MaxProgress) + ') called');
  64. end;
  65. function NextButtonClick(CurPageID: Integer): Boolean;
  66. var
  67. ResultCode: Integer;
  68. begin
  69. Log('NextButtonClick(' + IntToStr(CurPageID) + ') called');
  70. case CurPageID of
  71. wpSelectDir:
  72. MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);
  73. wpSelectProgramGroup:
  74. MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK);
  75. wpReady:
  76. begin
  77. if MsgBox('NextButtonClick:' #13#13 'Using the script, files can be extracted before the installation starts. For example we could extract ''MyProg.exe'' now and run it.' #13#13 'Do you want to do this?', mbConfirmation, MB_YESNO) = idYes then begin
  78. ExtractTemporaryFile('myprog.exe');
  79. if not ExecAsOriginalUser(ExpandConstant('{tmp}\myprog.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
  80. MsgBox('NextButtonClick:' #13#13 'The file could not be executed. ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
  81. end;
  82. BringToFrontAndRestore();
  83. MsgBox('NextButtonClick:' #13#13 'The normal installation will now start.', mbInformation, MB_OK);
  84. end;
  85. end;
  86. Result := True;
  87. end;
  88. function BackButtonClick(CurPageID: Integer): Boolean;
  89. begin
  90. Log('BackButtonClick(' + IntToStr(CurPageID) + ') called');
  91. Result := True;
  92. end;
  93. function ShouldSkipPage(PageID: Integer): Boolean;
  94. begin
  95. Log('ShouldSkipPage(' + IntToStr(PageID) + ') called');
  96. { Skip wpInfoBefore page; show all others }
  97. case PageID of
  98. wpInfoBefore:
  99. Result := True;
  100. else
  101. Result := False;
  102. end;
  103. end;
  104. procedure CurPageChanged(CurPageID: Integer);
  105. begin
  106. Log('CurPageChanged(' + IntToStr(CurPageID) + ') called');
  107. case CurPageID of
  108. wpWelcome:
  109. MsgBox('CurPageChanged:' #13#13 'Welcome to the [Code] scripting demo. This demo will show you some possibilities of the scripting support.' #13#13 'The scripting engine used is RemObjects Pascal Script by Carlo Kok. See http://www.remobjects.com/ps for more information.', mbInformation, MB_OK);
  110. wpFinished:
  111. MsgBox('CurPageChanged:' #13#13 'Welcome to final page of this demo. Click Finish to exit.', mbInformation, MB_OK);
  112. end;
  113. end;
  114. function PrepareToInstall(var NeedsRestart: Boolean): String;
  115. begin
  116. Log('PrepareToInstall() called');
  117. if MsgBox('PrepareToInstall:' #13#13 'Setup is preparing to install. Using the script you can install any prerequisites, abort Setup on errors, and request restarts. Do you want to return an error now?', mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = idYes then
  118. Result := '<your error text here>.'
  119. else
  120. Result := '';
  121. end;
  122. function MyProgCheck(): Boolean;
  123. begin
  124. Log('MyProgCheck() called');
  125. if not MyProgChecked then begin
  126. MyProgCheckResult := MsgBox('MyProgCheck:' #13#13 'Using the script you can decide at runtime to include or exclude files from the installation. Do you want to install MyProg.exe and MyProg.chm to ' + ExtractFilePath(CurrentFileName) + '?', mbConfirmation, MB_YESNO) = idYes;
  127. MyProgChecked := True;
  128. end;
  129. Result := MyProgCheckResult;
  130. end;
  131. procedure BeforeMyProgInstall(S: String);
  132. begin
  133. Log('BeforeMyProgInstall(''' + S + ''') called');
  134. MsgBox('BeforeMyProgInstall:' #13#13 'Setup is now going to install ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
  135. end;
  136. procedure AfterMyProgInstall(S: String);
  137. begin
  138. Log('AfterMyProgInstall(''' + S + ''') called');
  139. MsgBox('AfterMyProgInstall:' #13#13 'Setup just installed ' + S + ' as ' + CurrentFileName + '.', mbInformation, MB_OK);
  140. end;
  141. function MyConst(Param: String): String;
  142. begin
  143. Log('MyConst(''' + Param + ''') called');
  144. Result := ExpandConstant('{autopf}');
  145. end;