-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUMake_Options.pas
184 lines (143 loc) · 5.68 KB
/
UMake_Options.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
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
unit UMake_Options;
interface
uses
UMake_Configuration,
Forms, FileCtrl, RegOpts;
(*****************************************************************************)
(* TOptions
(*****************************************************************************)
type
TOptionsPerformIndex = (perfSuccess, perfFailure);
TOptionsPerformWindow = (perfWindowNone, perfWindowFront, perfWindowClose);
TOptionsPerform = record
RegOptWindow: TRegOptInteger;
RegOptLaunch: TRegOptString;
RegOptSound: TRegOptString;
end;
TOptions = class
public
RegOptDetails: TRegOptBoolean;
RegOptEditor: TRegOptString;
RegOptProjects: TRegOptString;
Perform: array [TOptionsPerformIndex] of TOptionsPerform;
constructor Create;
destructor Destroy; override;
procedure PerformAction(IndexPerform: TOptionsPerformIndex; Form: TCustomForm; Configuration: TConfiguration);
procedure PerformEdit(Configuration: TConfiguration; TextFileError: string; IndexLineError: Integer);
end;
implementation
uses
Registry, Windows, MMSystem, Shellapi, SysUtils, SysTools, RegExpr;
(*****************************************************************************)
(* TOptions
(*****************************************************************************)
constructor TOptions.Create;
const
TextNameProgram = 'Phase\UMake';
TextNameSettingPerform: array [TOptionsPerformIndex] of string = ('Success', 'Failure');
var
IndexPerform: TOptionsPerformIndex;
IndexProject: Integer;
Registry: TRegistry;
TextFileSound: string;
TextNameSetting: string;
TextNameSound: string;
begin
RegOptDetails := TRegOptBoolean.Create(TextNameProgram, 'Details', False);
RegOptEditor := TRegOptString.Create(TextNameProgram, 'Editor', '');
RegOptProjects := TRegOptString.CreateList(TextNameProgram, 'Projects');
for IndexProject := RegOptProjects.ItemCount - 1 downto 0 do
if not DirectoryExists(RegOptProjects[IndexProject].Value) then
RegOptProjects.ItemDelete(IndexProject);
if not DirectoryExists(RegOptProjects.Value) then
RegOptProjects.Value := '';
Registry := TRegistry.Create;
for IndexPerform := Low(TOptionsPerformIndex) to High(TOptionsPerformIndex) do
begin
case IndexPerform of
perfSuccess: TextNameSound := 'SystemExclamation';
perfFailure: TextNameSound := 'SystemHand';
end;
if Registry.OpenKeyReadOnly('\AppEvents\Schemes\Apps\.Default\' + TextNameSound + '\.Current')
then TextFileSound := Registry.ReadString('')
else TextFileSound := '';
TextNameSetting := 'Perform' + TextNameSettingPerform[IndexPerform];
with Perform[IndexPerform] do
begin
RegOptWindow := TRegOptInteger.Create(TextNameProgram, TextNameSetting + 'Window', Integer(perfWindowFront));
RegOptLaunch := TRegOptString .Create(TextNameProgram, TextNameSetting + 'Launch', '');
RegOptSound := TRegOptString .Create(TextNameProgram, TextNameSetting + 'Sound', TextFileSound);
if (RegOptWindow.Value < Integer(Low (TOptionsPerformWindow)))
or (RegOptWindow.Value > Integer(High(TOptionsPerformWindow))) then
RegOptWindow.Value := Integer(perfWindowFront);
end;
end;
Registry.Free;
end;
destructor TOptions.Destroy;
var
IndexPerform: TOptionsPerformIndex;
begin
RegOptDetails.Free;
RegOptEditor.Free;
RegOptProjects.Free;
for IndexPerform := Low(TOptionsPerformIndex) to High(TOptionsPerformIndex) do
begin
with Perform[IndexPerform] do
begin
RegOptWindow.Destroy;
RegOptLaunch.Destroy;
RegOptSound .Destroy;
end;
end;
end;
procedure TOptions.PerformAction(IndexPerform: TOptionsPerformIndex; Form: TCustomForm; Configuration: TConfiguration);
var
TextCommand: string;
OptionsSound: Integer;
begin
with Perform[IndexPerform] do
begin
if Length(Trim(RegOptSound.Value)) > 0 then
begin
OptionsSound := SND_FILENAME;
if TOptionsPerformWindow(RegOptWindow.Value) <> perfWindowClose then
OptionsSound := OptionsSound + SND_ASYNC;
PlaySound(PChar(RegOptSound.Value), 0, OptionsSound);
end;
TextCommand := RegOptLaunch.Value;
if Length(Trim(TextCommand)) > 0 then
begin
TextCommand := ReplaceRegExpr('%package%', TextCommand, Configuration.Package);
TextCommand := ReplaceRegExpr('%packagedir%', TextCommand, Configuration.DirPackage);
TextCommand := ReplaceRegExpr('%gamedir%', TextCommand, Configuration.DirGame);
LaunchProgram(TextCommand);
end;
case TOptionsPerformWindow(RegOptWindow.Value) of
perfWindowClose: begin Form.Hide; Form.Close; end;
perfWindowFront: begin Form.Show; Form.Update; end;
end;
end;
end;
procedure TOptions.PerformEdit(Configuration: TConfiguration; TextFileError: string; IndexLineError: Integer);
var
TextCommand: string;
begin
if Length(RegOptEditor.Value) > 0 then
begin
TextCommand := RegOptEditor.Value;
TextCommand := ReplaceRegExpr('%package%', TextCommand, Configuration.Package);
TextCommand := ReplaceRegExpr('%packagedir%', TextCommand, Configuration.DirPackage);
TextCommand := ReplaceRegExpr('%gamedir%', TextCommand, Configuration.DirGame);
TextCommand := ReplaceRegExpr('%errfile%', TextCommand, GetQuotedParam(TextFileError));
if IndexLineError = 0
then TextCommand := ReplaceRegExpr('%errline%', TextCommand, '1')
else TextCommand := ReplaceRegExpr('%errline%', TextCommand, IntToStr(IndexLineError));
if not LaunchProgram(TextCommand) then
Application.MessageBox('Unable to start specified source code editor.', PChar(Application.Title), MB_ICONERROR);
end
else begin
Application.MessageBox('No source code editor specified.', PChar(Application.Title), MB_ICONERROR)
end;
end;
end.