-
Notifications
You must be signed in to change notification settings - Fork 8
/
it_download.iss
404 lines (315 loc) · 13.6 KB
/
it_download.iss
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
[Files]
Source: {#emit ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','InstallPath','')}\itdownload.dll; Flags: dontcopy; DestDir: {tmp}
[Code]
(*
Inno Tools Downloader DLL
Copyright (C) Sherlock Software 2008
Version 0.3.6
Contact:
The author, Nicholas Sherlock, at [email protected].
Comments, questions and suggestions welcome.
Website:
http://www.sherlocksoftware.org/
History:
0.3.6 - Added callback that allows you to decide whether the install can continue
when some downloaded files are missing.
Fixed compatibility with Unicode Inno Setup
Added Spanish translation by lainz (http://lainzblog.blogspot.com/)
Added Greek translation by XhmikosR
0.3.5 - Moved strings used in the updater example to the language file, so that they
may be more easily translated.
Added event functions to support the example of integration with InnoTools tray.
Fixes bugs that could cause the download to hang until
some mouse movements were received.
Allows "detailed mode" to be turned on with ITD_SetOption
Allows the HTTP agent to be set with ITD_SetOption
0.3.4 - Added Brazilian Portuguese translation by Ronaldo Souza
0.3.3 - The "Hilbrand Edskes" release :), lots of suggestions and corrections from him, thank you!
The "Retry" button is now translated.
The "Current file" progress bar is hidden if only one file is being downloaded.
The page's title and description are updated in the case of failed downloads.
Several updates to the translations.
Several small GUI fixes.
0.3.2 - Minor tweaks to the English language file and the translation example script (example4.iss)
Added Dutch translation by Hilbrand Edskes
Added French translation by N�o
0.3.1 - Added language file examples, fixed several missing language strings
Preliminary support for proxy server autodetection
Allows the size of a file to be queried with ITD_GetFileSize
Several small bugfixes
0.3.0 - Properly supports timeouts.
Fixes bug with time remaining.
DLL is required again.
Supports localization through ITD_LoadStrings, ITD_SetString
Add mirrors for files
Post HTTP documents
Quick view and detailed view
0.2.2 - Fixed empty strings '' in calls and added timeouts
0.2.1 - Renamed identifiers to avoid name clashes
0.2.0 - Converted from DLL to pure native code
*)
function ITD_FileCount: integer;
external 'itd_filecount@files:itdownload.dll stdcall';
procedure ITD_Cancel;
external 'itd_cancel@files:itdownload.dll stdcall';
procedure ITD_ClearFiles;
external 'itd_clearfiles@files:itdownload.dll stdcall';
function ITD_GetResultLen: integer;
external 'itd_getresultlen@files:itdownload.dll stdcall';
procedure ITD_Internal_InitUI(HostHwnd: dword);
external 'itd_initui@files:itdownload.dll stdcall';
function ITD_Internal_GetString(index: integer): boolean;
external 'itd_getstring@files:itdownload.dll stdcall';
function ITD_Internal_DownloadFiles(surface: hwnd): integer;
external 'itd_downloadfiles@files:itdownload.dll stdcall';
#IF DEFINED(UNICODE)
function ITD_DownloadFile(url:string; destfilename:String): integer;
external 'itd_downloadfileW@files:itdownload.dll stdcall';
procedure ITD_GetResultString(buffer: string; maxlen: integer);
external 'itd_getresultstringW@files:itdownload.dll stdcall';
function ITD_Internal_IsDownloadComplete(filename:string):boolean;
external 'itd_isdownloadcompleteW@files:itdownload.dll stdcall';
function ITD_Internal_LoadStrings(filename: string): boolean;
external 'itd_loadstringsW@files:itdownload.dll stdcall';
procedure ITD_Internal_SetOption(option, value: string);
external 'itd_setoptionW@files:itdownload.dll stdcall';
function ITD_Internal_GetFileSize(url: string; var size: Cardinal): boolean;
external 'itd_getfilesizeW@files:itdownload.dll stdcall';
function ITD_Internal_GetOption(option: string; buffer: string; length: integer): integer;
external 'itd_getoptionW@files:itdownload.dll stdcall';
procedure ITD_Internal_SetString(index: integer; value: string);
external 'itd_setstringW@files:itdownload.dll stdcall';
procedure ITD_Internal_AddFile(url: string; destfilename: string);
external 'itd_addfileW@files:itdownload.dll stdcall';
procedure ITD_Internal_AddMirror(url: string; destfilename: string);
external 'itd_addmirrorW@files:itdownload.dll stdcall';
procedure ITD_Internal_AddFileSize(url: string; destfilename: string; size: integer);
external 'itd_addfilesizeW@files:itdownload.dll stdcall';
function ITD_Internal_PostPage(url: String; data:AnsiString; length: integer): boolean;
external 'itd_postpageW@files:itdownload.dll stdcall';
#ELSE
function ITD_DownloadFile(url:string; destfilename:String): integer;
external 'itd_downloadfileA@files:itdownload.dll stdcall';
procedure ITD_GetResultString(buffer: string; maxlen: integer);
external 'itd_getresultstringA@files:itdownload.dll stdcall';
function ITD_Internal_IsDownloadComplete(filename:string):boolean;
external 'itd_isdownloadcompleteA@files:itdownload.dll stdcall';
function ITD_Internal_LoadStrings(filename: string): boolean;
external 'itd_loadstringsA@files:itdownload.dll stdcall';
procedure ITD_Internal_SetOption(option, value: string);
external 'itd_setoptionA@files:itdownload.dll stdcall';
function ITD_Internal_GetFileSize(url: string; var size: Cardinal): boolean;
external 'itd_getfilesizeA@files:itdownload.dll stdcall';
function ITD_Internal_GetOption(option: string; buffer: string; length: integer): integer;
external 'itd_getoptionA@files:itdownload.dll stdcall';
procedure ITD_Internal_SetString(index: integer; value: string);
external 'itd_setstringA@files:itdownload.dll stdcall';
procedure ITD_Internal_AddFile(url: string; destfilename: string);
external 'itd_addfileA@files:itdownload.dll stdcall';
procedure ITD_Internal_AddMirror(url: string; destfilename: string);
external 'itd_addmirrorA@files:itdownload.dll stdcall';
procedure ITD_Internal_AddFileSize(url: string; destfilename: string; size: integer);
external 'itd_addfilesizeA@files:itdownload.dll stdcall';
function ITD_Internal_PostPage(url: String; data:AnsiString; length: integer): boolean;
external 'itd_postpageA@files:itdownload.dll stdcall';
#ENDIF
type
TITD_AllowContinueEvent=function:integer;
const
ITD_Offer_Continue = 0;
ITD_Silently_Continue = 1;
ITD_No_Continue = 2;
ITDERR_SUCCESS = 0;
ITDERR_USERCANCEL = 1;
ITDERR_ERROR = 3;
{Constants for Language String indexes:}
ITDS_DownloadFailed = 104;
ITDS_TitleCaption = 200;
ITDS_TitleDescription = 201;
ITDS_MessageFailRetryContinue = 250;
ITDS_MessageFailRetry = 251;
ITDS_Retry = 502;
{Constants for language strings of updater example}
ITDS_Update_Caption = 600;
ITDS_Update_Description = 601;
ITDS_Update_Checking = 602;
ITDS_Update_NewAvailable = 603;
ITDS_Update_NoNewAvailable = 604;
ITDS_Update_WantToCheck = 605;
ITDS_Update_Failed = 606;
ITDS_Update_WillLaunch = 607;
ITDS_Update_WillLaunchWithPath = 608;
ITD_Event_DownloadPageEntered = 1;
ITD_Event_DownloadPageLeft = 2;
ITD_Event_DownloadFailed = 3;
ITD_Event_FileBegin = 4;
ITD_Event_FileEnd = 5;
var
ITD_AllowContinue: boolean;
ITD_RetryOnBack: boolean;
ITD_AfterSuccess: procedure(downloadPage: TWizardPage);
ITD_EventHandler: procedure(event: integer);
ITD_AllowContinueEvent: TITD_AllowContinueEvent;
function ITD_DownloadFiles():integer;
begin
result:=ITD_Internal_DownloadFiles(0);
end;
procedure ITD_AddFile(const URL, filename: String);
begin
ITD_Internal_AddFile(URL, filename);
end;
procedure ITD_AddMirror(const URL, filename: String);
begin
ITD_Internal_AddMirror(URL, filename);
end;
procedure ITD_AddFileSize(const URL, filename: String; size: integer);
begin
ITD_Internal_AddFileSize(URL, filename, size);
end;
function ITD_HandleSkipPage(sender: TWizardPage): boolean;
begin
result := (itd_filecount = 0);
end;
function ITD_IsDownloadComplete(const filename:String):boolean;
begin
result:=ITD_Internal_IsDownloadComplete(filename);
end;
procedure ITD_SetString(index: integer; value: string);
begin
itd_internal_setstring(index, value);
end;
function ITD_GetFileSize(const url: String; var size: cardinal): boolean;
begin
result := itd_internal_getfilesize(url, size);
end;
function ITD_LoadStrings(const filename: string): boolean;
begin
result := itd_internal_loadstrings(filename);
end;
function ITD_GetString(index: integer): String;
begin
ITD_Internal_GetString(index);
SetLength(result, ITD_GetResultLen);
ITD_GetResultString(result, length(result));
end;
procedure ITD_NowDoDownload(sender: TWizardPage);
var err: integer;
allowcontinue:boolean;
begin
wizardform.backbutton.enabled := false;
wizardform.nextbutton.enabled := false;
sender.caption := ITD_GetString(ITDS_TitleCaption);
sender.description := ITD_GetString(ITDS_TitleDescription);
err := ITD_Internal_DownloadFiles(sender.surface.handle);
case err of
ITDERR_SUCCESS: begin
wizardform.nextbutton.enabled := true;
wizardform.nextbutton.onclick(nil);
if itd_aftersuccess <> nil then
itd_aftersuccess(sender);
end;
ITDERR_USERCANCEL: ; //Don't show a message, this happens on setup close and cancel click
else begin
//Some unexpected error, like connection interrupted
wizardform.backbutton.caption := ITD_GetString(ITDS_Retry);
wizardform.backbutton.enabled := true;
wizardform.backbutton.show();
itd_retryonback := true;
if ITD_EventHandler <> nil then
ITD_EventHandler(ITD_Event_DownloadFailed);
if (ITD_AllowContinueEvent <> nil) then begin
case ITD_AllowContinueEvent() of
ITD_Offer_Continue: allowcontinue:=true;
ITD_Silently_Continue:begin
wizardform.nextbutton.enabled := true;
wizardform.nextbutton.onclick(nil);
if itd_aftersuccess <> nil then
itd_aftersuccess(sender);
exit;
end;
ITD_No_Continue: allowcontinue:=false;
end;
end else
allowcontinue:=itd_allowcontinue;
if allowcontinue then begin
wizardform.nextbutton.enabled := true;
//Download failed, we can retry, continue, or exit
sender.caption := ITD_GetString(ITDS_DownloadFailed);
sender.description := ITD_GetString(ITDS_MessageFailRetryContinue);
MsgBox(ITD_GetString(ITDS_MessageFailRetryContinue), mbError, MB_OK);
end else begin //Download failed, we must retry or exit setup
wizardform.nextbutton.enabled := false;
sender.caption := ITD_GetString(ITDS_DownloadFailed);
sender.description := ITD_GetString(ITDS_MessageFailRetry);
MsgBox(ITD_GetString(ITDS_MessageFailRetry), mbError, MB_OK);
end;
end;
end;
end;
procedure ITD_HandleShowPage(sender: TWizardPage);
begin
wizardform.nextbutton.enabled := false;
wizardform.backbutton.hide();
if ITD_EventHandler <> nil then
ITD_EventHandler(ITD_Event_DownloadPageEntered);
itd_nowdodownload(sender);
end;
function ITD_HandleBackClick(sender: TWizardpage): boolean;
begin
result := false;
if itd_retryonback then begin
itd_retryonback := false;
wizardform.backbutton.hide();
itd_nowdodownload(sender);
end;
end;
function ITD_HandleNextClick(sender: TWizardpage): boolean;
begin
if ITD_EventHandler <> nil then
ITD_EventHandler(ITD_Event_DownloadPageLeft);
result := true;
end;
procedure ITD_Init;
begin
//Currently a NOP, don't count on it in future!
end;
function ITD_PostPage(const url, data: String; out response: String): boolean;
begin
result := ITD_Internal_PostPage(url, data, length(data));
if result then begin
setlength(response, ITD_GetResultLen);
ITD_GetResultString(response, length(response));
end;
end;
function ITD_DownloadAfter(afterID: integer): TWizardPage;
var itd_downloadPage: TWizardPage;
begin
itd_downloadpage := CreateCustomPage(afterID, ITD_GetString(ITDS_TitleCaption), ITD_GetString(ITDS_TitleDescription));
itd_downloadpage.onactivate := @itd_handleshowpage;
itd_downloadpage.onshouldskippage := @itd_handleskippage;
itd_downloadpage.onbackbuttonclick := @itd_handlebackclick;
itd_downloadpage.onnextbuttonclick := @itd_handlenextclick;
itd_internal_initui(itd_downloadpage.surface.handle);
result := itd_downloadpage;
end;
procedure ITD_SetOption(const option, value: string);
begin
//The options which call ITD_SetString are depreciated, use ITD_SetString directly
if comparetext(option, 'UI_Caption') = 0 then
ITD_SetString(ITDS_TitleCaption, value)
else if comparetext(option, 'UI_Description') = 0 then
ITD_SetString(ITDS_TitleDescription, value)
else if comparetext(option, 'UI_FailMessage') = 0 then
ITD_SetString(ITDS_MessageFailRetry, value)
else if comparetext(option, 'UI_FailOrContinueMessage') = 0 then
ITD_SetString(ITDS_MessageFailRetryContinue, value)
else if comparetext(option, 'UI_AllowContinue') = 0 then
ITD_AllowContinue := (value = '1')
else
ITD_Internal_SetOption(option, value);
end;
function ITD_GetOption(const option: AnsiString): AnsiString;
begin
setlength(result, 500);
setlength(result, itd_internal_getoption(option, result, length(result)));
end;