Setup.NewDiskForm.pas 3.6 KB

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