2 Source: {#emit ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','InstallPath','')}\itdownload.dll; Flags: dontcopy; DestDir: {tmp}
6 Inno Tools Downloader DLL
7 Copyright (C) Sherlock Software 2008
11 The author, Nicholas Sherlock, at nick@sherlocksoftware.org.
12 Comments, questions and suggestions welcome.
15 http://www.sherlocksoftware.org/
18 0.3.5 - Moved strings used in the updater example to the language file, so that they
19 may be more easily translated.
20 Added event functions to support the example of integration with InnoTools tray.
21 Fixes bugs that could cause the download to hang until
22 some mouse movements were received.
23 Allows "detailed mode" to be turned on with ITD_SetOption
24 Allows the HTTP agent to be set with ITD_SetOption
25 0.3.4 - Added Brazilian Portuguese translation by Ronaldo Souza
26 0.3.3 - The "Hilbrand Edskes" release :), lots of suggestions and corrections from him, thank you!
27 The "Retry" button is now translated.
28 The "Current file" progress bar is hidden if only one file is being downloaded.
29 The page's title and description are updated in the case of failed downloads.
30 Several updates to the translations.
31 Several small GUI fixes.
32 0.3.2 - Minor tweaks to the English language file and the translation example script (example4.iss)
33 Added Dutch translation by Hilbrand Edskes
34 Added French translation by Néo
35 0.3.1 - Added language file examples, fixed several missing language strings
36 Preliminary support for proxy server autodetection
37 Allows the size of a file to be queried with ITD_GetFileSize
38 Several small bugfixes
39 0.3.0 - Properly supports timeouts.
40 Fixes bug with time remaining.
41 DLL is required again.
42 Supports localization through ITD_LoadStrings, ITD_SetString
45 Quick view and detailed view
46 0.2.2 - Fixed empty strings '' in calls and added timeouts
47 0.2.1 - Renamed identifiers to avoid name clashes
48 0.2.0 - Converted from DLL to pure native code
52 external 'itd_cancel@files:itdownload.dll stdcall';
54 procedure ITD_ClearFiles;
55 external 'itd_clearfiles@files:itdownload.dll stdcall';
57 function ITD_DownloadFile(url: PChar; destfilename: PChar): integer;
58 external 'itd_downloadfile@files:itdownload.dll stdcall';
60 function ITD_GetResultLen: integer;
61 external 'itd_getresultlen@files:itdownload.dll stdcall';
63 procedure ITD_GetResultString(buffer: pchar; maxlen: integer);
64 external 'itd_getresultstring@files:itdownload.dll stdcall';
66 procedure ITD_Internal_InitUI(HostHwnd: dword);
67 external 'itd_initui@files:itdownload.dll stdcall';
69 function ITD_Internal_LoadStrings(filename: PChar): boolean;
70 external 'itd_loadstrings@files:itdownload.dll stdcall';
72 procedure ITD_Internal_SetOption(option, value: PChar);
73 external 'itd_setoption@files:itdownload.dll stdcall';
75 function ITD_Internal_GetFileSize(url: pchar; var size: Cardinal): boolean;
76 external 'itd_getfilesize@files:itdownload.dll stdcall';
78 function ITD_Internal_GetString(index: integer): boolean;
79 external 'itd_getstring@files:itdownload.dll stdcall';
81 function ITD_Internal_GetOption(option: PChar; buffer: PChar; length: integer): integer;
82 external 'itd_getoption@files:itdownload.dll stdcall';
84 procedure ITD_Internal_SetString(index: integer; value: PChar);
85 external 'itd_setstring@files:itdownload.dll stdcall';
87 procedure ITD_Internal_AddFile(url: PChar; destfilename: PChar);
88 external 'itd_addfile@files:itdownload.dll stdcall';
90 procedure ITD_Internal_AddMirror(url: PChar; destfilename: PChar);
91 external 'itd_addmirror@files:itdownload.dll stdcall';
93 procedure ITD_Internal_AddFileSize(url: PChar; destfilename: PChar; size: integer);
94 external 'itd_addfilesize@files:itdownload.dll stdcall';
96 function ITD_Internal_DownloadFiles(surface: hwnd): integer;
97 external 'itd_downloadfiles@files:itdownload.dll stdcall';
99 function ITD_FileCount: integer;
100 external 'itd_filecount@files:itdownload.dll stdcall';
102 function ITD_Internal_PostPage(url, buffer: PChar; length: integer): boolean;
103 external 'itd_postpage@files:itdownload.dll stdcall';
108 ITDERR_USERCANCEL = 1;
111 {Constants for Language String indexes:}
112 ITDS_DownloadFailed = 104;
114 ITDS_TitleCaption = 200;
115 ITDS_TitleDescription = 201;
117 ITDS_MessageFailRetryContinue = 250;
118 ITDS_MessageFailRetry = 251;
122 {Constants for language strings of updater example}
123 ITDS_Update_Caption = 600;
124 ITDS_Update_Description = 601;
125 ITDS_Update_Checking = 602;
126 ITDS_Update_NewAvailable = 603;
127 ITDS_Update_NoNewAvailable = 604;
128 ITDS_Update_WantToCheck = 605;
129 ITDS_Update_Failed = 606;
130 ITDS_Update_WillLaunch = 607;
131 ITDS_Update_WillLaunchWithPath = 608;
133 ITD_Event_DownloadPageEntered = 1;
134 ITD_Event_DownloadPageLeft = 2;
135 ITD_Event_DownloadFailed = 3;
138 itd_allowcontinue: boolean;
139 itd_retryonback: boolean;
141 ITD_AfterSuccess: procedure(downloadPage: TWizardPage);
142 ITD_EventHandler: procedure(event: integer);
144 procedure ITD_DownloadFiles();
146 ITD_Internal_DownloadFiles(0);
149 procedure ITD_AddFile(const URL, filename: string);
151 ITD_Internal_AddFile(URL, filename);
154 procedure ITD_AddMirror(const URL, filename: string);
156 ITD_Internal_AddMirror(URL, filename);
159 procedure ITD_AddFileSize(const URL, filename: string; size: integer);
161 ITD_Internal_AddFileSize(URL, filename, size);
164 function ITD_HandleSkipPage(sender: TWizardPage): boolean;
166 result := (itd_filecount = 0);
169 procedure ITD_SetString(index: integer; value: string);
171 itd_internal_setstring(index, value);
174 function ITD_GetFileSize(const url: string; var size: cardinal): boolean;
176 result := itd_internal_getfilesize(PChar(url), size);
179 function ITD_LoadStrings(const filename: string): boolean;
181 result := itd_internal_loadstrings(filename);
184 function ITD_GetString(index: integer): string;
186 itd_internal_getstring(index);
187 setlength(result, ITD_GetResultLen);
188 ITD_GetResultString(PChar(result), length(result));
191 procedure ITD_NowDoDownload(sender: TWizardPage);
194 wizardform.backbutton.enabled := false;
195 wizardform.nextbutton.enabled := false;
197 sender.caption := ITD_GetString(ITDS_TitleCaption);
198 sender.description := ITD_GetString(ITDS_TitleDescription);
200 err := ITD_Internal_DownloadFiles(sender.surface.handle);
203 ITDERR_SUCCESS: begin
204 wizardform.nextbutton.enabled := true;
205 wizardform.nextbutton.onclick(nil);
207 if itd_aftersuccess <> nil then
208 itd_aftersuccess(sender);
210 ITDERR_USERCANCEL: ; //Don't show a message, this happens on setup close and cancel click
212 //Some unexpected error, like connection interrupted
213 wizardform.backbutton.caption := ITD_GetString(ITDS_Retry);
214 wizardform.backbutton.enabled := true;
215 wizardform.backbutton.show();
216 itd_retryonback := true;
218 wizardform.nextbutton.enabled := itd_allowcontinue;
220 if ITD_EventHandler <> nil then
221 ITD_EventHandler(ITD_Event_DownloadFailed);
223 if itd_allowcontinue then begin //Download failed, we can retry, continue, or exit
224 sender.caption := ITD_GetString(ITDS_DownloadFailed);
225 sender.description := ITD_GetString(ITDS_MessageFailRetryContinue);
227 MsgBox(ITD_GetString(ITDS_MessageFailRetryContinue), mbError, MB_OK)
228 end else begin //Download failed, we must retry or exit setup
229 sender.caption := ITD_GetString(ITDS_DownloadFailed);
230 sender.description := ITD_GetString(ITDS_MessageFailRetry);
232 MsgBox(ITD_GetString(ITDS_MessageFailRetry), mbError, MB_OK)
238 procedure ITD_HandleShowPage(sender: TWizardPage);
240 wizardform.nextbutton.enabled := false;
241 wizardform.backbutton.hide();
243 if ITD_EventHandler <> nil then
244 ITD_EventHandler(ITD_Event_DownloadPageEntered);
246 itd_nowdodownload(sender);
249 function ITD_HandleBackClick(sender: TWizardpage): boolean;
252 if itd_retryonback then begin
253 itd_retryonback := false;
254 wizardform.backbutton.hide();
255 itd_nowdodownload(sender);
259 function ITD_HandleNextClick(sender: TWizardpage): boolean;
261 if ITD_EventHandler <> nil then
262 ITD_EventHandler(ITD_Event_DownloadPageLeft);
269 //Currently a NOP. Don't count on it in future.
272 function ITD_PostPage(const url, data: string; out response: string): boolean;
274 result := ITD_Internal_PostPage(PChar(url), PChar(data), length(data));
277 setlength(response, ITD_GetResultLen);
278 ITD_GetResultString(PChar(response), length(response));
282 function ITD_DownloadAfter(afterID: integer): TWizardPage;
283 var itd_downloadPage: TWizardPage;
285 itd_downloadpage := CreateCustomPage(afterID, ITD_GetString(ITDS_TitleCaption), ITD_GetString(ITDS_TitleDescription));
287 itd_downloadpage.onactivate := @itd_handleshowpage;
288 itd_downloadpage.onshouldskippage := @itd_handleskippage;
289 itd_downloadpage.onbackbuttonclick := @itd_handlebackclick;
290 itd_downloadpage.onnextbuttonclick := @itd_handlenextclick;
292 itd_internal_initui(itd_downloadpage.surface.handle);
294 result := itd_downloadpage;
297 procedure ITD_SetOption(const option, value: string);
299 //The options which call ITD_SetString are depreciated, use ITD_SetString directly
300 if comparetext(option, 'UI_Caption') = 0 then
301 ITD_SetString(ITDS_TitleCaption, value)
302 else if comparetext(option, 'UI_Description') = 0 then
303 ITD_SetString(ITDS_TitleDescription, value)
304 else if comparetext(option, 'UI_FailMessage') = 0 then
305 ITD_SetString(ITDS_MessageFailRetry, value)
306 else if comparetext(option, 'UI_FailOrContinueMessage') = 0 then
307 ITD_SetString(ITDS_MessageFailRetryContinue, value)
308 else if comparetext(option, 'UI_AllowContinue') = 0 then
309 ITD_AllowContinue := (value = '1')
311 ITD_Internal_SetOption(option, value);
314 function ITD_GetOption(const option: string): string;
316 setlength(result, 500);
317 setlength(result, itd_internal_getoption(pchar(option), pchar(result), length(result)));