-
Notifications
You must be signed in to change notification settings - Fork 5
/
HGI.GetItCmd.pas
258 lines (225 loc) · 6.56 KB
/
HGI.GetItCmd.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
unit HGI.GetItCmd;
interface
uses
Winapi.Windows, Winapi.ShellAPI, System.Classes, System.SysUtils, HGI.GetItAPI;
type
TFutureId = record
public
const
Delphi = 'delphi';
DelphiWindows = 'delphi_windows';
DelphiMacOS = 'delphi_macos';
DelphiLinux = 'delphi_linux';
DelphiIOS = 'delphi_ios';
DelphiAndroid = 'delphi_android';
CBuilder = 'cbuilder';
CBuilderWindows = 'cbuilder_windows';
CBuilderIOS = 'cbuilder_ios';
CBuilderAndroid = 'cbuilder_android';
French = 'french';
German = 'german';
Japanese = 'japanese';
Samples = 'samples';
Help = 'help';
TeeChart = 'teechart';
DUnit = 'dunit';
InterbaseExpress = 'interbase_express';
Interbase2020 = 'interbase_2020';
OpenJDK = 'openjdk';
AndroidSDK = 'android_sdk';
end;
TGetItCommand = class;
TGetItCmd = class
function Execute(const IDE: TIDEEntity; Command: TGetItCommand): Boolean;
end;
TGetItConfig = (UseOnline, UseOffline);
TGetItCommand = class
protected
FParams: TStringList;
public
/// <summary>
/// Install Item
/// </summary>
function Install(const ItemId: TArray<string>): TGetItCommand;
/// <summary>
/// Install Feature Available ID in TFutureId
/// </summary>
function InstallFeatures(const FeatureId: TArray<string>): TGetItCommand;
/// <summary>
/// Install deferred packages
/// </summary>
function InstallDeferred(const ItemId: TArray<string>): TGetItCommand;
/// <summary>
/// Uninstall Item
/// </summary>
function Uninstall(const ItemId: TArray<string>): TGetItCommand;
/// <summary>
/// Download a file
/// </summary>
function Download(const FileUrl: string): TGetItCommand;
/// <summary>
/// List all available items. Result set depends on sort and filter commands.
/// </summary>
function List(const SearchBy: string): TGetItCommand;
/// <summary>
/// Specifies the sort parameter for the list command. Default is "name". (name/vedor/date)
/// </summary>
function Sort(const Value: string): TGetItCommand;
/// <summary>
/// Specifies the filter parameter for the list command. Default is "installed". (all/installed)
/// </summary>
function Filter(const Value: string): TGetItCommand;
/// <summary>
/// Run an application before exit.
/// </summary>
function RunApp(const AppPath: string): TGetItCommand;
/// <summary>
/// Set up a GetIt system. (useonline/useoffline)
/// </summary>
function Config(const Value: TGetItConfig): TGetItCommand;
/// <summary>
/// User name for proxies with required authentication.
/// </summary>
function UserName(const Value: string): TGetItCommand;
/// <summary>
/// Password for proxies with required authentication.
/// </summary>
function Password(const Value: string): TGetItCommand;
/// <summary>
/// Specifies the verbose level for console output messages. (quiet/minimal/normal/detailed)
/// </summary>
function Verb(const Value: string): TGetItCommand;
/// <summary>
/// The user accepts EULA[s] of downloaded package[s].
/// </summary>
function AcceptEULAs: TGetItCommand;
/// <summary>
/// Do not set environment variables.
/// </summary>
function DoNotSetEnvFile: TGetItCommand;
/// <summary>
/// Print all available commands.
/// </summary>
function Help: TGetItCommand;
///Build line
function Build(AutoFree: Boolean = True): string;
constructor Create;
destructor Destroy; override;
end;
implementation
uses
System.IOUtils, FMX.Dialogs;
{ TGetItCommand }
function TGetItCommand.AcceptEULAs: TGetItCommand;
begin
Result := Self;
FParams.Add('--accepteulas');
end;
function TGetItCommand.Build(AutoFree: Boolean): string;
begin
FParams.Delimiter := ' ';
FParams.QuoteChar := #0;
Result := FParams.DelimitedText;
if AutoFree then
Free;
end;
function TGetItCommand.Config(const Value: TGetItConfig): TGetItCommand;
begin
Result := Self;
case Value of
UseOnline:
FParams.Add('--c=useonline');
UseOffline:
FParams.Add('--c=useoffline');
end;
end;
constructor TGetItCommand.Create;
begin
inherited;
FParams := TStringList.Create;
end;
destructor TGetItCommand.Destroy;
begin
FParams.Free;
inherited;
end;
function TGetItCommand.DoNotSetEnvFile: TGetItCommand;
begin
Result := Self;
FParams.Add('--donotsetenvfile');
end;
function TGetItCommand.Download(const FileUrl: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--download=' + FileUrl);
end;
function TGetItCommand.Filter(const Value: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--filter=' + Value);
end;
function TGetItCommand.Help: TGetItCommand;
begin
Result := Self;
FParams.Add('--help');
end;
function TGetItCommand.Install(const ItemId: TArray<string>): TGetItCommand;
begin
Result := Self;
FParams.Add('--install="' + string.Join(';', ItemId) + '"');
end;
function TGetItCommand.InstallDeferred(const ItemId: TArray<string>): TGetItCommand;
begin
Result := Self;
FParams.Add('--installdeferred="' + string.Join(';', ItemId) + '"');
end;
function TGetItCommand.InstallFeatures(const FeatureId: TArray<string>): TGetItCommand;
begin
Result := Self;
FParams.Add('--install_features="' + string.Join(';', FeatureId) + '"');
end;
function TGetItCommand.List(const SearchBy: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--list=' + SearchBy);
end;
function TGetItCommand.Password(const Value: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--password=' + Value);
end;
function TGetItCommand.RunApp(const AppPath: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--runapp="' + AppPath + '"');
end;
function TGetItCommand.Sort(const Value: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--sort=' + Value);
end;
function TGetItCommand.Uninstall(const ItemId: TArray<string>): TGetItCommand;
begin
Result := Self;
FParams.Add('-u="' + string.Join(';', ItemId) + '"');
end;
function TGetItCommand.UserName(const Value: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--username=' + Value);
end;
function TGetItCommand.Verb(const Value: string): TGetItCommand;
begin
Result := Self;
FParams.Add('--verb=' + Value);
end;
{ TGetItCmd }
function TGetItCmd.Execute(const IDE: TIDEEntity; Command: TGetItCommand): Boolean;
begin
Result := ShellExecute(0, 'open',
PChar(IDE.GetPathGetItCmd),
PChar(Command.Build),
PChar(IDE.GetPathBin),
SW_NORMAL) > SE_ERR_DLLNOTFOUND;
end;
end.