]> cygwin.com Git - cygwin-apps/setup.git/blob - threebar.cc
Support xz and lzma decompression via liblzma
[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 "win32.h"
21 #include "commctrl.h"
22 #include "resource.h"
23
24 #include "dialog.h"
25 #include "site.h"
26
27 #include "propsheet.h"
28 #include "threebar.h"
29 #include "String++.h"
30 #include "state.h"
31
32 #include "ControlAdjuster.h"
33
34 /*
35 Sizing information.
36 */
37 static ControlAdjuster::ControlInfo ThreeBarControlsInfo[] = {
38 {IDC_INS_ACTION, CP_LEFT, CP_TOP},
39 {IDC_INS_PKG, CP_LEFT, CP_TOP},
40 {IDC_INS_FILE, CP_LEFT, CP_TOP},
41 {IDC_INS_DISKFULL, CP_STRETCH, CP_TOP},
42 {IDC_INS_IPROGRESS, CP_STRETCH, CP_TOP},
43 {IDC_INS_PPROGRESS, CP_STRETCH, CP_TOP},
44 {IDC_INS_BL_PACKAGE, CP_LEFT, CP_TOP},
45 {IDC_INS_BL_TOTAL, CP_LEFT, CP_TOP},
46 {IDC_INS_BL_DISK, CP_LEFT, CP_TOP},
47 {0, CP_LEFT, CP_TOP}
48 };
49
50 ThreeBarProgressPage::ThreeBarProgressPage ()
51 {
52 sizeProcessor.AddControlInfo (ThreeBarControlsInfo);
53 }
54
55 bool ThreeBarProgressPage::Create ()
56 {
57 return PropertyPage::Create (IDD_INSTATUS);
58 }
59
60 void
61 ThreeBarProgressPage::OnInit ()
62 {
63 // Get HWNDs to the dialog controls
64 ins_action = GetDlgItem (IDC_INS_ACTION);
65 ins_pkgname = GetDlgItem (IDC_INS_PKG);
66 ins_filename = GetDlgItem (IDC_INS_FILE);
67 // Bars
68 ins_pprogress = GetDlgItem (IDC_INS_PPROGRESS);
69 ins_iprogress = GetDlgItem (IDC_INS_IPROGRESS);
70 ins_diskfull = GetDlgItem (IDC_INS_DISKFULL);
71 // Bar labels
72 ins_bl_package = GetDlgItem (IDC_INS_BL_PACKAGE);
73 ins_bl_total = GetDlgItem (IDC_INS_BL_TOTAL);
74 ins_bl_disk = GetDlgItem (IDC_INS_BL_DISK);
75 }
76
77 void
78 ThreeBarProgressPage::SetText1 (const TCHAR * t)
79 {
80 ::SetWindowText (ins_action, t);
81 }
82
83 void
84 ThreeBarProgressPage::SetText2 (const TCHAR * t)
85 {
86 ::SetWindowText (ins_pkgname, t);
87 }
88
89 void
90 ThreeBarProgressPage::SetText3 (const TCHAR * t)
91 {
92 ::SetWindowText (ins_filename, t);
93 }
94
95 void
96 ThreeBarProgressPage::SetText4 (const TCHAR * t)
97 {
98 ::SetWindowText (ins_bl_package, t);
99 }
100
101 void
102 ThreeBarProgressPage::SetBar1 (long progress, long max)
103 {
104 int percent = (int) (100.0 * ((double) progress) / (double) max);
105 SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) percent, 0);
106 }
107
108 void
109 ThreeBarProgressPage::SetBar2 (long progress, long max)
110 {
111 int percent = (int) (100.0 * ((double) progress) / (double) max);
112 SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) percent, 0);
113 std::string s = stringify(percent);
114 s += "% - Cygwin Setup";
115 GetOwner ()->SetWindowText (s.c_str());
116 }
117
118 void
119 ThreeBarProgressPage::SetBar3 (long progress, long max)
120 {
121 int percent = (int) (100.0 * ((double) progress) / (double) max);
122 SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) percent, 0);
123 }
124
125 void
126 ThreeBarProgressPage::EnableSingleBar (bool enable)
127 {
128 // Switch to/from single bar mode
129 ShowWindow (ins_bl_total, enable ? SW_HIDE : SW_SHOW);
130 ShowWindow (ins_bl_disk, enable ? SW_HIDE : SW_SHOW);
131 ShowWindow (ins_iprogress, enable ? SW_HIDE : SW_SHOW);
132 ShowWindow (ins_diskfull, enable ? SW_HIDE : SW_SHOW);
133 }
134
135 void
136 ThreeBarProgressPage::OnActivate ()
137 {
138 // Disable back and next buttons
139 GetOwner ()->SetButtons (0);
140
141 // Set all bars to 0
142 SetBar1 (0);
143 SetBar2 (0);
144 SetBar3 (0);
145
146 switch (task)
147 {
148 case WM_APP_START_SITE_INFO_DOWNLOAD:
149 case WM_APP_START_SETUP_INI_DOWNLOAD:
150 // For these tasks, show only a single progress bar.
151 EnableSingleBar ();
152 break;
153 default:
154 // Show the normal 3-bar view by default
155 EnableSingleBar (false);
156 break;
157 }
158
159 Window::PostMessage (task);
160 }
161
162 bool
163 ThreeBarProgressPage::OnMessageApp (UINT uMsg, WPARAM wParam, LPARAM lParam)
164 {
165 switch (uMsg)
166 {
167 case WM_APP_START_DOWNLOAD:
168 {
169 // Start the package download thread.
170 do_download (GetInstance (), GetHWND ());
171 break;
172 }
173 case WM_APP_DOWNLOAD_THREAD_COMPLETE:
174 {
175 if (lParam == IDD_S_INSTALL)
176 {
177 // Download is complete and we want to go on to the install.
178 Window::PostMessage (WM_APP_START_INSTALL);
179 }
180 else if (lParam != 0)
181 {
182 // Download either failed or completed in download-only mode.
183 GetOwner ()->SetActivePageByID (lParam);
184 }
185 else
186 {
187 fatal("Unexpected fallthrough from the download thread", NO_ERROR);
188 }
189 break;
190 }
191 case WM_APP_START_INSTALL:
192 {
193 // Start the install thread.
194 do_install (GetInstance (), GetHWND ());
195 break;
196 }
197 case WM_APP_INSTALL_THREAD_COMPLETE:
198 {
199 // Install is complete and we want to go on to the postinstall.
200 Window::PostMessage (WM_APP_START_POSTINSTALL);
201 break;
202 }
203 case WM_APP_START_POSTINSTALL:
204 {
205 // Start the postinstall script thread.
206 do_postinstall (GetInstance (), GetHWND ());
207 break;
208 }
209 case WM_APP_POSTINSTALL_THREAD_COMPLETE:
210 {
211 // Re-enable and "Push" the Next button
212 GetOwner ()->SetButtons (PSWIZB_NEXT);
213 GetOwner ()->PressButton (PSBTN_NEXT);
214 break;
215 }
216 case WM_APP_START_SITE_INFO_DOWNLOAD:
217 {
218 do_download_site_info (GetInstance (), GetHWND ());
219 break;
220 }
221 case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE:
222 {
223 GetOwner ()->SetActivePageByID (lParam);
224 break;
225 }
226 case WM_APP_START_SETUP_INI_DOWNLOAD:
227 {
228 do_ini (GetInstance (), GetHWND ());
229 break;
230 }
231 case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE:
232 {
233 if (lParam)
234 GetOwner ()->SetActivePageByID (IDD_CHOOSE);
235 else
236 {
237 if (source == IDC_SOURCE_CWD)
238 {
239 // There was a setup.ini file (as found by do_fromcwd), but it
240 // had parse errors. In unattended mode, don't retry even once,
241 // because we'll only loop forever.
242 if (unattended_mode)
243 {
244 log (LOG_PLAIN)
245 << "can't install from bad local package dir"
246 << endLog;
247 exit_msg = IDS_INSTALL_INCOMPLETE;
248 LogSingleton::GetInstance().exit (1);
249 }
250 GetOwner ()->SetActivePageByID (IDD_SOURCE);
251 }
252 else
253 {
254 // Download failed, try another site; in unattended mode, retry
255 // the same site a few times in case it was a transient network
256 // glitch, but don't loop forever.
257 static int retries = 4;
258 if (unattended_mode && retries-- <= 0)
259 {
260 log (LOG_PLAIN)
261 << "download/verify error in unattended_mode: out of retries"
262 << endLog;
263 exit_msg = IDS_INSTALL_INCOMPLETE;
264 LogSingleton::GetInstance().exit (1);
265 }
266 GetOwner ()->SetActivePageByID (IDD_SITE);
267 }
268 }
269 break;
270 }
271 default:
272 {
273 // Not handled
274 return false;
275 }
276 }
277
278 return true;
279 }
This page took 0.044452 seconds and 5 git commands to generate.