]> cygwin.com Git - cygwin-apps/setup.git/blob - threebar.cc
Bump displayed copyright year
[cygwin-apps/setup.git] / threebar.cc
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
19 #include <string>
20 #include "LogFile.h"
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"
30 #include "String++.h"
31 #include "state.h"
32
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
51 ThreeBarProgressPage::ThreeBarProgressPage ()
52 {
53 sizeProcessor.AddControlInfo (ThreeBarControlsInfo);
54 }
55
56 bool ThreeBarProgressPage::Create ()
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
79 ThreeBarProgressPage::SetText1 (const wchar_t * t)
80 {
81 ::SetWindowTextW (ins_action, t);
82 }
83
84 void
85 ThreeBarProgressPage::SetText2 (const wchar_t * t)
86 {
87 ::SetWindowTextW (ins_pkgname, t);
88 }
89
90 void
91 ThreeBarProgressPage::SetText2 (const TCHAR * t)
92 {
93 ::SetWindowText (ins_pkgname, t);
94 }
95
96 void
97 ThreeBarProgressPage::SetText3 (const TCHAR * t)
98 {
99 ::SetWindowText (ins_filename, t);
100 }
101
102 void
103 ThreeBarProgressPage::SetText4 (const TCHAR * t)
104 {
105 ::SetWindowText (ins_bl_package, t);
106 }
107
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
132 void
133 ThreeBarProgressPage::SetBar1 (off_t progress, off_t max)
134 {
135 int percent = (int) (100.0 * ((double) progress) / (double) max);
136 SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) percent, 0);
137 }
138
139 void
140 ThreeBarProgressPage::SetBar2 (off_t progress, off_t max)
141 {
142 int percent = (int) (100.0 * ((double) progress) / (double) max);
143 SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) percent, 0);
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());
148 GetOwner ()->SetWindowText (s.c_str());
149 }
150
151 void
152 ThreeBarProgressPage::SetBar3 (off_t progress, off_t max)
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:
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;
191 }
192
193 Window::PostMessageNow (task);
194 }
195
196 bool
197 ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam)
198 {
199 switch (uMsg)
200 {
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 }
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.
223 Window::PostMessageNow (WM_APP_START_INSTALL);
224 }
225 else if (lParam != 0)
226 {
227 // Download either failed or completed in download-only mode.
228 GetOwner ()->SetActivePageByID (lParam);
229 }
230 else
231 {
232 Log (LOG_PLAIN) << "Unexpected fallthrough from the download thread" << endLog;
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:
243 {
244 // Install is complete and we want to go on to the postinstall.
245 Window::PostMessageNow (WM_APP_START_POSTINSTALL);
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:
255 {
256 GetOwner ()->SetActivePageByID (lParam);
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 {
276 if (lParam)
277 GetOwner ()->SetActivePageByID (IDD_CHOOSE);
278 else
279 {
280 if (source == IDC_SOURCE_LOCALDIR)
281 {
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 {
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);
292 }
293 GetOwner ()->SetActivePageByID (IDD_SOURCE);
294 }
295 else
296 {
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 {
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);
308 }
309 GetOwner ()->SetActivePageByID (IDD_SITE);
310 }
311 }
312 break;
313 }
314 default:
315 {
316 // Not handled
317 return false;
318 }
319 }
320
321 return true;
322
323 }
This page took 0.048661 seconds and 5 git commands to generate.