IDE.Wizard.WizardFileForm.pas 7.0 KB

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