Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / prereq.cc
blob8c96cebf4f53c32ae0e271524f97dc52936b52c0
1 /*
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
10 * http://www.gnu.org/
12 * Written by Brian Dessent <brian@dessent.net>
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"
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},
31 {0, CP_LEFT, CP_TOP}
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);
46 bool
47 PrereqPage::Create ()
49 return PropertyPage::Create (IDD_PREREQ);
52 void
53 PrereqPage::OnInit ()
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);
62 void
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
69 std::string s;
70 PrereqChecker p;
71 p.getUnmetString (s);
72 Log (LOG_PLAIN) << s << endLog;
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)
78 s.replace(pos, 1, "\r\n");
79 pos += 2;
81 SetDlgItemText (GetHWND (), IDC_PREREQ_EDIT, s.c_str ());
83 SetFocus (GetDlgItem (IDC_PREREQ_CHECK));
86 long
87 PrereqPage::OnNext ()
89 HWND h = GetHWND ();
90 packagedb db;
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);
97 if (res == IDNO)
98 return -1;
99 else
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();
108 else
110 db.solution.applyDefaultProblemSolutions();
113 PrereqChecker p;
114 p.finalize();
116 return IDD_CONFIRM;
119 long
120 PrereqPage::OnBack ()
122 // Add reinstall tasks
123 PrereqChecker p;
124 p.augment();
126 // Reset the package database to correspond to the solver's solution
127 packagedb db;
128 db.solution.trans2db();
130 return IDD_CHOOSE;
133 long
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)
138 return -1;
140 packagedb db;
141 db.solution.applyDefaultProblemSolutions();
143 PrereqChecker p;
144 p.finalize();
146 return IDD_CONFIRM;
149 // ---------------------------------------------------------------------------
150 // implements class PrereqChecker
151 // ---------------------------------------------------------------------------
153 // instantiate the static members
154 bool PrereqChecker::use_test_packages;
155 SolverTasks PrereqChecker::q;
157 bool
158 PrereqChecker::isMet ()
160 packagedb db;
162 Progress.SetText1 (IDS_PROGRESS_SOLVING);
163 Progress.SetText2 ("");
164 Progress.SetText3 ("");
166 // Create task list corresponding to current state of package database
167 q.setTasks();
169 // apply solver to those tasks and global state (use test or not)
170 return db.solution.update(q, SolverSolution::keep, use_test_packages);
173 void
174 PrereqChecker::finalize ()
176 augment();
178 packagedb db;
179 db.solution.addSource(IncludeSource);
180 db.solution.dumpTransactionList();
183 void
184 PrereqChecker::augment ()
186 packagedb db;
187 db.solution.augmentTasks(q);
190 /* Formats problems and solutions as a string for display to the user. */
191 void
192 PrereqChecker::getUnmetString (std::string &s)
194 packagedb db;
195 s = db.solution.report();
198 // ---------------------------------------------------------------------------
199 // progress page glue
200 // ---------------------------------------------------------------------------
202 static int
203 do_prereq_check_thread(HINSTANCE h, HWND owner)
205 PrereqChecker p;
206 int retval;
208 if (p.isMet ())
210 p.finalize();
211 retval = IDD_CONFIRM;
213 else
215 // rut-roh, some required things are not selected
216 retval = IDD_PREREQ;
219 return retval;
222 static DWORD WINAPI
223 do_prereq_check_reflector (void *p)
225 HANDLE *context;
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");
239 ExitThread(0);
242 static HANDLE context[2];
244 void
245 do_prereq_check (HINSTANCE h, HWND owner)
247 context[0] = h;
248 context[1] = owner;
250 DWORD threadID;
251 CreateThread (NULL, 0, do_prereq_check_reflector, context, 0, &threadID);