-
Notifications
You must be signed in to change notification settings - Fork 2
/
OTA.SetOEMDir.pas
108 lines (87 loc) · 2.79 KB
/
OTA.SetOEMDir.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
unit OTA.SetOEMDir;
{$WARN UNIT_PLATFORM OFF}
interface
uses
ToolsAPI;
type
TSetOEMDir = class(TNotifierObject, IOTAIDENotifier, IOTAIDENotifier50)
private
function GetOEMDir(const aFileName: string; out aOEMDir: string): Boolean;
protected
procedure FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
procedure AfterCompile(Succeeded: Boolean); overload;
procedure BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean;
var Cancel: Boolean); overload;
procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean); overload;
public
end;
implementation
uses Classes, FileCtrl, SysUtils, OTA.IDE;
resourcestring
StrOEMDir = 'OEMDir';
procedure TSetOEMDir.AfterCompile(Succeeded: Boolean);
begin
end;
procedure TSetOEMDir.AfterCompile(Succeeded, IsCodeInsight: Boolean);
begin
end;
procedure TSetOEMDir.BeforeCompile(const Project: IOTAProject;
IsCodeInsight: Boolean; var Cancel: Boolean);
var sOEMDir, sEnvOEMDir: string;
M: IOTAModuleServices;
begin
if IsCodeInsight then Exit;
M := BorlandIDEServices as IOTAModuleServices;
if GetOEMDir(M.MainProjectGroup.FileName, sOEMDir) then begin
sEnvOEMDir := GetEnvironmentVariable(StrOEMDir);
if sEnvOEMDir <> sOEMDir then
TOTAUtil.SetVariable(StrOEMDir, sOEMDir);
end;
end;
procedure TSetOEMDir.BeforeCompile(const Project: IOTAProject;
var Cancel: Boolean);
begin
end;
procedure TSetOEMDir.FileNotification(NotifyCode: TOTAFileNotification;
const FileName: string; var Cancel: Boolean);
var sExt: string;
sGroup, sProj: string;
sOEMDir: string;
begin
if NotifyCode = ofnFileOpening then begin
sExt := ExtractFileExt(FileName);
sGroup := {$if CompilerVersion<=18} '.bdsgroup' {$else} '.groupproj' {$ifend};
sProj := {$if CompilerVersion<=18} '.bdsproj' {$else} '.dproj' {$ifend};
if SameText(sExt, sGroup) or SameText(sExt, sProj) then begin
if GetOEMDir(FileName, sOEMDir) then
TOTAUtil.SetVariable(StrOEMDir, sOEMDir);
end;
end;
Cancel := False;
end;
function TSetOEMDir.GetOEMDir(const aFileName: string; out aOEMDir: string):
Boolean;
var N: TStringList;
sIniFile, sOEM, sBranch: string;
begin
Result := False;
if TOTAUtil.GetSetupIni(aFileName, sIniFile) then begin
N := TStringList.Create;
try
N.CaseSensitive := False;
N.LoadFromFile(sIniFile);
sOEM := N.Values['OEM'];
if sOEM = '' then sOEM := 'developer';
sBranch := N.Values['Branch'];
if sBranch <> '' then
sBranch := '.' + sBranch;
aOEMDir := Format('..\..\oem%s\%s', [sBranch, sOEM]);
Result := True;
finally
N.Free;
end;
end;
end;
end.