2
0

IDE.Wizard.WizardFileForm.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. unit IDE.Wizard.WizardFileForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Compiler IDE Script Wizard File form
  8. }
  9. interface
  10. uses
  11. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12. UIStateForm, StdCtrls, ExtCtrls, NewStaticText;
  13. type
  14. TWizardFileOption = (foDownload, foExtractArchive, foRecurseSubDirs, foCreateAllSubDirs);
  15. TWizardFileOptions = set of TWizardFileOption;
  16. PWizardFile = ^TWizardFile;
  17. TWizardFile = record
  18. Source: String;
  19. Options: TWizardFileOptions;
  20. DestRootDir: String;
  21. DestRootDirIsConstant: Boolean;
  22. DestSubDir: String;
  23. DestName: String;
  24. ExternalSize: Int64;
  25. { Don't forget to initialize new fields in TWizardFormFilesHelper.AddWizardFile }
  26. end;
  27. TWizardFileForm = class(TUIStateForm)
  28. OKButton: TButton;
  29. CancelButton: TButton;
  30. GroupBox2: TGroupBox;
  31. DestRootDirComboBox: TComboBox;
  32. DestRootDirEdit: TEdit;
  33. DestRootDirLabel: TNewStaticText;
  34. DestSubDirEdit: TEdit;
  35. DestSubDirLabel: TNewStaticText;
  36. RequiredLabel1: TNewStaticText;
  37. RequiredLabel2: TNewStaticText;
  38. GroupBox1: TGroupBox;
  39. SourceLabel: TNewStaticText;
  40. SourceEdit: TEdit;
  41. RecurseSubDirsCheck: TCheckBox;
  42. CreateAllSubDirsCheck: TCheckBox;
  43. ExtractArchiveCheck: TCheckBox;
  44. DestNameLabel: TNewStaticText;
  45. DestNameEdit: TEdit;
  46. procedure OKButtonClick(Sender: TObject);
  47. procedure FormCreate(Sender: TObject);
  48. procedure DestRootDirComboBoxChange(Sender: TObject);
  49. procedure CheckClick(Sender: TObject);
  50. private
  51. FAllowAppDestRootDir: Boolean;
  52. FWizardFile: PWizardFile;
  53. procedure SetWizardFile(WizardFile: PWizardFile);
  54. procedure UpdateUI;
  55. public
  56. property AllowAppDestRootDir: Boolean write FAllowAppDestRootDir;
  57. property WizardFile: PWizardFile write SetWizardFile;
  58. end;
  59. implementation
  60. uses
  61. IDE.Messages, Shared.CommonFunc.Vcl, Shared.CommonFunc, IDE.HelperFunc;
  62. {$R *.DFM}
  63. type
  64. TConstant = record
  65. Constant, Description: String;
  66. end;
  67. const
  68. DestRootDirs: array[0..6] of TConstant =
  69. (
  70. ( Constant: '{app}'; Description: 'Application directory'),
  71. ( Constant: '{autopf}'; Description: 'Program Files directory'),
  72. ( Constant: '{autocf}'; Description: 'Common Files directory'),
  73. ( Constant: '{win}'; Description: 'Windows directory'),
  74. ( Constant: '{sys}'; Description: 'Windows system directory'),
  75. ( Constant: '{src}'; Description: 'Setup source directory'),
  76. ( Constant: '{sd}'; Description: 'System drive root directory')
  77. );
  78. procedure MakeBold(const Ctl: TNewStaticText);
  79. begin
  80. Ctl.Font.Style := [fsBold];
  81. end;
  82. procedure TWizardFileForm.SetWizardFile(WizardFile: PWizardFile);
  83. var
  84. I: Integer;
  85. begin
  86. FWizardFile := WizardFile;
  87. if foDownload in WizardFile.Options then begin
  88. SourceLabel.Caption := '&Source URL:';
  89. SourceEdit.Text := Format('%s (~%.1f MB)', [WizardFile.Source, WizardFile.ExternalSize/(1024*1024)]);
  90. MakeBold(DestNameLabel);
  91. end else begin
  92. SourceEdit.Text := WizardFile.Source;
  93. if NewFileExists(WizardFile.Source) then
  94. RecurseSubDirsCheck.Enabled := False;
  95. ExtractArchiveCheck.Visible := False;
  96. if IsWildcard(WizardFile.Source) then begin
  97. DestNameLabel.Enabled := False;
  98. DestNameEdit.Color := clBtnFace;
  99. DestNameEdit.ReadOnly := True;
  100. end;
  101. end;
  102. ExtractArchiveCheck.Checked := foExtractArchive in WizardFile.Options;
  103. RecurseSubDirsCheck.Checked := foRecurseSubDirs in WizardFile.Options;
  104. CreateAllSubDirsCheck.Checked := foCreateAllSubDirs in WizardFile.Options;
  105. if WizardFile.DestRootDirIsConstant then begin
  106. for I := Low(DestRootDirs) to High(DestRootDirs) do begin
  107. if DestRootDirs[I].Constant = WizardFile.DestRootDir then begin
  108. DestRootDirComboBox.ItemIndex := I;
  109. Break;
  110. end;
  111. end;
  112. end else begin
  113. DestRootDirComboBox.ItemIndex := DestRootDirComboBox.Items.Count-1;
  114. DestRootDirEdit.Text := WizardFile.DestRootDir;
  115. end;
  116. DestSubDirEdit.Text := WizardFile.DestSubDir;
  117. DestNameEdit.Text := WizardFile.DestName;
  118. UpdateUI;
  119. end;
  120. { --- }
  121. procedure TWizardFileForm.FormCreate(Sender: TObject);
  122. var
  123. I: Integer;
  124. begin
  125. InitFormFont(Self);
  126. InitFormTheme(Self);
  127. MakeBold(SourceLabel);
  128. MakeBold(DestRootDirLabel);
  129. MakeBold(RequiredLabel1);
  130. RequiredLabel2.Left := RequiredLabel1.Left + RequiredLabel1.Width;
  131. for I := Low(DestRootDirs) to High(DestRootDirs) do
  132. DestRootDirComboBox.Items.Add(DestRootDirs[I].Description);
  133. DestRootDirComboBox.Items.Add('(Custom)');
  134. DestRootDirComboBox.ItemIndex := 0;
  135. end;
  136. { --- }
  137. procedure TWizardFileForm.UpdateUI;
  138. begin
  139. if foDownload in FWizardFile.Options then
  140. RecurseSubDirsCheck.Enabled := ExtractArchiveCheck.Checked;
  141. CreateAllSubDirsCheck.Enabled := RecurseSubDirsCheck.Enabled and RecurseSubDirsCheck.Checked;
  142. if DestRootDirComboBox.ItemIndex = DestRootDirComboBox.Items.Count-1 then begin
  143. DestRootDirEdit.Enabled := True;
  144. DestRootDirEdit.Color := clWindow;
  145. end else begin
  146. DestRootDirEdit.Enabled := False;
  147. DestRootDirEdit.Color := clBtnFace;
  148. end;
  149. end;
  150. { --- }
  151. procedure TWizardFileForm.CheckClick(Sender: TObject);
  152. begin
  153. if (Sender = ExtractArchiveCheck) and ExtractArchiveCheck.Checked then begin
  154. RecurseSubDirsCheck.Checked := True;
  155. CreateAllSubDirsCheck.Checked := True;
  156. end;
  157. UpdateUI;
  158. end;
  159. procedure TWizardFileForm.DestRootDirComboBoxChange(Sender: TObject);
  160. begin
  161. UpdateUI;
  162. if DestRootDirEdit.Enabled then
  163. ActiveControl := DestRootDirEdit;
  164. end;
  165. procedure TWizardFileForm.OKButtonClick(Sender: TObject);
  166. var
  167. DestRootDirIndex: Integer;
  168. begin
  169. ModalResult := mrNone;
  170. DestRootDirIndex := DestRootDirComboBox.ItemIndex;
  171. if (DestRootDirIndex = DestRootDirComboBox.Items.Count-1) and (DestRootDirEdit.Text = '') then begin
  172. MsgBox(SWizardFileDestRootDirError, '', mbError, MB_OK);
  173. ActiveControl := DestRootDirEdit;
  174. end else if (DestRootDirs[DestRootDirIndex].Constant = '{app}') and not FAllowAppDestRootDir then begin
  175. MsgBox(SWizardFileAppDestRootDirError, '', mbError, MB_OK);
  176. ActiveControl := DestRootDirComboBox;
  177. end else
  178. ModalResult := mrOk;
  179. if ModalResult = mrOk then begin
  180. FWizardFile.Options := FWizardFile.Options * [foDownload];
  181. if ExtractArchiveCheck.Checked then
  182. Include(FWizardFile.Options, foExtractArchive);
  183. if RecurseSubDirsCheck.Checked then
  184. Include(FWizardFile.Options, foRecurseSubDirs);
  185. if CreateAllSubDirsCheck.Checked then
  186. Include(FWizardFile.Options, foCreateAllSubDirs);
  187. if DestRootDirIndex = DestRootDirComboBox.Items.Count-1 then begin
  188. FWizardFile.DestRootDir := DestRootDirEdit.Text;
  189. FWizardFile.DestRootDirIsConstant := False;
  190. end else begin
  191. FWizardFile.DestRootDir := DestRootDirs[DestRootDirIndex].Constant;
  192. FWizardFile.DestRootDirIsConstant := True;
  193. end;
  194. FWizardFile.DestSubDir := DestSubDirEdit.Text;
  195. FWizardFile.DestName := DestNameEdit.Text;
  196. end;
  197. end;
  198. end.