Skip to content

Commit 86d1e8a

Browse files
committed
Add support for new ICompilerAutoDetect methods
Add methods to ICompilerAutoDetect in Compilers.UGlobals. Implement methods in Compilers.UBorland Update TPersistCompilers in Compilers.UCompilers to persist CanAutoInstall "property" in config file.
1 parent 97411af commit 86d1e8a

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

Src/Compilers.UBorland.pas

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ TBorlandCompiler = class(TCompilerBase)
3535
var
3636
fId: TCompilerID;
3737
{Identifies compiler}
38+
// Flags whether user permits compiler to be auto installed.
39+
fCanAutoInstall: Boolean;
3840
function InstallPathFromReg(const RootKey: HKEY): string;
3941
{Gets compiler install root path from given registry root key, if present.
4042
@param RootKey [in] Given registry root key.
@@ -70,10 +72,35 @@ TBorlandCompiler = class(TCompilerBase)
7072
@param Obj Compiler object to copy.
7173
}
7274
{ ICompilerAutoDetect }
75+
/// <summary>Detects and records path to command line compiler exe file,
76+
/// if compiler is registered as installed.</summary>
77+
/// <returns>Boolean. True if compiler is registered as installed, False
78+
/// otherwise.</returns>
79+
/// <remarks>
80+
/// <para>Does not check if the compiler exe file actually exists.</para>
81+
/// <para>Does not set compiler exe file if compiler is not installed.
82+
/// </para>
83+
/// <para>Method of ICompilerAutoDetect.</para>
84+
/// </remarks>
7385
function DetectExeFile: Boolean;
74-
{Detects and records path to command line compiler if present.
75-
@return True if compiler path found, false otherwise.
76-
}
86+
/// <summary>Checks if the compiler is installed on the user's system.
87+
/// </summary>
88+
/// <returns>Boolean. True if compiler is physically installed, False
89+
/// otherwise.</returns>
90+
/// <remarks>
91+
/// <para>Checks if compiler exe is actually present.</para>
92+
/// <para>Method of ICompilerAutoDetect.</para>
93+
/// </remarks>
94+
function IsInstalled: Boolean;
95+
/// <summary>Checks if the compiler is permitted to be automatically
96+
/// installed.</summary>
97+
/// <remarks>Method of ICompilerAutoDetect.</remarks>
98+
function GetCanAutoInstall: Boolean;
99+
/// <summary>Determines whether the compiler can be automatically
100+
/// installed.</summary>
101+
/// <remarks>Method of ICompilerAutoDetect.</remarks>
102+
procedure SetCanAutoInstall(const Value: Boolean);
103+
77104
{ ICompiler }
78105
function GetDefaultSwitches: string; override;
79106
{Returns default command line switches for compiler.
@@ -97,7 +124,7 @@ implementation
97124

98125
uses
99126
// Delphi
100-
SysUtils, Registry,
127+
SysUtils, Registry, IOUtils,
101128
// Project
102129
UIStringList, UStrUtils, USystemInfo;
103130

@@ -118,6 +145,7 @@ constructor TBorlandCompiler.CreateCopy(const Obj: TBorlandCompiler);
118145
begin
119146
inherited CreateCopy(Obj);
120147
fId := Obj.GetID;
148+
fCanAutoInstall := Obj.GetCanAutoInstall;
121149
end;
122150

123151
procedure TBorlandCompiler.DeleteObjFiles(const Path, Project: string);
@@ -144,6 +172,11 @@ function TBorlandCompiler.DetectExeFile: Boolean;
144172
SetExecFile(ExePath);
145173
end;
146174

175+
function TBorlandCompiler.GetCanAutoInstall: Boolean;
176+
begin
177+
Result := fCanAutoInstall;
178+
end;
179+
147180
function TBorlandCompiler.GetDefaultSwitches: string;
148181
{Returns default command line switches for Borland compilers.
149182
@return Switches separated by commas.
@@ -211,6 +244,15 @@ function TBorlandCompiler.InstallPathFromReg(const RootKey: HKEY): string;
211244
end;
212245
end;
213246

247+
function TBorlandCompiler.IsInstalled: Boolean;
248+
var
249+
ExePath: string;
250+
begin
251+
if not GetExePathIfInstalled(ExePath) then
252+
Exit(False);
253+
Result := TFile.Exists(ExePath, False);
254+
end;
255+
214256
function TBorlandCompiler.SearchDirParams: string;
215257
{One of more parameters that define any search directories to be passed to
216258
compiler on command line.
@@ -228,5 +270,10 @@ function TBorlandCompiler.SearchDirParams: string;
228270
+ ' ' + StrQuoteSpaced('-R' + Dirs.GetText(';', False));
229271
end;
230272

273+
procedure TBorlandCompiler.SetCanAutoInstall(const Value: Boolean);
274+
begin
275+
fCanAutoInstall := Value;
276+
end;
277+
231278
end.
232279

Src/Compilers.UCompilers.pas

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ procedure TPersistCompilers.Load(const Compilers: ICompilers);
328328
// Load search directories
329329
SearchDirNames := Storage.GetStrings('SearchDirCount', 'SearchDir%d');
330330
Compiler.SetSearchDirs(TSearchDirs.Create(SearchDirNames.ToArray));
331+
332+
// Check if compiler can be auto-detected
333+
if Supports(Compiler, ICompilerAutoDetect) then
334+
(Compiler as ICompilerAutoDetect).SetCanAutoInstall(
335+
Storage.GetBoolean('CanAutoInstall', True)
336+
);
331337
end;
332338
end;
333339

@@ -363,6 +369,10 @@ procedure TPersistCompilers.Save(const Compilers: ICompilers);
363369
Storage.SetString('Namespaces', Compiler.GetRTLNamespaces);
364370
SearchDirNames := TIStringList.Create(Compiler.GetSearchDirs.ToStrings);
365371
Storage.SetStrings('SearchDirCount', 'SearchDir%d', SearchDirNames);
372+
if Supports(Compiler, ICompilerAutoDetect) then
373+
Storage.SetBoolean(
374+
'CanAutoInstall', (Compiler as ICompilerAutoDetect).GetCanAutoInstall
375+
);
366376
// save the data
367377
Storage.Save;
368378
end;

Src/Compilers.UGlobals.pas

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ interface
299299
property Count: Integer read GetCount;
300300

301301
/// <summary>Number of compilers installed on this computer and made
302-
/// available CodeSnip.</summary>
302+
/// available to CodeSnip.</summary>
303303
property AvailableCount: Integer read GetAvailableCount;
304304

305305
/// <summary>Checks if any compilers in the list are displayable.</summary>
@@ -327,6 +327,15 @@ interface
327327
/// <summary>Detects and records the full path of the compiler's
328328
/// executable.</summary>
329329
function DetectExeFile: Boolean;
330+
/// <summary>Checks if the compiler is installed on the user's system.
331+
/// </summary>
332+
function IsInstalled: Boolean;
333+
/// <summary>Checks if the compiler is permitted to be automatically
334+
/// installed.</summary>
335+
function GetCanAutoInstall: Boolean;
336+
/// <summary>Determines whether the compiler can be automatically
337+
/// installed.</summary>
338+
procedure SetCanAutoInstall(const Value: Boolean);
330339
end;
331340

332341

0 commit comments

Comments
 (0)