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.
27 #include "propsheet.h"
32 #include "ControlAdjuster.h"
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
},
50 ThreeBarProgressPage::ThreeBarProgressPage ()
52 sizeProcessor
.AddControlInfo (ThreeBarControlsInfo
);
55 bool ThreeBarProgressPage::Create ()
57 return PropertyPage::Create (IDD_INSTATUS
);
61 ThreeBarProgressPage::OnInit ()
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
);
68 ins_pprogress
= GetDlgItem (IDC_INS_PPROGRESS
);
69 ins_iprogress
= GetDlgItem (IDC_INS_IPROGRESS
);
70 ins_diskfull
= GetDlgItem (IDC_INS_DISKFULL
);
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
);
78 ThreeBarProgressPage::SetText1 (const TCHAR
* t
)
80 ::SetWindowText (ins_action
, t
);
84 ThreeBarProgressPage::SetText2 (const TCHAR
* t
)
86 ::SetWindowText (ins_pkgname
, t
);
90 ThreeBarProgressPage::SetText3 (const TCHAR
* t
)
92 ::SetWindowText (ins_filename
, t
);
96 ThreeBarProgressPage::SetText4 (const TCHAR
* t
)
98 ::SetWindowText (ins_bl_package
, t
);
102 ThreeBarProgressPage::SetBar1 (long progress
, long max
)
104 int percent
= (int) (100.0 * ((double) progress
) / (double) max
);
105 SendMessage (ins_pprogress
, PBM_SETPOS
, (WPARAM
) percent
, 0);
109 ThreeBarProgressPage::SetBar2 (long progress
, long max
)
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());
119 ThreeBarProgressPage::SetBar3 (long progress
, long max
)
121 int percent
= (int) (100.0 * ((double) progress
) / (double) max
);
122 SendMessage (ins_diskfull
, PBM_SETPOS
, (WPARAM
) percent
, 0);
126 ThreeBarProgressPage::EnableSingleBar (bool enable
)
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
);
136 ThreeBarProgressPage::OnActivate ()
138 // Disable back and next buttons
139 GetOwner ()->SetButtons (0);
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.
154 // Show the normal 3-bar view by default
155 EnableSingleBar (false);
159 Window::PostMessage (task
);
163 ThreeBarProgressPage::OnMessageApp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
167 case WM_APP_START_DOWNLOAD
:
169 // Start the package download thread.
170 do_download (GetInstance (), GetHWND ());
173 case WM_APP_DOWNLOAD_THREAD_COMPLETE
:
175 if (lParam
== IDD_S_INSTALL
)
177 // Download is complete and we want to go on to the install.
178 Window::PostMessage (WM_APP_START_INSTALL
);
180 else if (lParam
!= 0)
182 // Download either failed or completed in download-only mode.
183 GetOwner ()->SetActivePageByID (lParam
);
187 fatal("Unexpected fallthrough from the download thread", NO_ERROR
);
191 case WM_APP_START_INSTALL
:
193 // Start the install thread.
194 do_install (GetInstance (), GetHWND ());
197 case WM_APP_INSTALL_THREAD_COMPLETE
:
199 // Install is complete and we want to go on to the postinstall.
200 Window::PostMessage (WM_APP_START_POSTINSTALL
);
203 case WM_APP_START_POSTINSTALL
:
205 // Start the postinstall script thread.
206 do_postinstall (GetInstance (), GetHWND ());
209 case WM_APP_POSTINSTALL_THREAD_COMPLETE
:
211 GetOwner ()->SetActivePageByID (lParam
);
214 case WM_APP_START_SITE_INFO_DOWNLOAD
:
216 do_download_site_info (GetInstance (), GetHWND ());
219 case WM_APP_SITE_INFO_DOWNLOAD_COMPLETE
:
221 GetOwner ()->SetActivePageByID (lParam
);
224 case WM_APP_START_SETUP_INI_DOWNLOAD
:
226 do_ini (GetInstance (), GetHWND ());
229 case WM_APP_SETUP_INI_DOWNLOAD_COMPLETE
:
232 GetOwner ()->SetActivePageByID (IDD_CHOOSE
);
235 if (source
== IDC_SOURCE_CWD
)
237 // There was a setup.ini file (as found by do_fromcwd), but it
238 // had parse errors. In unattended mode, don't retry even once,
239 // because we'll only loop forever.
243 << "can't install from bad local package dir"
245 exit_msg
= IDS_INSTALL_INCOMPLETE
;
246 LogSingleton::GetInstance().exit (1);
248 GetOwner ()->SetActivePageByID (IDD_SOURCE
);
252 // Download failed, try another site; in unattended mode, retry
253 // the same site a few times in case it was a transient network
254 // glitch, but don't loop forever.
255 static int retries
= 4;
256 if (unattended_mode
&& retries
-- <= 0)
259 << "download/verify error in unattended_mode: out of retries"
261 exit_msg
= IDS_INSTALL_INCOMPLETE
;
262 LogSingleton::GetInstance().exit (1);
264 GetOwner ()->SetActivePageByID (IDD_SITE
);