Statistics
| Branch: | Revision:

root / trunk / Pithos.Installer / it_download.iss @ 99882980

History | View | Annotate | Download (10.3 kB)

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