Setup.NewDiskForm.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. unit Setup.NewDiskForm;
  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. New Disk form
  8. }
  9. interface
  10. uses
  11. Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  12. Setup.SetupForm, StdCtrls, ExtCtrls, NewStaticText, BitmapImage, NewCtrls;
  13. type
  14. TNewDiskForm = class(TSetupForm)
  15. DiskBitmapImage: TBitmapImage;
  16. SelectDiskLabel: TNewStaticText;
  17. PathLabel: TNewStaticText;
  18. PathEdit: TNewPathEdit;
  19. BrowseButton: TNewButton;
  20. OKButton: TNewButton;
  21. CancelButton: TNewButton;
  22. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  23. procedure BrowseButtonClick(Sender: TObject);
  24. private
  25. FFilename: string;
  26. function GetSanitizedPath: String;
  27. public
  28. constructor Create(AOwner: TComponent); override;
  29. end;
  30. function SelectDisk(const DiskNumber: Integer; const AFilename: String; var Path: String): Boolean;
  31. implementation
  32. uses
  33. ShellAPI,
  34. PathFunc, BrowseFunc,
  35. Shared.SetupMessageIDs, Shared.CommonFunc.Vcl, Shared.CommonFunc,
  36. SetupLdrAndSetup.Messages, Setup.MainFunc, Setup.MainForm, Setup.WizardForm;
  37. {$R *.DFM}
  38. function SelectDisk(const DiskNumber: Integer; const AFilename: String;
  39. var Path: String): Boolean;
  40. begin
  41. Application.Restore; { see comments in MsgBox }
  42. with TNewDiskForm.Create(Application) do
  43. try
  44. FFilename := AFilename;
  45. SelectDiskLabel.Caption := FmtSetupMessage(msgSelectDiskLabel2, [IntToStr(DiskNumber)]);
  46. PathEdit.Text := Path;
  47. ActiveControl := OKButton;
  48. Result := ShowModal = mrOK;
  49. if Result then
  50. Path := GetSanitizedPath;
  51. finally
  52. Free;
  53. end;
  54. end;
  55. { TNewDiskForm }
  56. constructor TNewDiskForm.Create(AOwner: TComponent);
  57. begin
  58. inherited;
  59. InitializeFont(False, True);
  60. Caption := SetupMessages[msgChangeDiskTitle];
  61. PathLabel.Caption := SetupMessages[msgPathLabel];
  62. BrowseButton.Caption := SetupMessages[msgButtonBrowse];
  63. OKButton.Caption := SetupMessages[msgButtonOK];
  64. CancelButton.Caption := SetupMessages[msgButtonCancel];
  65. DiskBitmapImage.InitializeFromStockIcon(SIID_MEDIABLANKCD, clNone, [48, 64]);
  66. SetForeground := True;
  67. { WizardForm will not exist yet if we're being called from [Code]'s
  68. ExtractTemporaryFile in InitializeSetup }
  69. FlipAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
  70. end;
  71. function TNewDiskForm.GetSanitizedPath: String;
  72. begin
  73. Result := PathExpand(RemoveBackslashUnlessRoot(Trim(PathEdit.Text)));
  74. end;
  75. procedure TNewDiskForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  76. var
  77. Path: String;
  78. begin
  79. case ModalResult of
  80. mrOK: begin
  81. Path := GetSanitizedPath;
  82. if (Path = '') or not NewFileExists(AddBackslash(Path) + FFilename) then begin
  83. CanClose := False;
  84. LoggedMsgBox(FmtSetupMessage(msgFileNotInDir2, [FFilename, Path]),
  85. '', mbError, MB_OK, False, 0);
  86. end;
  87. end;
  88. mrCancel: CanClose := ExitSetupMsgBox;
  89. end;
  90. end;
  91. procedure TNewDiskForm.BrowseButtonClick(Sender: TObject);
  92. var
  93. Dir: String;
  94. begin
  95. Dir := GetSanitizedPath;
  96. if BrowseForFolder(SetupMessages[msgSelectDirectoryLabel], Dir, Handle, False) then
  97. PathEdit.Text := Dir;
  98. end;
  99. end.