]>
Commit | Line | Data |
---|---|---|
b7301c43 RC |
1 | /* |
2 | * Copyright (c) 2001, Gary R. Van Sickle. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net> | |
13 | * | |
14 | */ | |
15 | ||
16 | // This is the implementation of the ThreeBarProgressPage class. It is a fairly generic | |
17 | // progress indicator property page with three progress bars. | |
18 | ||
8300be9c | 19 | #include <string> |
5fa64c3c | 20 | #include "LogFile.h" |
b7301c43 RC |
21 | #include "win32.h" |
22 | #include "commctrl.h" | |
23 | #include "resource.h" | |
24 | ||
25 | #include "dialog.h" | |
26 | #include "site.h" | |
27 | ||
28 | #include "propsheet.h" | |
29 | #include "threebar.h" | |
af111c7d | 30 | #include "String++.h" |
d9f4a2ba | 31 | #include "state.h" |
b7301c43 | 32 | |
a8d753b6 RC |
33 | #include "ControlAdjuster.h" |
34 | ||
35 | /* | |
36 | Sizing information. | |
37 | */ | |
38 | static ControlAdjuster::ControlInfo ThreeBarControlsInfo[] = { | |
39 | {IDC_INS_ACTION, CP_LEFT, CP_TOP}, | |
40 | {IDC_INS_PKG, CP_LEFT, CP_TOP}, | |
41 | {IDC_INS_FILE, CP_LEFT, CP_TOP}, | |
42 | {IDC_INS_DISKFULL, CP_STRETCH, CP_TOP}, | |
43 | {IDC_INS_IPROGRESS, CP_STRETCH, CP_TOP}, | |
44 | {IDC_INS_PPROGRESS, CP_STRETCH, CP_TOP}, | |
45 | {IDC_INS_BL_PACKAGE, CP_LEFT, CP_TOP}, | |
46 | {IDC_INS_BL_TOTAL, CP_LEFT, CP_TOP}, | |
47 | {IDC_INS_BL_DISK, CP_LEFT, CP_TOP}, | |
48 | {0, CP_LEFT, CP_TOP} | |
49 | }; | |
50 | ||
00fa5f6c | 51 | ThreeBarProgressPage::ThreeBarProgressPage () |
a8d753b6 RC |
52 | { |
53 | sizeProcessor.AddControlInfo (ThreeBarControlsInfo); | |
54 | } | |
55 | ||
58db1046 | 56 | bool ThreeBarProgressPage::Create () |
b7301c43 RC |
57 | { |
58 | return PropertyPage::Create (IDD_INSTATUS); | |
59 | } | |
60 | ||
61 | void | |
62 | ThreeBarProgressPage::OnInit () | |
63 | { | |
64 | // Get HWNDs to the dialog controls | |
65 | ins_action = GetDlgItem (IDC_INS_ACTION); | |
66 | ins_pkgname = GetDlgItem (IDC_INS_PKG); | |
67 | ins_filename = GetDlgItem (IDC_INS_FILE); | |
68 | // Bars | |
69 | ins_pprogress = GetDlgItem (IDC_INS_PPROGRESS); | |
70 | ins_iprogress = GetDlgItem (IDC_INS_IPROGRESS); | |
71 | ins_diskfull = GetDlgItem (IDC_INS_DISKFULL); | |
72 | // Bar labels | |
73 | ins_bl_package = GetDlgItem (IDC_INS_BL_PACKAGE); | |
74 | ins_bl_total = GetDlgItem (IDC_INS_BL_TOTAL); | |
75 | ins_bl_disk = GetDlgItem (IDC_INS_BL_DISK); | |
76 | } | |
77 | ||
78 | void | |
c2f99cb1 | 79 | ThreeBarProgressPage::SetText1 (const wchar_t * t) |
b7301c43 | 80 | { |
c2f99cb1 | 81 | ::SetWindowTextW (ins_action, t); |
b7301c43 RC |
82 | } |
83 | ||
dfd97f99 JT |
84 | void |
85 | ThreeBarProgressPage::SetText2 (const wchar_t * t) | |
86 | { | |
87 | ::SetWindowTextW (ins_pkgname, t); | |
88 | } | |
89 | ||
b7301c43 RC |
90 | void |
91 | ThreeBarProgressPage::SetText2 (const TCHAR * t) | |
92 | { | |
58db1046 | 93 | ::SetWindowText (ins_pkgname, t); |
b7301c43 RC |
94 | } |
95 | ||
96 | void | |
97 | ThreeBarProgressPage::SetText3 (const TCHAR * t) | |
98 | { | |
58db1046 | 99 | ::SetWindowText (ins_filename, t); |
b7301c43 RC |
100 | } |
101 | ||
aa1e3b4d RC |
102 | void |
103 | ThreeBarProgressPage::SetText4 (const TCHAR * t) | |
104 | { | |
105 | ::SetWindowText (ins_bl_package, t); | |
106 | } | |
107 | ||
207380f4 JT |
108 | void |
109 | ThreeBarProgressPage::SetText1 (unsigned int id) | |
110 | { | |
111 | ::SetWindowTextW (ins_action, LoadStringW(id).c_str()); | |
112 | } | |
113 | ||
114 | void | |
115 | ThreeBarProgressPage::SetText2 (unsigned int id) | |
116 | { | |
117 | ::SetWindowTextW (ins_pkgname, LoadStringW(id).c_str()); | |
118 | } | |
119 | ||
120 | void | |
121 | ThreeBarProgressPage::SetText3 (unsigned int id) | |
122 | { | |
123 | ::SetWindowTextW (ins_filename, LoadStringW(id).c_str()); | |
124 | } | |
125 | ||
126 | void | |
127 | ThreeBarProgressPage::SetText4 (unsigned int id) | |
128 | { | |
129 | ::SetWindowTextW (ins_bl_package, LoadStringW(id).c_str()); | |
130 | } | |
131 | ||
b7301c43 | 132 | void |
44d31ea0 | 133 | ThreeBarProgressPage::SetBar1 (off_t progress, off_t max) |
b7301c43 RC |
134 | { |
135 | int percent = (int) (100.0 * ((double) progress) / (double) max); | |
136 | SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) percent, 0); | |
137 | } | |
138 | ||
139 | void | |
44d31ea0 | 140 | ThreeBarProgressPage::SetBar2 (off_t progress, off_t max) |
b7301c43 RC |
141 | { |
142 | int percent = (int) (100.0 * ((double) progress) / (double) max); | |
143 | SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) percent, 0); | |
c156d59f JT |
144 | |
145 | // also update window title to show progress | |
146 | std::wstring caption = LoadStringW(IDS_MBOX_CAPTION); | |
147 | std::wstring s = format(L"%d%% - %ls", percent, caption.c_str()); | |
d2a3615c | 148 | GetOwner ()->SetWindowText (s.c_str()); |
b7301c43 RC |
149 | } |
150 | ||
151 | void | |
44d31ea0 | 152 | ThreeBarProgressPage::SetBar3 (off_t progress, off_t max) |
b7301c43 RC |
153 | { |
154 | int percent = (int) (100.0 * ((double) progress) / (double) max); | |
155 | SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) percent, 0); | |
156 | } | |
157 | ||
158 | void | |
159 | ThreeBarProgressPage::EnableSingleBar (bool enable) | |
160 | { | |
161 | // Switch to/from single bar mode | |
162 | ShowWindow (ins_bl_total, enable ? SW_HIDE : SW_SHOW); | |
163 | ShowWindow (ins_bl_disk, enable ? SW_HIDE : SW_SHOW); | |
164 | ShowWindow (ins_iprogress, enable ? SW_HIDE : SW_SHOW); | |
165 | ShowWindow (ins_diskfull, enable ? SW_HIDE : SW_SHOW); | |
166 | } | |
167 | ||
168 | void | |
169 | ThreeBarProgressPage::OnActivate () | |
170 | { | |
171 | // Disable back and next buttons | |
172 | GetOwner ()->SetButtons (0); | |
173 | ||
174 | // Set all bars to 0 | |
175 | SetBar1 (0); | |
176 | SetBar2 (0); | |
177 | SetBar3 (0); | |
178 | ||
179 | switch (task) | |
180 | { | |
181 | case WM_APP_START_SITE_INFO_DOWNLOAD: | |
182 | case WM_APP_START_SETUP_INI_DOWNLOAD: | |
ad20ac46 | 183 | case WM_APP_PREREQ_CHECK: |
b7301c43 RC |
184 | // For these tasks, show only a single progress bar. |
185 | EnableSingleBar (); | |
186 | break; | |
187 | default: | |
188 | // Show the normal 3-bar view by default | |
189 | EnableSingleBar (false); | |
190 | break; | |
191 | } | |
192 | ||
6ab6abae | 193 | Window::PostMessageNow (task); |
b7301c43 RC |
194 | } |
195 | ||
196 | bool | |
d3472167 | 197 | ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam) |
b7301c43 RC |
198 | { |
199 | switch (uMsg) | |
200 | { | |
ad20ac46 JT |
201 | case WM_APP_PREREQ_CHECK: |
202 | { | |
203 | // Start the prereq-check thread | |
204 | do_prereq_check (GetInstance (), GetHWND ()); | |
205 | break; | |
206 | } | |
207 | case WM_APP_PREREQ_CHECK_THREAD_COMPLETE: | |
208 | { | |
209 | GetOwner ()->SetActivePageByID (lParam); | |
210 | break; | |
211 | } | |
b7301c43 RC |
212 | case WM_APP_START_DOWNLOAD: |
213 | { | |
214 | // Start the package download thread. | |
215 | do_download (GetInstance (), GetHWND ()); | |
216 | break; | |
217 | } | |
218 | case WM_APP_DOWNLOAD_THREAD_COMPLETE: | |
219 | { | |
220 | if (lParam == IDD_S_INSTALL) | |
221 | { | |
222 | // Download is complete and we want to go on to the install. | |
6ab6abae | 223 | Window::PostMessageNow (WM_APP_START_INSTALL); |
b7301c43 RC |
224 | } |
225 | else if (lParam != 0) | |
226 | { | |
6c8daadf | 227 | // Download either failed or completed in download-only mode. |
b7301c43 RC |
228 | GetOwner ()->SetActivePageByID (lParam); |
229 | } | |
230 | else | |
231 | { | |
20f95aca | 232 | Log (LOG_PLAIN) << "Unexpected fallthrough from the download thread" << endLog; |
b7301c43 RC |
233 | } |
234 | break; | |
235 | } | |
236 | case WM_APP_START_INSTALL: | |
237 | { | |
238 | // Start the install thread. | |
239 | do_install (GetInstance (), GetHWND ()); | |
240 | break; | |
241 | } | |
242 | case WM_APP_INSTALL_THREAD_COMPLETE: | |
39ba3555 MB |
243 | { |
244 | // Install is complete and we want to go on to the postinstall. | |
6ab6abae | 245 | Window::PostMessageNow (WM_APP_START_POSTINSTALL); |
39ba3555 MB |
246 | break; |
247 | } | |
248 | case WM_APP_START_POSTINSTALL: | |
249 | { | |
250 | // Start the postinstall script thread. | |
251 | do_postinstall (GetInstance (), GetHWND ()); | |
252 | break; | |
253 | } | |
254 | case WM_APP_POSTINSTALL_THREAD_COMPLETE: | |
b7301c43 | 255 | { |
d0dba6b6 | 256 | GetOwner ()->SetActivePageByID (lParam); |
b7301c43 RC |
257 | break; |
258 | } | |
259 | case WM_APP_START_SITE_INFO_DOWNLOAD: | |
260 | { | |
261 | do_download_site_info (GetInstance (), GetHWND ()); | |
262 | break; | |
263 | } | |
264 | case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE: | |
265 | { | |
266 | GetOwner ()->SetActivePageByID (lParam); | |
267 | break; | |
268 | } | |
269 | case WM_APP_START_SETUP_INI_DOWNLOAD: | |
270 | { | |
271 | do_ini (GetInstance (), GetHWND ()); | |
272 | break; | |
273 | } | |
274 | case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE: | |
275 | { | |
d9f4a2ba | 276 | if (lParam) |
00fa5f6c | 277 | GetOwner ()->SetActivePageByID (IDD_CHOOSE); |
b7301c43 RC |
278 | else |
279 | { | |
7cc4d95e | 280 | if (source == IDC_SOURCE_LOCALDIR) |
d9f4a2ba | 281 | { |
e1751ab2 DK |
282 | // There was a setup.ini file (as found by do_fromcwd), but it |
283 | // had parse errors. In unattended mode, don't retry even once, | |
284 | // because we'll only loop forever. | |
285 | if (unattended_mode) | |
286 | { | |
157dc2b8 | 287 | Log (LOG_PLAIN) |
e1751ab2 DK |
288 | << "can't install from bad local package dir" |
289 | << endLog; | |
5fa64c3c CV |
290 | Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE); |
291 | Logger ().exit (1); | |
e1751ab2 | 292 | } |
d9f4a2ba MB |
293 | GetOwner ()->SetActivePageByID (IDD_SOURCE); |
294 | } | |
295 | else | |
296 | { | |
e1751ab2 DK |
297 | // Download failed, try another site; in unattended mode, retry |
298 | // the same site a few times in case it was a transient network | |
299 | // glitch, but don't loop forever. | |
300 | static int retries = 4; | |
301 | if (unattended_mode && retries-- <= 0) | |
302 | { | |
157dc2b8 | 303 | Log (LOG_PLAIN) |
e1751ab2 DK |
304 | << "download/verify error in unattended_mode: out of retries" |
305 | << endLog; | |
5fa64c3c CV |
306 | Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE); |
307 | Logger ().exit (1); | |
e1751ab2 | 308 | } |
d9f4a2ba MB |
309 | GetOwner ()->SetActivePageByID (IDD_SITE); |
310 | } | |
b7301c43 RC |
311 | } |
312 | break; | |
313 | } | |
314 | default: | |
315 | { | |
316 | // Not handled | |
317 | return false; | |
318 | } | |
319 | } | |
320 | ||
321 | return true; | |
ad20ac46 | 322 | |
b7301c43 | 323 | } |