Link with mingwex before libntll
[cygwin-setup.git] / threebar.cc
blobff4c5cb356c14ad45ff5f37dc00ee79d2f2018df
1 /*
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
10 * http://www.gnu.org/
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.
19 #include <string>
20 #include "LogFile.h"
21 #include "win32.h"
22 #include "commctrl.h"
23 #include "resource.h"
25 #include "dialog.h"
26 #include "site.h"
28 #include "propsheet.h"
29 #include "threebar.h"
30 #include "String++.h"
31 #include "state.h"
33 #include "ControlAdjuster.h"
36 Sizing information.
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}
51 ThreeBarProgressPage::ThreeBarProgressPage ()
53 sizeProcessor.AddControlInfo (ThreeBarControlsInfo);
56 bool ThreeBarProgressPage::Create ()
58 return PropertyPage::Create (IDD_INSTATUS);
61 void
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);
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);
78 void
79 ThreeBarProgressPage::SetText1 (const wchar_t * t)
81 ::SetWindowTextW (ins_action, t);
84 void
85 ThreeBarProgressPage::SetText2 (const wchar_t * t)
87 ::SetWindowTextW (ins_pkgname, t);
90 void
91 ThreeBarProgressPage::SetText2 (const TCHAR * t)
93 ::SetWindowText (ins_pkgname, t);
96 void
97 ThreeBarProgressPage::SetText3 (const TCHAR * t)
99 ::SetWindowText (ins_filename, t);
102 void
103 ThreeBarProgressPage::SetText4 (const TCHAR * t)
105 ::SetWindowText (ins_bl_package, t);
108 void
109 ThreeBarProgressPage::SetText1 (unsigned int id)
111 ::SetWindowTextW (ins_action, LoadStringW(id).c_str());
114 void
115 ThreeBarProgressPage::SetText2 (unsigned int id)
117 ::SetWindowTextW (ins_pkgname, LoadStringW(id).c_str());
120 void
121 ThreeBarProgressPage::SetText3 (unsigned int id)
123 ::SetWindowTextW (ins_filename, LoadStringW(id).c_str());
126 void
127 ThreeBarProgressPage::SetText4 (unsigned int id)
129 ::SetWindowTextW (ins_bl_package, LoadStringW(id).c_str());
132 void
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);
139 void
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());
151 void
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);
158 void
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);
168 void
169 ThreeBarProgressPage::OnActivate ()
171 // Disable back and next buttons
172 GetOwner ()->SetButtons (0);
174 // Set all bars to 0
175 SetBar1 (0);
176 SetBar2 (0);
177 SetBar3 (0);
179 switch (task)
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.
185 EnableSingleBar ();
186 break;
187 default:
188 // Show the normal 3-bar view by default
189 EnableSingleBar (false);
190 break;
193 Window::PostMessageNow (task);
196 bool
197 ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam)
199 switch (uMsg)
201 case WM_APP_PREREQ_CHECK:
203 // Start the prereq-check thread
204 do_prereq_check (GetInstance (), GetHWND ());
205 break;
207 case WM_APP_PREREQ_CHECK_THREAD_COMPLETE:
209 GetOwner ()->SetActivePageByID (lParam);
210 break;
212 case WM_APP_START_DOWNLOAD:
214 // Start the package download thread.
215 do_download (GetInstance (), GetHWND ());
216 break;
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);
230 else
232 Log (LOG_PLAIN) << "Unexpected fallthrough from the download thread" << endLog;
234 break;
236 case WM_APP_START_INSTALL:
238 // Start the install thread.
239 do_install (GetInstance (), GetHWND ());
240 break;
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);
246 break;
248 case WM_APP_START_POSTINSTALL:
250 // Start the postinstall script thread.
251 do_postinstall (GetInstance (), GetHWND ());
252 break;
254 case WM_APP_POSTINSTALL_THREAD_COMPLETE:
256 GetOwner ()->SetActivePageByID (lParam);
257 break;
259 case WM_APP_START_SITE_INFO_DOWNLOAD:
261 do_download_site_info (GetInstance (), GetHWND ());
262 break;
264 case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE:
266 GetOwner ()->SetActivePageByID (lParam);
267 break;
269 case WM_APP_START_SETUP_INI_DOWNLOAD:
271 do_ini (GetInstance (), GetHWND ());
272 break;
274 case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE:
276 if (lParam)
277 GetOwner ()->SetActivePageByID (IDD_CHOOSE);
278 else
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.
285 if (unattended_mode)
287 Log (LOG_PLAIN)
288 << "can't install from bad local package dir"
289 << endLog;
290 Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE);
291 Logger ().exit (1);
293 GetOwner ()->SetActivePageByID (IDD_SOURCE);
295 else
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)
303 Log (LOG_PLAIN)
304 << "download/verify error in unattended_mode: out of retries"
305 << endLog;
306 Logger ().setExitMsg (IDS_INSTALL_INCOMPLETE);
307 Logger ().exit (1);
309 GetOwner ()->SetActivePageByID (IDD_SITE);
312 break;
314 default:
316 // Not handled
317 return false;
321 return true;