2 * Copyright (c) 2005 Brian Dessent
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 Brian Dessent <brian@dessent.net>
28 #include "propsheet.h"
31 #include "LogSingleton.h"
32 #include "ControlAdjuster.h"
33 #include "package_db.h"
34 #include "package_meta.h"
36 #include "Exception.h"
37 #include "getopt++/BoolOption.h"
39 // Sizing information.
40 static ControlAdjuster::ControlInfo PrereqControlsInfo
[] = {
41 {IDC_PREREQ_CHECK
, CP_LEFT
, CP_BOTTOM
},
42 {IDC_PREREQ_EDIT
, CP_STRETCH
, CP_STRETCH
},
46 extern ThreeBarProgressPage Progress
;
47 BoolOption
IncludeSource (false, 'I', "include-source", "Automatically install source for every package installed");
49 // ---------------------------------------------------------------------------
50 // implements class PrereqPage
51 // ---------------------------------------------------------------------------
53 PrereqPage::PrereqPage ()
55 sizeProcessor
.AddControlInfo (PrereqControlsInfo
);
61 return PropertyPage::Create (IDD_PREREQ
);
67 // start with the checkbox set
68 CheckDlgButton (GetHWND (), IDC_PREREQ_CHECK
, BST_CHECKED
);
70 // set the edit-area to a larger font
71 SetDlgItemFont(IDC_PREREQ_EDIT
, "MS Shell Dlg", 10);
75 PrereqPage::OnActivate()
77 // if we have gotten this far, then PrereqChecker has already run isMet
78 // and found that there were problems; so we can just call
79 // getUnmetString to format the results and display it
84 SetDlgItemText (GetHWND (), IDC_PREREQ_EDIT
, s
.c_str ());
86 SetFocus (GetDlgItem (IDC_PREREQ_CHECK
));
94 if (!IsDlgButtonChecked (h
, IDC_PREREQ_CHECK
))
103 PrereqPage::whatNext ()
105 if (source
== IDC_SOURCE_LOCALDIR
)
108 Progress
.SetActivateTask (WM_APP_START_INSTALL
);
112 // Next, start download from internet
113 Progress
.SetActivateTask (WM_APP_START_DOWNLOAD
);
119 PrereqPage::OnBack ()
125 PrereqPage::OnUnattended ()
127 // in chooser-only mode, show this page so the user can choose to fix dependency problems or not
128 if (unattended_mode
== chooseronly
)
135 PrereqPage::OnMessageCmd (int id
, HWND hwndctl
, UINT code
)
137 if ((code
== BN_CLICKED
) && (id
== IDC_PREREQ_CHECK
))
139 GetOwner ()->SetButtons (PSWIZB_BACK
| (IsButtonChecked (id
) ? PSWIZB_NEXT
: 0));
146 // ---------------------------------------------------------------------------
147 // implements class PrereqChecker
148 // ---------------------------------------------------------------------------
150 // instantiate the static members
151 bool PrereqChecker::upgrade
;
152 bool PrereqChecker::use_test_packages
;
155 PrereqChecker::isMet ()
159 Progress
.SetText1 ("Solving dependencies...");
160 Progress
.SetText2 ("");
161 Progress
.SetText3 ("");
163 // go through all packages, adding changed ones to the solver task list
166 for (packagedb::packagecollection::iterator p
= db
.packages
.begin ();
167 p
!= db
.packages
.end (); ++p
)
169 packagemeta
*pkg
= p
->second
;
171 // decode UI state to action
172 // skip and keep don't change dependency solution
173 if (pkg
->installed
!= pkg
->desired
)
176 q
.add(pkg
->desired
, SolverTasks::taskInstall
); // install/upgrade
178 q
.add(pkg
->installed
, SolverTasks::taskUninstall
); // uninstall
182 q
.add(pkg
->installed
, SolverTasks::taskReinstall
); // reinstall
184 // only install action makes sense for source packages
185 if (pkg
->srcpicked())
188 q
.add(pkg
->desired
.sourcePackage(), SolverTasks::taskInstall
);
190 q
.add(pkg
->installed
.sourcePackage(), SolverTasks::taskInstall
);
194 // apply solver to those tasks and the chooser global state (keep, curr, test)
195 return db
.solution
.update(q
, upgrade
, use_test_packages
, IncludeSource
);
198 /* Formats problems and solutions as a string for display to the user. */
200 PrereqChecker::getUnmetString (std::string
&s
)
203 s
= db
.solution
.report();
207 while ((pos
= s
.find("\n", pos
)) != std::string::npos
)
209 s
.replace(pos
, 1, "\r\n");
214 // ---------------------------------------------------------------------------
215 // progress page glue
216 // ---------------------------------------------------------------------------
219 do_prereq_check_thread(HINSTANCE h
, HWND owner
)
226 if (source
== IDC_SOURCE_LOCALDIR
)
227 Progress
.SetActivateTask (WM_APP_START_INSTALL
); // install
229 Progress
.SetActivateTask (WM_APP_START_DOWNLOAD
); // start download
230 retval
= IDD_INSTATUS
;
234 // rut-roh, some required things are not selected
242 do_prereq_check_reflector (void *p
)
245 context
= (HANDLE
*) p
;
249 int next_dialog
= do_prereq_check_thread ((HINSTANCE
) context
[0], (HWND
) context
[1]);
251 // Tell the progress page that we're done prereq checking
252 Progress
.PostMessageNow (WM_APP_PREREQ_CHECK_THREAD_COMPLETE
, 0, next_dialog
);
254 TOPLEVEL_CATCH((HWND
) context
[1], "prereq_check");
259 static HANDLE context
[2];
262 do_prereq_check (HINSTANCE h
, HWND owner
)
268 CreateThread (NULL
, 0, do_prereq_check_reflector
, context
, 0, &threadID
);