NewDisk.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. unit NewDisk;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2005 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. New Disk form
  8. $jrsoftware: issrc/Projects/NewDisk.pas,v 1.34 2010/10/22 10:33:26 mlaan Exp $
  9. }
  10. interface
  11. {$I VERSION.INC}
  12. uses
  13. Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  14. SetupForm, StdCtrls, ExtCtrls, NewStaticText, BitmapImage, BidiCtrls;
  15. type
  16. TNewDiskForm = class(TSetupForm)
  17. DiskBitmapImage: TBitmapImage;
  18. SelectDiskLabel: TNewStaticText;
  19. PathLabel: TNewStaticText;
  20. PathEdit: TEdit;
  21. BrowseButton: TNewButton;
  22. OKButton: TNewButton;
  23. CancelButton: TNewButton;
  24. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  25. procedure BrowseButtonClick(Sender: TObject);
  26. private
  27. { Private declarations }
  28. Filename: string;
  29. function GetSanitizedPath: String;
  30. public
  31. { Public declarations }
  32. constructor Create(AOwner: TComponent); override;
  33. end;
  34. function SelectDisk(const DiskNumber: Integer; const AFilename: String; var Path: String): Boolean;
  35. implementation
  36. uses
  37. Msgs, MsgIDs, PathFunc, CmnFunc, CmnFunc2, BrowseFunc,
  38. Main, Wizard;
  39. {$R *.DFM}
  40. function SelectDisk(const DiskNumber: Integer; const AFilename: String;
  41. var Path: String): Boolean;
  42. begin
  43. with TNewDiskForm.Create(Application) do
  44. try
  45. Filename := AFilename;
  46. SelectDiskLabel.Caption := FmtSetupMessage(msgSelectDiskLabel2, [IntToStr(DiskNumber)]);
  47. PathEdit.Text := Path;
  48. MessageBeep(0);
  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. function TNewDiskForm.GetSanitizedPath: String;
  74. begin
  75. Result := PathExpand(RemoveBackslashUnlessRoot(Trim(PathEdit.Text)));
  76. end;
  77. procedure TNewDiskForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  78. var
  79. Path: String;
  80. begin
  81. case ModalResult of
  82. mrOK: begin
  83. Path := GetSanitizedPath;
  84. if (Path = '') or not NewFileExists(AddBackslash(Path) + Filename) then begin
  85. CanClose := False;
  86. LoggedMsgBox(FmtSetupMessage(msgFileNotInDir2, [Filename, Path]),
  87. '', mbError, MB_OK, False, 0);
  88. end;
  89. end;
  90. mrCancel: CanClose := ExitSetupMsgBox;
  91. end;
  92. end;
  93. procedure TNewDiskForm.BrowseButtonClick(Sender: TObject);
  94. var
  95. Dir: String;
  96. begin
  97. Dir := GetSanitizedPath;
  98. if BrowseForFolder(SetupMessages[msgSelectDirectoryLabel], Dir, Handle, False) then
  99. PathEdit.Text := Dir;
  100. end;
  101. end.