forked from digao-dalpiaz/CompInstall
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUFrm.pas
More file actions
208 lines (167 loc) · 5.1 KB
/
UFrm.pas
File metadata and controls
208 lines (167 loc) · 5.1 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{------------------------------------------------------------------------------
Component Installer app
Developed by Rodrigo Depine Dalpiaz (digao dalpiaz)
Delphi utility app to auto-install component packages into IDE
https://github.com/digao-dalpiaz/CompInstall
Please, read the documentation at GitHub link.
------------------------------------------------------------------------------}
unit UFrm;
interface
uses Vcl.Forms, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.Buttons,
Vcl.Controls, System.Classes, System.IOUtils,
//
Vcl.Graphics, UDefinitions;
type
TFrm = class(TForm)
LbComponentName: TLabel;
EdCompName: TEdit;
LbDelphiVersion: TLabel;
EdDV: TComboBox;
Ck64bit: TCheckBox;
LbInstallLog: TLabel;
BtnInstall: TBitBtn;
BtnExit: TBitBtn;
M: TRichEdit;
LbVersion: TLabel;
LbDigaoDalpiaz: TLinkLabel;
LbComponentVersion: TLabel;
EdCompVersion: TEdit;
lnklbl1: TLinkLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
procedure BtnInstallClick(Sender: TObject);
procedure LbDigaoDalpiazLinkClick(Sender: TObject; const Link: string;
LinkType: TSysLinkType);
procedure FormShow(Sender: TObject);
private
D: TDefinitions;
DefLoaded: Boolean;
public
procedure LoadDefinitions;
procedure SetNewPackageVersion;
procedure SetButtons(bEnabled: Boolean);
procedure Log(const A: string; bBold: Boolean = True; Color: TColor = clBlack);
end;
var
Frm: TFrm;
G_NewVersion : string;
implementation
{$R *.dfm}
uses System.SysUtils, Vcl.Dialogs, System.UITypes,
Winapi.Windows, Winapi.Messages, Winapi.ShellAPI,
UCommon, UProcess, UGitHub, UDelphiVersionCombo;
procedure TFrm.Log(const A: string; bBold: Boolean = True; Color: TColor = clBlack);
begin
//log text at RichEdit control, with some formatted rules
M.SelStart := Length(M.Text);
if bBold then
M.SelAttributes.Style := [fsBold]
else
M.SelAttributes.Style := [];
M.SelAttributes.Color := Color;
M.SelText := A+#13#10;
SendMessage(M.Handle, WM_VSCROLL, SB_BOTTOM, 0); //scroll to bottom
end;
procedure TFrm.LoadDefinitions;
begin
if G_NewVersion <> '' then
begin
if Assigned(D) then
begin
Log('Write Updated Component Version to INI File...');
SetNewPackageVersion;
end;
end;
if Assigned(D) then D.Free;
DefLoaded := False;
D := TDefinitions.Create;
try
D.LoadIniFile(TPath.Combine(TPath.GetAppPath, INI_FILE_NAME));
EdCompName.Text := D.CompName;
EdCompVersion.Text := D.CompVersion;
TDelphiVersionComboLoader.Load(EdDV, D.DelphiVersions);
Ck64bit.Visible := D.HasAny64bit;
DefLoaded := True;
except
on E: Exception do
Log('Error loading component definitions: '+E.Message, True, clRed);
end;
end;
procedure TFrm.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown := True;
AppDir := ExtractFilePath(Application.ExeName);
G_NewVersion := '';
LoadDefinitions;
end;
procedure TFrm.FormDestroy(Sender: TObject);
begin
D.Free;
TDelphiVersionComboLoader.Clear(EdDV);
end;
procedure TFrm.FormShow(Sender: TObject);
begin
if DefLoaded then
CheckGitHubUpdate(D.GitHubRepository, D.CompVersion);
end;
procedure TFrm.LbDigaoDalpiazLinkClick(Sender: TObject; const Link: string;
LinkType: TSysLinkType);
begin
ShellExecute(0, '', PChar(Link), '', '', SW_SHOWNORMAL);
end;
procedure TFrm.BtnExitClick(Sender: TObject);
begin
Close;
end;
procedure TFrm.BtnInstallClick(Sender: TObject);
var
P: TProcess;
LDelphiVersion : string;
begin
if not DefLoaded then
raise Exception.Create('Component definitions are not loaded');
M.Clear; //clear log
if EdDV.ItemIndex=-1 then
begin
MessageDlg('Select one Delphi version', mtError, [mbOK], 0);
EdDV.SetFocus;
Exit;
end;
//check if Delphi IDE is running
if FindWindow('TAppBuilder', nil)<>0 then
begin
MessageDlg('Please, close Delphi IDE first!', mtError, [mbOK], 0);
Exit;
end;
SetButtons(False);
Refresh;
// Here we know about the selected Delphi Version
//LDelphiVersion := EdDV.Items[EdDV.ItemIndex]; // Long Delphi Name, not Tag from INI File
//LDelphiVersion := TDelphiVersionItem(EdDV.Items.Objects[EdDV.ItemIndex]).InternalNumber; // Version 23.0 for Delphi 12
LDelphiVersion := TDelphiVersionItem(EdDV.Items.Objects[EdDV.ItemIndex]).Iniver;
// Reload Packages to get version specific sections
Log('Reload Packages to get Delphi Version specific Settings with Delphi suffix: ' + LDelphiVersion);
D.ReloadPackages(TPath.Combine(TPath.GetAppPath,INI_FILE_NAME),LDelphiVersion);
P := TProcess.Create(D,
TDelphiVersionItem(EdDV.Items.Objects[EdDV.ItemIndex]).InternalNumber,
Ck64bit.Checked and Ck64bit.Visible);
P.Start;
end;
procedure TFrm.SetButtons(bEnabled: Boolean);
begin
BtnInstall.Enabled := bEnabled;
BtnExit.Enabled := bEnabled;
end;
procedure TFrm.SetNewPackageVersion;
begin
if D.AutoUpdateIniFile then
begin
if D.CompVersion <> G_NewVersion then
begin
D.UpdatedVersion := G_NewVersion;
G_NewVersion := '';
end;
end;
end;
end.