Skip to content

Commit d53e557

Browse files
committed
WIP: Find previous installed CLI
Will detect all occurrences of exercism.exe that might exist in PATH. At this point only deals with the first found. The first found location can optionally become the install location, which will overwrite the old CLI with the latest. More needs to be done to deal with multiple finds of the CLI and if it was installed previously via Chocolatey.
1 parent cb20fee commit d53e557

File tree

3 files changed

+195
-7
lines changed

3 files changed

+195
-7
lines changed

Delphi/Project/ExercismCLIInstaller.dproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes>
9191
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
9292
<DCC_ExeOutput>Win32\Release</DCC_ExeOutput>
93-
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.5.3.3;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.5;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
93+
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.5.3.4;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.5;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys>
9494
<DCC_DcuOutput>Win32\Release</DCC_DcuOutput>
9595
<VerInfo_MinorVer>5</VerInfo_MinorVer>
9696
<VerInfo_Release>3</VerInfo_Release>
97-
<VerInfo_Build>3</VerInfo_Build>
97+
<VerInfo_Build>4</VerInfo_Build>
9898
<VerInfo_PreRelease>true</VerInfo_PreRelease>
9999
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
100100
<AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode>
@@ -167,6 +167,12 @@
167167
<Overwrite>true</Overwrite>
168168
</Platform>
169169
</DeployFile>
170+
<DeployFile LocalName="Win32\Debug\ExercismCLIInstaller.exe" Configuration="Debug" Class="ProjectOutput">
171+
<Platform Name="Win32">
172+
<RemoteName>ExercismCLIInstaller.exe</RemoteName>
173+
<Overwrite>true</Overwrite>
174+
</Platform>
175+
</DeployFile>
170176
<DeployClass Name="AdditionalDebugSymbols">
171177
<Platform Name="iOSSimulator">
172178
<Operation>1</Operation>

Delphi/Project/Source/uInstallLocationFrm.dfm

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ object frmInstallLocation: TfrmInstallLocation
1515
Font.Style = []
1616
OldCreateOrder = False
1717
Position = poScreenCenter
18+
OnActivate = FormActivate
1819
OnCreate = FormCreate
20+
OnDestroy = FormDestroy
1921
PixelsPerInch = 96
2022
TextHeight = 13
2123
object Label3: TLabel
@@ -48,6 +50,79 @@ object frmInstallLocation: TfrmInstallLocation
4850
Caption = 'By clicking &Next you accept the'
4951
Transparent = True
5052
end
53+
object pnlPreexistingCLI: TPanel
54+
Left = 8
55+
Top = 88
56+
Width = 624
57+
Height = 169
58+
ParentBackground = False
59+
ShowCaption = False
60+
TabOrder = 6
61+
Visible = False
62+
object Label6: TLabel
63+
Left = 23
64+
Top = 12
65+
Width = 578
66+
Height = 36
67+
AutoSize = False
68+
Caption =
69+
'A copy of the Exercism CLI has been found already installed on t' +
70+
'his system. Only one copy of the CLI should be installed and al' +
71+
'l other copies removed.'
72+
Font.Charset = DEFAULT_CHARSET
73+
Font.Color = clWindowText
74+
Font.Height = -15
75+
Font.Name = 'Tahoma'
76+
Font.Style = []
77+
ParentFont = False
78+
WordWrap = True
79+
end
80+
object Label7: TLabel
81+
Left = 81
82+
Top = 64
83+
Width = 462
84+
Height = 18
85+
Caption =
86+
'Would you like to install the CLI where the previous version was' +
87+
' found?'
88+
Font.Charset = DEFAULT_CHARSET
89+
Font.Color = clWindowText
90+
Font.Height = -15
91+
Font.Name = 'Tahoma'
92+
Font.Style = []
93+
ParentFont = False
94+
end
95+
object btnYes: TButton
96+
Left = 220
97+
Top = 92
98+
Width = 75
99+
Height = 25
100+
Caption = 'Yes'
101+
Font.Charset = DEFAULT_CHARSET
102+
Font.Color = clWindowText
103+
Font.Height = -15
104+
Font.Name = 'Tahoma'
105+
Font.Style = []
106+
ParentFont = False
107+
TabOrder = 0
108+
OnClick = btnYesClick
109+
end
110+
object btnNo: TButton
111+
Left = 328
112+
Top = 92
113+
Width = 75
114+
Height = 25
115+
Caption = 'No'
116+
Font.Charset = DEFAULT_CHARSET
117+
Font.Color = clWindowText
118+
Font.Height = -15
119+
Font.Name = 'Tahoma'
120+
Font.Style = []
121+
ParentFont = False
122+
TabOrder = 1
123+
OnClick = btnNoClick
124+
end
125+
end
51126
object Panel1: TPanel
52127
Left = 0
53128
Top = 0
@@ -6348,7 +6423,7 @@ object frmInstallLocation: TfrmInstallLocation
63486423
Left = 311
63496424
Top = 193
63506425
Width = 95
6351-
Height = 13
6426+
Height = 17
63526427
Hint =
63536428
'https://github.com/exercism/windows-installer/blob/master/LICENS' +
63546429
'E'

Delphi/Project/Source/uInstallLocationFrm.pas

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
unit uInstallLocationFrm;
2-
{_define SimTLSCheckFailure}
3-
{$define SkipTLSCheck}
42
interface
53

64
uses
75
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
86
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uTypes, Vcl.StdCtrls, Vcl.ExtCtrls,
9-
Vcl.Imaging.pngimage, System.UITypes;
7+
Vcl.Imaging.pngimage, System.Generics.Collections, System.UITypes, Vcl.Buttons;
108

119
type
10+
TCLIPresent = class;
11+
1212
TfrmInstallLocation = class(TForm)
1313
Panel1: TPanel;
1414
Label1: TLabel;
@@ -23,24 +23,53 @@ TfrmInstallLocation = class(TForm)
2323
Image1: TImage;
2424
imgV2Logo: TImage;
2525
LinkLabel1: TLinkLabel;
26+
pnlPreexistingCLI: TPanel;
27+
Label6: TLabel;
28+
Label7: TLabel;
29+
btnYes: TButton;
30+
btnNo: TButton;
2631
procedure btnCancelClick(Sender: TObject);
2732
procedure btnNextClick(Sender: TObject);
2833
procedure btnBrowseClick(Sender: TObject);
2934
procedure FormCreate(Sender: TObject);
3035
procedure LinkLabel1LinkClick(Sender: TObject; const Link: string;
3136
LinkType: TSysLinkType);
37+
procedure FormDestroy(Sender: TObject);
38+
procedure FormActivate(Sender: TObject);
39+
procedure btnYesClick(Sender: TObject);
40+
procedure btnNoClick(Sender: TObject);
3241
private
3342
{ Private declarations }
43+
OldCLIPresent: TCLIPresent;
3444
public
3545
{ Public declarations }
3646
NextClicked: boolean;
3747
end;
3848

49+
TCLIPresent = class
50+
strict private
51+
const
52+
CliFilename = 'exercism.exe';
53+
var
54+
FInstallTo: string;
55+
FListOfFinds: TList<string>;
56+
FIsPresent: Boolean;
57+
FNumberFound: Integer;
58+
function GetPath: string;
59+
public
60+
constructor Create;
61+
destructor Destroy; override;
62+
procedure FindPreexistingCLI;
63+
property InstallTo: string read FInstallTo;
64+
property IsPresent: Boolean read FIsPresent;
65+
property NumberFound: Integer read FNumberFound;
66+
end;
67+
3968
function ShowInstallLocationForm(var aInstallInfo: TInstallInfo): TResultStatus;
4069

4170
implementation
4271
uses
43-
Vcl.FileCtrl, Vcl.ExtActns;
72+
StrUtils, Vcl.FileCtrl, Vcl.ExtActns, Registry;
4473
{$R *.dfm}
4574

4675
function ShowInstallLocationForm(var aInstallInfo: TInstallInfo): TResultStatus;
@@ -105,12 +134,36 @@ procedure TfrmInstallLocation.btnNextClick(Sender: TObject);
105134
end;
106135
end;
107136

137+
procedure TfrmInstallLocation.btnNoClick(Sender: TObject);
138+
begin
139+
pnlPreexistingCLI.Visible := false;
140+
MessageDlg('Please remove all copies of the CLI before attempting to install the latest version.', mtInformation, [mbOk], 0);
141+
btnCancel.Click;
142+
end;
143+
144+
procedure TfrmInstallLocation.FormActivate(Sender: TObject);
145+
begin
146+
OldCLIPresent.FindPreexistingCLI;
147+
if OldCLIPresent.IsPresent then
148+
begin
149+
pnlPreexistingCLI.BringToFront;
150+
pnlPreexistingCLI.Visible := true;
151+
btnNext.Enabled := false;
152+
end;
153+
end;
154+
108155
procedure TfrmInstallLocation.FormCreate(Sender: TObject);
109156
begin
110157
NextClicked := false;
158+
OldCLIPresent := TCLIPresent.Create;
111159
SetWindowLong(Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
112160
end;
113161

162+
procedure TfrmInstallLocation.FormDestroy(Sender: TObject);
163+
begin
164+
OldCLIPresent.DisposeOf;
165+
end;
166+
114167
procedure TfrmInstallLocation.LinkLabel1LinkClick(Sender: TObject;
115168
const Link: string; LinkType: TSysLinkType);
116169
begin
@@ -120,4 +173,58 @@ procedure TfrmInstallLocation.LinkLabel1LinkClick(Sender: TObject;
120173
Browser.DisposeOf;
121174
end;
122175

176+
procedure TfrmInstallLocation.btnYesClick(Sender: TObject);
177+
begin
178+
pnlPreexistingCLI.Visible := false;
179+
fldLocation.Text := OldCLIPresent.InstallTo;
180+
btnNext.Enabled := True;
181+
end;
182+
183+
{ TCLIPresent }
184+
185+
constructor TCLIPresent.Create;
186+
begin
187+
inherited;
188+
FListOfFinds := TList<string>.Create;
189+
end;
190+
191+
destructor TCLIPresent.Destroy;
192+
begin
193+
FListOfFinds.DisposeOf;
194+
inherited;
195+
end;
196+
197+
procedure TCLIPresent.FindPreexistingCLI;
198+
begin
199+
var PathArray := GetPath.Split([';']);
200+
for var aPath in PathArray do
201+
begin
202+
var fixedPath := aPath;
203+
if not fixedPath.EndsWith('\') then
204+
fixedPath := fixedPath + '\';
205+
var LFileToFind := fixedPath + CliFilename;
206+
if FileExists(LFileToFind) then
207+
FListOfFinds.Add(aPath);
208+
end;
209+
FNumberFound := FListOfFinds.Count;
210+
FIsPresent := FNumberFound > 0;
211+
FInstallTo := ifthen(FIsPresent, FListOfFinds[0]);
212+
end;
213+
214+
function TCLIPresent.GetPath: string;
215+
begin
216+
var reg := TRegistry.Create;
217+
try
218+
reg.RootKey := HKEY_CURRENT_USER;
219+
var openResult := reg.OpenKeyReadOnly('Environment');
220+
if openResult then
221+
Result := reg.ReadString('Path')
222+
else
223+
Result := '';
224+
finally
225+
reg.CloseKey;
226+
reg.Free;
227+
end;
228+
end;
229+
123230
end.

0 commit comments

Comments
 (0)