CodeDlg.iss 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. ; -- CodeDlg.iss --
  2. ;
  3. ; This script shows how to insert custom wizard pages into Setup and how to handle
  4. ; these pages. Furthermore it shows how to 'communicate' between the [Code] section
  5. ; and the regular Inno Setup sections using {code:...} constants. Finally it shows
  6. ; how to customize the settings text on the 'Ready To Install' page.
  7. [Setup]
  8. AppName=My Program
  9. AppVersion=1.5
  10. WizardStyle=modern
  11. DisableWelcomePage=no
  12. DefaultDirName={autopf}\My Program
  13. DisableProgramGroupPage=yes
  14. UninstallDisplayIcon={app}\MyProg.exe
  15. OutputDir=userdocs:Inno Setup Examples Output
  16. PrivilegesRequired=lowest
  17. [Files]
  18. Source: "MyProg.exe"; DestDir: "{app}"
  19. Source: "MyProg.chm"; DestDir: "{app}"
  20. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  21. [Registry]
  22. Root: HKA; Subkey: "Software\My Company"; Flags: uninsdeletekeyifempty
  23. Root: HKA; Subkey: "Software\My Company\My Program"; Flags: uninsdeletekey
  24. Root: HKA; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "Name"; ValueData: "{code:GetUser|Name}"
  25. Root: HKA; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "Company"; ValueData: "{code:GetUser|Company}"
  26. Root: HKA; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "DataDir"; ValueData: "{code:GetDataDir}"
  27. ; etc.
  28. [Dirs]
  29. Name: {code:GetDataDir}; Flags: uninsneveruninstall
  30. [Code]
  31. var
  32. UserPage: TInputQueryWizardPage;
  33. UsagePage: TInputOptionWizardPage;
  34. LightMsgPage: TOutputMsgWizardPage;
  35. KeyPage: TInputQueryWizardPage;
  36. ProgressPage: TOutputProgressWizardPage;
  37. DataDirPage: TInputDirWizardPage;
  38. procedure InitializeWizard;
  39. begin
  40. { Create the pages }
  41. UserPage := CreateInputQueryPage(wpWelcome,
  42. 'Personal Information', 'Who are you?',
  43. 'Please specify your name and the company for whom you work, then click Next.');
  44. UserPage.Add('Name:', False);
  45. UserPage.Add('Company:', False);
  46. UsagePage := CreateInputOptionPage(UserPage.ID,
  47. 'Personal Information', 'How will you use My Program?',
  48. 'Please specify how you would like to use My Program, then click Next.',
  49. True, False);
  50. UsagePage.Add('Light mode (no ads, limited functionality)');
  51. UsagePage.Add('Sponsored mode (with ads, full functionality)');
  52. UsagePage.Add('Paid mode (no ads, full functionality)');
  53. LightMsgPage := CreateOutputMsgPage(UsagePage.ID,
  54. 'Personal Information', 'How will you use My Program?',
  55. 'Note: to enjoy all features My Program can offer and to support its development, ' +
  56. 'you can switch to sponsored or paid mode at any time by selecting ''Usage Mode'' ' +
  57. 'in the ''Help'' menu of My Program after the installation has completed.'#13#13 +
  58. 'Click Back if you want to change your usage mode setting now, or click Next to ' +
  59. 'continue with the installation.');
  60. KeyPage := CreateInputQueryPage(UsagePage.ID,
  61. 'Personal Information', 'What''s your registration key?',
  62. 'Please specify your registration key and click Next to continue. If you don''t ' +
  63. 'have a valid registration key, click Back to choose a different usage mode.');
  64. KeyPage.Add('Registration key:', False);
  65. ProgressPage := CreateOutputProgressPage('Personal Information',
  66. 'What''s your registration key?');
  67. DataDirPage := CreateInputDirPage(wpSelectDir,
  68. 'Select Personal Data Directory', 'Where should personal data files be installed?',
  69. 'Select the folder in which Setup should install personal data files, then click Next.',
  70. False, '');
  71. DataDirPage.Add('');
  72. { Set default values, using settings that were stored last time if possible }
  73. UserPage.Values[0] := GetPreviousData('Name', ExpandConstant('{sysuserinfoname}'));
  74. UserPage.Values[1] := GetPreviousData('Company', ExpandConstant('{sysuserinfoorg}'));
  75. case GetPreviousData('UsageMode', '') of
  76. 'light': UsagePage.SelectedValueIndex := 0;
  77. 'sponsored': UsagePage.SelectedValueIndex := 1;
  78. 'paid': UsagePage.SelectedValueIndex := 2;
  79. else
  80. UsagePage.SelectedValueIndex := 1;
  81. end;
  82. DataDirPage.Values[0] := GetPreviousData('DataDir', '');
  83. end;
  84. procedure RegisterPreviousData(PreviousDataKey: Integer);
  85. var
  86. UsageMode: String;
  87. begin
  88. { Store the settings so we can restore them next time }
  89. SetPreviousData(PreviousDataKey, 'Name', UserPage.Values[0]);
  90. SetPreviousData(PreviousDataKey, 'Company', UserPage.Values[1]);
  91. case UsagePage.SelectedValueIndex of
  92. 0: UsageMode := 'light';
  93. 1: UsageMode := 'sponsored';
  94. 2: UsageMode := 'paid';
  95. end;
  96. SetPreviousData(PreviousDataKey, 'UsageMode', UsageMode);
  97. SetPreviousData(PreviousDataKey, 'DataDir', DataDirPage.Values[0]);
  98. end;
  99. function ShouldSkipPage(PageID: Integer): Boolean;
  100. begin
  101. { Skip pages that shouldn't be shown }
  102. if (PageID = LightMsgPage.ID) and (UsagePage.SelectedValueIndex <> 0) then
  103. Result := True
  104. else if (PageID = KeyPage.ID) and (UsagePage.SelectedValueIndex <> 2) then
  105. Result := True
  106. else
  107. Result := False;
  108. end;
  109. function NextButtonClick(CurPageID: Integer): Boolean;
  110. var
  111. I: Integer;
  112. begin
  113. { Validate certain pages before allowing the user to proceed }
  114. if CurPageID = UserPage.ID then begin
  115. if UserPage.Values[0] = '' then begin
  116. MsgBox('You must enter your name.', mbError, MB_OK);
  117. Result := False;
  118. end else begin
  119. if DataDirPage.Values[0] = '' then
  120. DataDirPage.Values[0] := 'C:\' + UserPage.Values[0];
  121. Result := True;
  122. end;
  123. end else if CurPageID = KeyPage.ID then begin
  124. { Just to show how 'OutputProgress' pages work.
  125. Always use a try..finally between the Show and Hide calls as shown below. }
  126. ProgressPage.SetText('Authorizing registration key...', '');
  127. ProgressPage.SetProgress(0, 0);
  128. ProgressPage.Show;
  129. try
  130. for I := 0 to 10 do begin
  131. ProgressPage.SetProgress(I, 10);
  132. Sleep(100);
  133. end;
  134. finally
  135. ProgressPage.Hide;
  136. end;
  137. if GetSHA1OfString('codedlg' + KeyPage.Values[0]) = '8013f310d340dab18a0d0cda2b5b115d2dcd97e4' then
  138. Result := True
  139. else begin
  140. MsgBox('You must enter a valid registration key. (Hint: The key is "inno".)', mbError, MB_OK);
  141. Result := False;
  142. end;
  143. end else
  144. Result := True;
  145. end;
  146. function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo,
  147. MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
  148. var
  149. S: String;
  150. begin
  151. { Fill the 'Ready Memo' with the normal settings and the custom settings }
  152. S := '';
  153. S := S + 'Personal Information:' + NewLine;
  154. S := S + Space + UserPage.Values[0] + NewLine;
  155. if UserPage.Values[1] <> '' then
  156. S := S + Space + UserPage.Values[1] + NewLine;
  157. S := S + NewLine;
  158. S := S + 'Usage Mode:' + NewLine + Space;
  159. case UsagePage.SelectedValueIndex of
  160. 0: S := S + 'Light mode';
  161. 1: S := S + 'Sponsored mode';
  162. 2: S := S + 'Paid mode';
  163. end;
  164. S := S + NewLine + NewLine;
  165. S := S + MemoDirInfo + NewLine;
  166. S := S + Space + DataDirPage.Values[0] + ' (personal data files)' + NewLine;
  167. Result := S;
  168. end;
  169. function GetUser(Param: String): String;
  170. begin
  171. { Return a user value }
  172. { Could also be split into separate GetUserName and GetUserCompany functions }
  173. if Param = 'Name' then
  174. Result := UserPage.Values[0]
  175. else if Param = 'Company' then
  176. Result := UserPage.Values[1];
  177. end;
  178. function GetDataDir(Param: String): String;
  179. begin
  180. { Return the selected DataDir }
  181. Result := DataDirPage.Values[0];
  182. end;