2 * Copyright (c) 2001, Gary R. Van Sickle.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
16 // This is the implementation of the ThreeBarProgressPage class. It is a fairly generic
17 // progress indicator property page with three progress bars.
28 #include "propsheet.h"
33 #include "ControlAdjuster.h"
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
},
51 ThreeBarProgressPage::ThreeBarProgressPage ()
53 sizeProcessor
.AddControlInfo (ThreeBarControlsInfo
);
56 bool ThreeBarProgressPage::Create ()
58 return PropertyPage::Create (IDD_INSTATUS
);
62 ThreeBarProgressPage::OnInit ()
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
);
69 ins_pprogress
= GetDlgItem (IDC_INS_PPROGRESS
);
70 ins_iprogress
= GetDlgItem (IDC_INS_IPROGRESS
);
71 ins_diskfull
= GetDlgItem (IDC_INS_DISKFULL
);
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
);
79 ThreeBarProgressPage::SetText1 (const wchar_t * t
)
81 ::SetWindowTextW (ins_action
, t
);
85 ThreeBarProgressPage::SetText2 (const wchar_t * t
)
87 ::SetWindowTextW (ins_pkgname
, t
);
91 ThreeBarProgressPage::SetText2 (const TCHAR
* t
)
93 ::SetWindowText (ins_pkgname
, t
);
97 ThreeBarProgressPage::SetText3 (const TCHAR
* t
)
99 ::SetWindowText (ins_filename
, t
);
103 ThreeBarProgressPage::SetText4 (const TCHAR
* t
)
105 ::SetWindowText (ins_bl_package
, t
);
109 ThreeBarProgressPage::SetText1 (unsigned int id
)
111 ::SetWindowTextW (ins_action
, LoadStringW(id
).c_str());
115 ThreeBarProgressPage::SetText2 (unsigned int id
)
117 ::SetWindowTextW (ins_pkgname
, LoadStringW(id
).c_str());
121 ThreeBarProgressPage::SetText3 (unsigned int id
)
123 ::SetWindowTextW (ins_filename
, LoadStringW(id
).c_str());
127 ThreeBarProgressPage::SetText4 (unsigned int id
)
129 ::SetWindowTextW (ins_bl_package
, LoadStringW(id
).c_str());
133 ThreeBarProgressPage::SetBar1 (long progress
, long max
)
135 int percent
= (int) (100.0 * ((double) progress
) / (double) max
);
136 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) percent
, 0);
140 ThreeBarProgressPage::SetBar2 (long long progress
, long long max
)
142 int percent
= (int) (100.0 * ((double) progress
) / (double) max
);
143 SendMessage (ins_iprogress
, PBM_SETPOS
, (WPARAM
) percent
, 0);
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());
148 GetOwner ()->SetWindowText (s
.c_str());
152 ThreeBarProgressPage::SetBar3 (long progress
, long max
)
154 int percent
= (int) (100.0 * ((double) progress
) / (double) max
);
155 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) percent
, 0);
159 ThreeBarProgressPage::EnableSingleBar (bool enable
)
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
);
169 ThreeBarProgressPage::OnActivate ()
171 // Disable back and next buttons
172 GetOwner ()->SetButtons (0);
181 case WM_APP_START_SITE_INFO_DOWNLOAD
:
182 case WM_APP_START_SETUP_INI_DOWNLOAD
:
183 case WM_APP_PREREQ_CHECK
:
184 // For these tasks, show only a single progress bar.
188 // Show the normal 3-bar view by default
189 EnableSingleBar (false);
193 Window::PostMessageNow (task
);
197 ThreeBarProgressPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
201 case WM_APP_PREREQ_CHECK
:
203 // Start the prereq-check thread
204 do_prereq_check (GetInstance (), GetHWND ());
207 case WM_APP_PREREQ_CHECK_THREAD_COMPLETE
:
209 GetOwner ()->SetActivePageByID (lParam
);
212 case WM_APP_START_DOWNLOAD
:
214 // Start the package download thread.
215 do_download (GetInstance (), GetHWND ());
218 case WM_APP_DOWNLOAD_THREAD_COMPLETE
:
220 if (lParam
== IDD_S_INSTALL
)
222 // Download is complete and we want to go on to the install.
223 Window::PostMessageNow (WM_APP_START_INSTALL
);
225 else if (lParam
!= 0)
227 // Download either failed or completed in download-only mode.
228 GetOwner ()->SetActivePageByID (lParam
);
232 Log (LOG_PLAIN
) << "Unexpected fallthrough from the download thread" << endLog
;
236 case WM_APP_START_INSTALL
:
238 // Start the install thread.
239 do_install (GetInstance (), GetHWND ());
242 case WM_APP_INSTALL_THREAD_COMPLETE
:
244 // Install is complete and we want to go on to the postinstall.
245 Window::PostMessageNow (WM_APP_START_POSTINSTALL
);
248 case WM_APP_START_POSTINSTALL
:
250 // Start the postinstall script thread.
251 do_postinstall (GetInstance (), GetHWND ());
254 case WM_APP_POSTINSTALL_THREAD_COMPLETE
:
256 GetOwner ()->SetActivePageByID (lParam
);
259 case WM_APP_START_SITE_INFO_DOWNLOAD
:
261 do_download_site_info (GetInstance (), GetHWND ());
264 case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE
:
266 GetOwner ()->SetActivePageByID (lParam
);
269 case WM_APP_START_SETUP_INI_DOWNLOAD
:
271 do_ini (GetInstance (), GetHWND ());
274 case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE
:
277 GetOwner ()->SetActivePageByID (IDD_CHOOSE
);
280 if (source
== IDC_SOURCE_LOCALDIR
)
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.
288 << "can't install from bad local package dir"
290 Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE
);
293 GetOwner ()->SetActivePageByID (IDD_SOURCE
);
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)
304 << "download/verify error in unattended_mode: out of retries"
306 Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE
);
309 GetOwner ()->SetActivePageByID (IDD_SITE
);