forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetupTypes.pas
300 lines (276 loc) · 8.08 KB
/
SetupTypes.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
unit SetupTypes;
{
Inno Setup
Copyright (C) 1997-2018 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
Types and functions used by both ISCmplr-only and Setup-only units
}
interface
uses
SysUtils, Classes, Struct;
type
TSetupStep = (ssPreInstall, ssInstall, ssPostInstall, ssDone);
TUninstallStep = (usAppMutexCheck, usUninstall, usPostUninstall, usDone);
const
{ Predefined page identifiers }
wpWelcome = 1;
wpLicense = 2;
wpPassword = 3;
wpInfoBefore = 4;
wpUserInfo = 5;
wpSelectDir = 6;
wpSelectComponents = 7;
wpSelectProgramGroup = 8;
wpSelectTasks = 9;
wpReady = 10;
wpPreparing = 11;
wpInstalling = 12;
wpInfoAfter = 13;
wpFinished = 14;
type
TInstallOnThisVersionResult = (irInstall, irNotOnThisPlatform,
irVersionTooLow, irServicePackTooLow, irVerTooHigh);
TRenamedConstantCallBack = procedure(const Cnst, CnstRenamed: String) of object;
const
crHand = 1;
CodeRootKeyFlagMask = $7F000000;
CodeRootKeyFlag32Bit = $01000000;
CodeRootKeyFlag64Bit = $02000000;
CodeRootKeyValidFlags = CodeRootKeyFlag32Bit or CodeRootKeyFlag64Bit;
HKEY_AUTO = 1; { Any value will work as long as it isn't 0 and doesn't match a predefined key handle (8xxxxxxx) nor includes any of the CodeRootKeyValidFlags flags. }
function StringsToCommaString(const Strings: TStrings): String;
procedure SetStringsFromCommaString(const Strings: TStrings; const Value: String);
function StrToSetupVersionData(const S: String; var VerData: TSetupVersionData): Boolean;
procedure HandleRenamedConstants(var Cnst: String; const RenamedConstantCallback: TRenamedConstantCallback);
implementation
uses
CmnFunc2;
function QuoteStringIfNeeded(const S: String): String;
{ Used internally by StringsToCommaString. Adds quotes around the string if
needed, and doubles any embedded quote characters.
Note: No lead byte checking is done since spaces/commas/quotes aren't used
as trail bytes in any of the Far East code pages (CJK). }
var
Len, QuoteCount, I: Integer;
HasSpecialChars: Boolean;
P: PChar;
begin
Len := Length(S);
HasSpecialChars := False;
QuoteCount := 0;
for I := 1 to Len do begin
case S[I] of
#0..' ', ',': HasSpecialChars := True;
'"': Inc(QuoteCount);
end;
end;
if not HasSpecialChars and (QuoteCount = 0) then begin
Result := S;
Exit;
end;
SetString(Result, nil, Len + QuoteCount + 2);
P := Pointer(Result);
P^ := '"';
Inc(P);
for I := 1 to Len do begin
if S[I] = '"' then begin
P^ := '"';
Inc(P);
end;
P^ := S[I];
Inc(P);
end;
P^ := '"';
end;
function StringsToCommaString(const Strings: TStrings): String;
{ Creates a comma-delimited string from Strings.
Note: Unlike Delphi 2's TStringList.CommaText property, this function can
handle an unlimited number of characters. }
var
I: Integer;
S: String;
begin
if (Strings.Count = 1) and (Strings[0] = '') then
Result := '""'
else begin
Result := '';
for I := 0 to Strings.Count-1 do begin
S := QuoteStringIfNeeded(Strings[I]);
if I = 0 then
Result := S
else
Result := Result + ',' + S;
end;
end;
end;
procedure SetStringsFromCommaString(const Strings: TStrings; const Value: String);
{ Replaces Strings with strings from the comma- or space-delimited Value.
Note: No lead byte checking is done since spaces/commas/quotes aren't used
as trail bytes in any of the Far East code pages (CJK).
Also, this isn't bugged like Delphi 3+'s TStringList.CommaText property --
SetStringsFromCommaString(..., 'a,') will add two items, not one. }
var
P, PStart, PDest: PChar;
CharCount: Integer;
S: String;
begin
Strings.BeginUpdate;
try
Strings.Clear;
P := PChar(Value);
while CharInSet(P^, [#1..' ']) do
Inc(P);
if P^ <> #0 then begin
while True do begin
if P^ = '"' then begin
Inc(P);
PStart := P;
CharCount := 0;
while P^ <> #0 do begin
if P^ = '"' then begin
Inc(P);
if P^ <> '"' then Break;
end;
Inc(CharCount);
Inc(P);
end;
P := PStart;
SetString(S, nil, CharCount);
PDest := Pointer(S);
while P^ <> #0 do begin
if P^ = '"' then begin
Inc(P);
if P^ <> '"' then Break;
end;
PDest^ := P^;
Inc(P);
Inc(PDest);
end;
end
else begin
PStart := P;
while (P^ > ' ') and (P^ <> ',') do
Inc(P);
SetString(S, PStart, P - PStart);
end;
Strings.Add(S);
while CharInSet(P^, [#1..' ']) do
Inc(P);
if P^ = #0 then
Break;
if P^ = ',' then begin
repeat
Inc(P);
until not CharInSet(P^, [#1..' ']);
end;
end;
end;
finally
Strings.EndUpdate;
end;
end;
function StrToSetupVersionData(const S: String; var VerData: TSetupVersionData): Boolean;
procedure Split(const Str: String; var Ver: TSetupVersionDataVersion;
var ServicePack: Word);
var
I, J: Integer;
Z, B: String;
HasBuild: Boolean;
begin
Cardinal(Ver) := 0;
ServicePack := 0;
Z := Lowercase(Str);
I := Pos('sp', Z);
if I <> 0 then begin
J := StrToInt(Copy(Z, I+2, Maxint));
if (J < Low(Byte)) or (J > High(Byte)) then
Abort;
ServicePack := J shl 8;
{ ^ Shift left 8 bits because we're setting the "major" service pack
version number. This parser doesn't currently accept "minor" service
pack version numbers. }
SetLength(Z, I-1);
end;
I := Pos('.', Z);
if I = Length(Z) then Abort;
if I <> 0 then begin
J := StrToInt(Copy(Z, 1, I-1));
if (J < 0) or (J > 127) then
Abort;
Ver.Major := J;
Z := Copy(Z, I+1, Maxint);
I := Pos('.', Z);
HasBuild := I <> 0;
if not HasBuild then
I := Length(Z)+1;
B := Copy(Z, I+1, Maxint);
Z := Copy(Z, 1, I-1);
J := StrToInt(Z);
if (J < 0) or (J > 99) then Abort;
Ver.Minor := J;
if HasBuild then begin
J := StrToInt(B);
if (J < Low(Ver.Build)) or (J > High(Ver.Build)) then
Abort;
Ver.Build := J;
end;
end
else begin { no minor version specified }
J := StrToInt(Z);
if (J < 0) or (J > 127) then
Abort;
Ver.Major := J;
end;
end;
var
I: Integer;
SP: Word;
begin
try
VerData.WinVersion := 0;
I := Pos(',', S);
if I <> 0 then begin
Split(Trim(Copy(S, 1, I-1)),
TSetupVersionDataVersion(VerData.WinVersion), SP);
if SP <> 0 then Abort; { only NT has service packs }
end;
Split(Trim(Copy(S, I+1, Maxint)),
TSetupVersionDataVersion(VerData.NTVersion), VerData.NTServicePack);
Result := True;
except
if (ExceptObject is EAbort) or (ExceptObject is EConvertError) then
Result := False
else
raise;
end;
end;
procedure HandleRenamedConstants(var Cnst: String; const RenamedConstantCallback: TRenamedConstantCallback);
var
CnstRenamed: String;
begin
if Cnst = 'fonts' then
CnstRenamed := 'commonfonts'
else if Cnst = 'sendto' then
CnstRenamed := 'usersendto'
else if Cnst = 'pf' then
CnstRenamed := 'commonpf'
else if Cnst = 'pf32' then
CnstRenamed := 'commonpf32'
else if Cnst = 'pf64' then
CnstRenamed := 'commonpf64'
else if Cnst = 'cf' then
CnstRenamed := 'commoncf'
else if Cnst = 'cf32' then
CnstRenamed := 'commoncf32'
else if Cnst = 'cf64' then
CnstRenamed := 'commoncf64'
else
CnstRenamed := '';
if CnstRenamed <> '' then begin
if Assigned(RenamedConstantCallback) then
RenamedConstantCallback(Cnst, CnstRenamed);
Cnst := CnstRenamed;
end;
end;
end.