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>
20 #include "LogSingleton.h"
21 #include "ControlAdjuster.h"
22 #include "package_db.h"
24 #include "Exception.h"
25 #include "getopt++/BoolOption.h"
27 // Sizing information.
28 static ControlAdjuster::ControlInfo PrereqControlsInfo
[] = {
29 {IDC_PREREQ_CHECK
, CP_LEFT
, CP_BOTTOM
},
30 {IDC_PREREQ_EDIT
, CP_STRETCH
, CP_STRETCH
},
34 extern ThreeBarProgressPage Progress
;
35 BoolOption
IncludeSource (false, 'I', "include-source", IDS_HELPTEXT_INCLUDE_SOURCE
);
37 // ---------------------------------------------------------------------------
38 // implements class PrereqPage
39 // ---------------------------------------------------------------------------
41 PrereqPage::PrereqPage ()
43 sizeProcessor
.AddControlInfo (PrereqControlsInfo
);
49 return PropertyPage::Create (IDD_PREREQ
);
55 // start with the checkbox set
56 CheckDlgButton (GetHWND (), IDC_PREREQ_CHECK
, BST_CHECKED
);
58 // set the edit-area to a larger font
59 SetDlgItemFont(IDC_PREREQ_EDIT
, "MS Shell Dlg", 10);
63 PrereqPage::OnActivate()
65 // if we have gotten this far, then PrereqChecker has already run isMet
66 // and found that there were problems; so we can just call
67 // getUnmetString to format the results and display it
72 Log (LOG_PLAIN
) << s
<< endLog
;
74 // convert to CRLF line endings for Windows text box
76 while ((pos
= s
.find("\n", pos
)) != std::string::npos
)
78 s
.replace(pos
, 1, "\r\n");
81 SetDlgItemText (GetHWND (), IDC_PREREQ_EDIT
, s
.c_str ());
83 SetFocus (GetDlgItem (IDC_PREREQ_CHECK
));
92 if (!IsDlgButtonChecked (h
, IDC_PREREQ_CHECK
))
94 // breakage imminent! danger, danger
95 int res
= mbox (h
, IDS_PREREQ_UNSOLVED_PROBLEMS
,
96 MB_YESNO
| MB_ICONEXCLAMATION
| MB_DEFBUTTON2
);
102 "NOTE! User continued with unsolved problems! "
103 "Expect some packages to give errors or not function at all." << endLog
;
104 // Change the solver's transaction list to reflect the user's choices.
105 db
.solution
.db2trans();
110 db
.solution
.applyDefaultProblemSolutions();
120 PrereqPage::OnBack ()
122 // Add reinstall tasks
126 // Reset the package database to correspond to the solver's solution
128 db
.solution
.trans2db();
134 PrereqPage::OnUnattended ()
136 // in chooser-only mode, show this page so the user can choose to fix dependency problems or not
137 if (unattended_mode
== chooseronly
)
141 db
.solution
.applyDefaultProblemSolutions();
149 // ---------------------------------------------------------------------------
150 // implements class PrereqChecker
151 // ---------------------------------------------------------------------------
153 // instantiate the static members
154 bool PrereqChecker::use_test_packages
;
155 SolverTasks
PrereqChecker::q
;
158 PrereqChecker::isMet ()
162 Progress
.SetText1 (IDS_PROGRESS_SOLVING
);
163 Progress
.SetText2 ("");
164 Progress
.SetText3 ("");
166 // Create task list corresponding to current state of package database
169 // apply solver to those tasks and global state (use test or not)
170 return db
.solution
.update(q
, SolverSolution::keep
, use_test_packages
);
174 PrereqChecker::finalize ()
179 db
.solution
.addSource(IncludeSource
);
180 db
.solution
.dumpTransactionList();
184 PrereqChecker::augment ()
187 db
.solution
.augmentTasks(q
);
190 /* Formats problems and solutions as a string for display to the user. */
192 PrereqChecker::getUnmetString (std::string
&s
)
195 s
= db
.solution
.report();
198 // ---------------------------------------------------------------------------
199 // progress page glue
200 // ---------------------------------------------------------------------------
203 do_prereq_check_thread(HINSTANCE h
, HWND owner
)
211 retval
= IDD_CONFIRM
;
215 // rut-roh, some required things are not selected
223 do_prereq_check_reflector (void *p
)
226 context
= (HANDLE
*) p
;
228 SetThreadUILanguage(langid
);
232 int next_dialog
= do_prereq_check_thread ((HINSTANCE
) context
[0], (HWND
) context
[1]);
234 // Tell the progress page that we're done prereq checking
235 Progress
.PostMessageNow (WM_APP_PREREQ_CHECK_THREAD_COMPLETE
, 0, next_dialog
);
237 TOPLEVEL_CATCH((HWND
) context
[1], "prereq_check");
242 static HANDLE context
[2];
245 do_prereq_check (HINSTANCE h
, HWND owner
)
251 CreateThread (NULL
, 0, do_prereq_check_reflector
, context
, 0, &threadID
);