]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2005 Brian Dessent | |
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 Brian Dessent <brian@dessent.net> | |
13 | * | |
14 | */ | |
15 | ||
16 | #include "prereq.h" | |
17 | #include "resource.h" | |
18 | #include "state.h" | |
19 | #include "threebar.h" | |
20 | #include "LogSingleton.h" | |
21 | #include "ControlAdjuster.h" | |
22 | #include "package_db.h" | |
23 | ||
24 | #include "Exception.h" | |
25 | #include "getopt++/BoolOption.h" | |
26 | ||
27 | // Sizing information. | |
28 | static ControlAdjuster::ControlInfo PrereqControlsInfo[] = { | |
29 | {IDC_PREREQ_CHECK, CP_LEFT, CP_BOTTOM}, | |
30 | {IDC_PREREQ_EDIT, CP_STRETCH, CP_STRETCH}, | |
31 | {0, CP_LEFT, CP_TOP} | |
32 | }; | |
33 | ||
34 | extern ThreeBarProgressPage Progress; | |
35 | BoolOption IncludeSource (false, 'I', "include-source", IDS_HELPTEXT_INCLUDE_SOURCE); | |
36 | ||
37 | // --------------------------------------------------------------------------- | |
38 | // implements class PrereqPage | |
39 | // --------------------------------------------------------------------------- | |
40 | ||
41 | PrereqPage::PrereqPage () | |
42 | { | |
43 | sizeProcessor.AddControlInfo (PrereqControlsInfo); | |
44 | } | |
45 | ||
46 | bool | |
47 | PrereqPage::Create () | |
48 | { | |
49 | return PropertyPage::Create (IDD_PREREQ); | |
50 | } | |
51 | ||
52 | void | |
53 | PrereqPage::OnInit () | |
54 | { | |
55 | // start with the checkbox set | |
56 | CheckDlgButton (GetHWND (), IDC_PREREQ_CHECK, BST_CHECKED); | |
57 | ||
58 | // set the edit-area to a larger font | |
59 | SetDlgItemFont(IDC_PREREQ_EDIT, "MS Shell Dlg", 10); | |
60 | } | |
61 | ||
62 | void | |
63 | PrereqPage::OnActivate() | |
64 | { | |
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 | |
68 | ||
69 | std::string s; | |
70 | PrereqChecker p; | |
71 | p.getUnmetString (s); | |
72 | Log (LOG_PLAIN) << s << endLog; | |
73 | ||
74 | // convert to CRLF line endings for Windows text box | |
75 | size_t pos = 0; | |
76 | while ((pos = s.find("\n", pos)) != std::string::npos) | |
77 | { | |
78 | s.replace(pos, 1, "\r\n"); | |
79 | pos += 2; | |
80 | } | |
81 | SetDlgItemText (GetHWND (), IDC_PREREQ_EDIT, s.c_str ()); | |
82 | ||
83 | SetFocus (GetDlgItem (IDC_PREREQ_CHECK)); | |
84 | } | |
85 | ||
86 | long | |
87 | PrereqPage::OnNext () | |
88 | { | |
89 | HWND h = GetHWND (); | |
90 | packagedb db; | |
91 | ||
92 | if (!IsDlgButtonChecked (h, IDC_PREREQ_CHECK)) | |
93 | { | |
94 | // breakage imminent! danger, danger | |
95 | int res = mbox (h, IDS_PREREQ_UNSOLVED_PROBLEMS, | |
96 | MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2); | |
97 | if (res == IDNO) | |
98 | return -1; | |
99 | else | |
100 | { | |
101 | Log (LOG_PLAIN) << | |
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(); | |
106 | } | |
107 | } | |
108 | else | |
109 | { | |
110 | db.solution.applyDefaultProblemSolutions(); | |
111 | } | |
112 | ||
113 | PrereqChecker p; | |
114 | p.finalize(); | |
115 | ||
116 | return IDD_CONFIRM; | |
117 | } | |
118 | ||
119 | long | |
120 | PrereqPage::OnBack () | |
121 | { | |
122 | // Add reinstall tasks | |
123 | PrereqChecker p; | |
124 | p.augment(); | |
125 | ||
126 | // Reset the package database to correspond to the solver's solution | |
127 | packagedb db; | |
128 | db.solution.trans2db(); | |
129 | ||
130 | return IDD_CHOOSE; | |
131 | } | |
132 | ||
133 | long | |
134 | PrereqPage::OnUnattended () | |
135 | { | |
136 | // in chooser-only mode, show this page so the user can choose to fix dependency problems or not | |
137 | if (unattended_mode == chooseronly) | |
138 | return -1; | |
139 | ||
140 | packagedb db; | |
141 | db.solution.applyDefaultProblemSolutions(); | |
142 | ||
143 | PrereqChecker p; | |
144 | p.finalize(); | |
145 | ||
146 | return IDD_CONFIRM; | |
147 | } | |
148 | ||
149 | // --------------------------------------------------------------------------- | |
150 | // implements class PrereqChecker | |
151 | // --------------------------------------------------------------------------- | |
152 | ||
153 | // instantiate the static members | |
154 | bool PrereqChecker::use_test_packages; | |
155 | SolverTasks PrereqChecker::q; | |
156 | ||
157 | bool | |
158 | PrereqChecker::isMet () | |
159 | { | |
160 | packagedb db; | |
161 | ||
162 | Progress.SetText1 (IDS_PROGRESS_SOLVING); | |
163 | Progress.SetText2 (""); | |
164 | Progress.SetText3 (""); | |
165 | ||
166 | // Create task list corresponding to current state of package database | |
167 | q.setTasks(); | |
168 | ||
169 | // apply solver to those tasks and global state (use test or not) | |
170 | return db.solution.update(q, SolverSolution::keep, use_test_packages); | |
171 | } | |
172 | ||
173 | void | |
174 | PrereqChecker::finalize () | |
175 | { | |
176 | augment(); | |
177 | ||
178 | packagedb db; | |
179 | db.solution.addSource(IncludeSource); | |
180 | db.solution.dumpTransactionList(); | |
181 | } | |
182 | ||
183 | void | |
184 | PrereqChecker::augment () | |
185 | { | |
186 | packagedb db; | |
187 | db.solution.augmentTasks(q); | |
188 | } | |
189 | ||
190 | /* Formats problems and solutions as a string for display to the user. */ | |
191 | void | |
192 | PrereqChecker::getUnmetString (std::string &s) | |
193 | { | |
194 | packagedb db; | |
195 | s = db.solution.report(); | |
196 | } | |
197 | ||
198 | // --------------------------------------------------------------------------- | |
199 | // progress page glue | |
200 | // --------------------------------------------------------------------------- | |
201 | ||
202 | static int | |
203 | do_prereq_check_thread(HINSTANCE h, HWND owner) | |
204 | { | |
205 | PrereqChecker p; | |
206 | int retval; | |
207 | ||
208 | if (p.isMet ()) | |
209 | { | |
210 | p.finalize(); | |
211 | retval = IDD_CONFIRM; | |
212 | } | |
213 | else | |
214 | { | |
215 | // rut-roh, some required things are not selected | |
216 | retval = IDD_PREREQ; | |
217 | } | |
218 | ||
219 | return retval; | |
220 | } | |
221 | ||
222 | static DWORD WINAPI | |
223 | do_prereq_check_reflector (void *p) | |
224 | { | |
225 | HANDLE *context; | |
226 | context = (HANDLE *) p; | |
227 | ||
228 | SetThreadUILanguage(langid); | |
229 | ||
230 | try | |
231 | { | |
232 | int next_dialog = do_prereq_check_thread ((HINSTANCE) context[0], (HWND) context[1]); | |
233 | ||
234 | // Tell the progress page that we're done prereq checking | |
235 | Progress.PostMessageNow (WM_APP_PREREQ_CHECK_THREAD_COMPLETE, 0, next_dialog); | |
236 | } | |
237 | TOPLEVEL_CATCH((HWND) context[1], "prereq_check"); | |
238 | ||
239 | ExitThread(0); | |
240 | } | |
241 | ||
242 | static HANDLE context[2]; | |
243 | ||
244 | void | |
245 | do_prereq_check (HINSTANCE h, HWND owner) | |
246 | { | |
247 | context[0] = h; | |
248 | context[1] = owner; | |
249 | ||
250 | DWORD threadID; | |
251 | CreateThread (NULL, 0, do_prereq_check_reflector, context, 0, &threadID); | |
252 | } |