@@ -35,11 +35,22 @@ 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.
4143 @return Required root path or '' if not compiler not installed.
4244 }
45+ // / <summary>Gets the path to the compiler exe file if the compiler is
46+ // / registered as installed on the user's computer.</summary>
47+ // / <param name="ExePath">string [out] Set to path to compiler executable
48+ // / file. Empty string if compiler not installed.</param>
49+ // / <returns>Boolean. True if compiler is registered as installed or False
50+ // / otherwise.</returns>
51+ // / <remarks>Does not check if compiler exe is actually present, just if
52+ // / it is registered.</remarks>
53+ function GetExePathIfInstalled (out ExePath: string): Boolean;
4354 strict protected
4455 function SearchDirParams : string; override;
4556 { One of more parameters that define any search directories to be passed
@@ -61,10 +72,35 @@ TBorlandCompiler = class(TCompilerBase)
6172 @param Obj Compiler object to copy.
6273 }
6374 { 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>
6485 function DetectExeFile : Boolean;
65- { Detects and records path to command line compiler if present.
66- @return True if compiler path found, false otherwise.
67- }
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+
68104 { ICompiler }
69105 function GetDefaultSwitches : string; override;
70106 { Returns default command line switches for compiler.
@@ -88,7 +124,7 @@ implementation
88124
89125uses
90126 // Delphi
91- SysUtils, Registry,
127+ SysUtils, Registry, IOUtils,
92128 // Project
93129 UIStringList, UStrUtils, USystemInfo;
94130
@@ -109,6 +145,7 @@ constructor TBorlandCompiler.CreateCopy(const Obj: TBorlandCompiler);
109145begin
110146 inherited CreateCopy(Obj);
111147 fId := Obj.GetID;
148+ fCanAutoInstall := Obj.GetCanAutoInstall;
112149end ;
113150
114151procedure TBorlandCompiler.DeleteObjFiles (const Path, Project: string);
@@ -128,17 +165,16 @@ function TBorlandCompiler.DetectExeFile: Boolean;
128165 @return True if compiler path found, false otherwise.
129166 }
130167var
131- InstDir : string; // installation root directory
168+ ExePath : string;
132169begin
133- // try HKLM
134- InstDir := InstallPathFromReg(HKEY_LOCAL_MACHINE);
135- if InstDir = ' ' then
136- // in case install was for user only, try HKCU
137- InstDir := InstallPathFromReg(HKEY_CURRENT_USER);
138- if InstDir = ' ' then
139- Exit(False);
140- SetExecFile(IncludeTrailingPathDelimiter(InstDir) + ' Bin\DCC32.exe' );
141- Result := True;
170+ Result := GetExePathIfInstalled(ExePath);
171+ if Result then
172+ SetExecFile(ExePath);
173+ end ;
174+
175+ function TBorlandCompiler.GetCanAutoInstall : Boolean;
176+ begin
177+ Result := fCanAutoInstall;
142178end ;
143179
144180function TBorlandCompiler.GetDefaultSwitches : string;
@@ -161,6 +197,22 @@ function TBorlandCompiler.GetDefaultSwitches: string;
161197 + ' -$P+' ; // Open string params ON
162198end ;
163199
200+ function TBorlandCompiler.GetExePathIfInstalled (out ExePath: string): Boolean;
201+ var
202+ InstDir: string;
203+ begin
204+ ExePath := ' ' ;
205+ // try HKLM
206+ InstDir := InstallPathFromReg(HKEY_LOCAL_MACHINE);
207+ if InstDir = ' ' then
208+ // in case install was for user only, try HKCU
209+ InstDir := InstallPathFromReg(HKEY_CURRENT_USER);
210+ if InstDir = ' ' then
211+ Exit(False);
212+ ExePath := TPath.Combine(InstDir, ' Bin\DCC32.exe' );
213+ Result := True;
214+ end ;
215+
164216function TBorlandCompiler.GetID : TCompilerID;
165217 { Provides the unique id of the compiler.
166218 @return Compiler id.
@@ -192,6 +244,15 @@ function TBorlandCompiler.InstallPathFromReg(const RootKey: HKEY): string;
192244 end ;
193245end ;
194246
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+
195256function TBorlandCompiler.SearchDirParams : string;
196257 { One of more parameters that define any search directories to be passed to
197258 compiler on command line.
@@ -209,5 +270,10 @@ function TBorlandCompiler.SearchDirParams: string;
209270 + ' ' + StrQuoteSpaced(' -R' + Dirs.GetText(' ;' , False));
210271end ;
211272
273+ procedure TBorlandCompiler.SetCanAutoInstall (const Value : Boolean);
274+ begin
275+ fCanAutoInstall := Value ;
276+ end ;
277+
212278end .
213279
0 commit comments