CodeDlg.iss 7.2 KB

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