Setup.NewDiskForm.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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, BidiCtrls;
  13. type
  14. TNewDiskForm = class(TSetupForm)
  15. DiskBitmapImage: TBitmapImage;
  16. SelectDiskLabel: TNewStaticText;
  17. PathLabel: TNewStaticText;
  18. PathEdit: TEdit;
  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. { Private declarations }
  26. Filename: string;
  27. function GetSanitizedPath: String;
  28. procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
  29. public
  30. { Public declarations }
  31. constructor Create(AOwner: TComponent); override;
  32. end;
  33. function SelectDisk(const DiskNumber: Integer; const AFilename: String; var Path: String): Boolean;
  34. implementation
  35. uses
  36. SetupLdrAndSetup.Messages, Shared.SetupMessageIDs, PathFunc, Shared.CommonFunc.Vcl, Shared.CommonFunc, BrowseFunc,
  37. Setup.MainFunc, Setup.MainForm, Setup.WizardForm;
  38. {$R *.DFM}
  39. function SelectDisk(const DiskNumber: Integer; const AFilename: String;
  40. var Path: String): Boolean;
  41. begin
  42. Application.Restore; { see comments in AppMessageBox }
  43. with TNewDiskForm.Create(Application) do
  44. try
  45. Filename := AFilename;
  46. SelectDiskLabel.Caption := FmtSetupMessage(msgSelectDiskLabel2, [IntToStr(DiskNumber)]);
  47. PathEdit.Text := Path;
  48. ActiveControl := OKButton;
  49. Result := ShowModal = mrOK;
  50. if Result then
  51. Path := GetSanitizedPath;
  52. finally
  53. Free;
  54. end;
  55. end;
  56. { TNewDiskForm }
  57. constructor TNewDiskForm.Create(AOwner: TComponent);
  58. begin
  59. inherited;
  60. InitializeFont;
  61. Caption := SetupMessages[msgChangeDiskTitle];
  62. PathLabel.Caption := SetupMessages[msgPathLabel];
  63. BrowseButton.Caption := SetupMessages[msgButtonBrowse];
  64. OKButton.Caption := SetupMessages[msgButtonOK];
  65. CancelButton.Caption := SetupMessages[msgButtonCancel];
  66. DiskBitmapImage.InitializeFromIcon(HInstance, 'Z_DISKICON', Color, [48, 64]); {don't localize}
  67. TryEnableAutoCompleteFileSystem(PathEdit.Handle);
  68. KeepSizeY := True;
  69. { WizardForm will not exist yet if we're being called from [Code]'s
  70. ExtractTemporaryFile in InitializeSetup }
  71. FlipSizeAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
  72. end;
  73. procedure TNewDiskForm.CMShowingChanged(var Message: TMessage);
  74. begin
  75. inherited;
  76. { This usually just makes the taskbar button flash }
  77. if Showing then
  78. SetForegroundWindow(Handle);
  79. end;
  80. function TNewDiskForm.GetSanitizedPath: String;
  81. begin
  82. Result := PathExpand(RemoveBackslashUnlessRoot(Trim(PathEdit.Text)));
  83. end;
  84. procedure TNewDiskForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  85. var
  86. Path: String;
  87. begin
  88. case ModalResult of
  89. mrOK: begin
  90. Path := GetSanitizedPath;
  91. if (Path = '') or not NewFileExists(AddBackslash(Path) + Filename) then begin
  92. CanClose := False;
  93. LoggedMsgBox(FmtSetupMessage(msgFileNotInDir2, [Filename, Path]),
  94. '', mbError, MB_OK, False, 0);
  95. end;
  96. end;
  97. mrCancel: CanClose := ExitSetupMsgBox;
  98. end;
  99. end;
  100. procedure TNewDiskForm.BrowseButtonClick(Sender: TObject);
  101. var
  102. Dir: String;
  103. begin
  104. Dir := GetSanitizedPath;
  105. if BrowseForFolder(SetupMessages[msgSelectDirectoryLabel], Dir, Handle, False) then
  106. PathEdit.Text := Dir;
  107. end;
  108. end.