forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewDisk.pas
124 lines (101 loc) · 3.32 KB
/
NewDisk.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
unit NewDisk;
{
Inno Setup
Copyright (C) 1997-2005 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
New Disk form
$jrsoftware: issrc/Projects/NewDisk.pas,v 1.34 2010/10/22 10:33:26 mlaan Exp $
}
interface
{$I VERSION.INC}
uses
Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms, Dialogs,
SetupForm, StdCtrls, ExtCtrls, NewStaticText, BitmapImage, BidiCtrls;
type
TNewDiskForm = class(TSetupForm)
DiskBitmapImage: TBitmapImage;
SelectDiskLabel: TNewStaticText;
PathLabel: TNewStaticText;
PathEdit: TEdit;
BrowseButton: TNewButton;
OKButton: TNewButton;
CancelButton: TNewButton;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure BrowseButtonClick(Sender: TObject);
private
{ Private declarations }
Filename: string;
function GetSanitizedPath: String;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
end;
function SelectDisk(const DiskNumber: Integer; const AFilename: String; var Path: String): Boolean;
implementation
uses
Msgs, MsgIDs, PathFunc, CmnFunc, CmnFunc2, BrowseFunc,
Main, Wizard;
{$R *.DFM}
function SelectDisk(const DiskNumber: Integer; const AFilename: String;
var Path: String): Boolean;
begin
with TNewDiskForm.Create(Application) do
try
Filename := AFilename;
SelectDiskLabel.Caption := FmtSetupMessage(msgSelectDiskLabel2, [IntToStr(DiskNumber)]);
PathEdit.Text := Path;
MessageBeep(0);
Result := ShowModal = mrOK;
if Result then
Path := GetSanitizedPath;
finally
Free;
end;
end;
{ TNewDiskForm }
constructor TNewDiskForm.Create(AOwner: TComponent);
begin
inherited;
InitializeFont;
Caption := SetupMessages[msgChangeDiskTitle];
PathLabel.Caption := SetupMessages[msgPathLabel];
BrowseButton.Caption := SetupMessages[msgButtonBrowse];
OKButton.Caption := SetupMessages[msgButtonOK];
CancelButton.Caption := SetupMessages[msgButtonCancel];
DiskBitmapImage.InitializeFromIcon(HInstance, 'Z_DISKICON', Color, [48, 64]); {don't localize}
TryEnableAutoCompleteFileSystem(PathEdit.Handle);
KeepSizeY := True;
{ WizardForm will not exist yet if we're being called from [Code]'s
ExtractTemporaryFile in InitializeSetup }
FlipSizeAndCenterIfNeeded(Assigned(WizardForm), WizardForm, False);
end;
function TNewDiskForm.GetSanitizedPath: String;
begin
Result := PathExpand(RemoveBackslashUnlessRoot(Trim(PathEdit.Text)));
end;
procedure TNewDiskForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
Path: String;
begin
case ModalResult of
mrOK: begin
Path := GetSanitizedPath;
if (Path = '') or not NewFileExists(AddBackslash(Path) + Filename) then begin
CanClose := False;
LoggedMsgBox(FmtSetupMessage(msgFileNotInDir2, [Filename, Path]),
'', mbError, MB_OK, False, 0);
end;
end;
mrCancel: CanClose := ExitSetupMsgBox;
end;
end;
procedure TNewDiskForm.BrowseButtonClick(Sender: TObject);
var
Dir: String;
begin
Dir := GetSanitizedPath;
if BrowseForFolder(SetupMessages[msgSelectDirectoryLabel], Dir, Handle, False) then
PathEdit.Text := Dir;
end;
end.