c4ffcd852830051188f1bf0f08a226ed8655e85b
[reactos.git] / reactos / lib / devmgr / devprblm.c
1 /*
2 * ReactOS Device Manager Applet
3 * Copyright (C) 2004 - 2005 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* $Id: hwpage.c 19599 2005-11-26 02:12:58Z weiden $
20 *
21 * PROJECT: ReactOS devmgr.dll
22 * FILE: lib/devmgr/devprblm.c
23 * PURPOSE: ReactOS Device Manager
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
25 * UPDATE HISTORY:
26 * 04-04-2004 Created
27 */
28 #include <precomp.h>
29
30 #define NDEBUG
31 #include <debug.h>
32
33
34 BOOL
35 ShowDeviceProblemWizard(IN HWND hWndParent OPTIONAL,
36 IN HDEVINFO hDevInfo,
37 IN PSP_DEVINFO_DATA DevInfoData,
38 IN HMACHINE hMachine OPTIONAL)
39 {
40 CONFIGRET cr;
41 ULONG Status, ProblemNumber;
42 BOOL Ret = FALSE;
43
44 cr = CM_Get_DevNode_Status_Ex(&Status,
45 &ProblemNumber,
46 DevInfoData->DevInst,
47 0,
48 hMachine);
49 if (cr == CR_SUCCESS && (Status & DN_HAS_PROBLEM))
50 {
51 switch (ProblemNumber)
52 {
53 case CM_PROB_DEVLOADER_FAILED:
54 {
55 /* FIXME - only if it's not a root bus devloader */
56 /* FIXME - display the update driver wizard */
57 break;
58 }
59
60 case CM_PROB_OUT_OF_MEMORY:
61 case CM_PROB_ENTRY_IS_WRONG_TYPE:
62 case CM_PROB_LACKED_ARBITRATOR:
63 case CM_PROB_FAILED_START:
64 case CM_PROB_LIAR:
65 case CM_PROB_UNKNOWN_RESOURCE:
66 {
67 /* FIXME - display the update driver wizard */
68 break;
69 }
70
71 case CM_PROB_BOOT_CONFIG_CONFLICT:
72 case CM_PROB_NORMAL_CONFLICT:
73 case CM_PROB_REENUMERATION:
74 {
75 /* FIXME - display the conflict wizard */
76 break;
77 }
78
79 case CM_PROB_FAILED_FILTER:
80 case CM_PROB_REINSTALL:
81 case CM_PROB_FAILED_INSTALL:
82 {
83 /* FIXME - display the driver (re)installation wizard */
84 break;
85 }
86
87 case CM_PROB_DEVLOADER_NOT_FOUND:
88 {
89 /* FIXME - 4 cases:
90 1) if it's a missing system devloader:
91 - fail
92 2) if it's not a system devloader but still missing:
93 - display the driver reinstallation wizard
94 3) if it's not a system devloader but the file can be found:
95 - display the update driver wizard
96 4) if it's a missing or empty software key
97 - display the update driver wizard
98 */
99 break;
100 }
101
102 case CM_PROB_INVALID_DATA:
103 case CM_PROB_PARTIAL_LOG_CONF:
104 case CM_PROB_NO_VALID_LOG_CONF:
105 case CM_PROB_HARDWARE_DISABLED:
106 case CM_PROB_CANT_SHARE_IRQ:
107 case CM_PROB_TRANSLATION_FAILED:
108 case CM_PROB_SYSTEM_SHUTDOWN:
109 case CM_PROB_PHANTOM:
110 /* FIXME - do nothing */
111 break;
112
113 case CM_PROB_NOT_VERIFIED:
114 case CM_PROB_DEVICE_NOT_THERE:
115 /* FIXME - display search hardware wizard */
116 break;
117
118 case CM_PROB_NEED_RESTART:
119 case CM_PROB_WILL_BE_REMOVED:
120 case CM_PROB_MOVED:
121 case CM_PROB_TOO_EARLY:
122 case CM_PROB_DISABLED_SERVICE:
123 /* FIXME - reboot computer */
124 break;
125
126 case CM_PROB_REGISTRY:
127 /* FIXME - check registry */
128 break;
129
130 case CM_PROB_DISABLED:
131 {
132 /* FIXME - if device was disabled by user display the "Enable Device" wizard,
133 otherwise Troubleshoot because the device was disabled by the system */
134 break;
135 }
136
137 case CM_PROB_DEVLOADER_NOT_READY:
138 {
139 /* FIXME - if it's a graphics adapter:
140 - if it's a a secondary adapter and the main adapter
141 couldn't be found
142 - do nothing or default action
143 - else
144 - display the Properties
145 - else
146 - Update driver
147 */
148 break;
149 }
150
151 case CM_PROB_FAILED_ADD:
152 {
153 /* FIXME - display the properties of the sub-device */
154 break;
155 }
156
157 case CM_PROB_NO_SOFTCONFIG:
158 case CM_PROB_IRQ_TRANSLATION_FAILED:
159 case CM_PROB_FAILED_DRIVER_ENTRY:
160 case CM_PROB_DRIVER_FAILED_PRIOR_UNLOAD:
161 case CM_PROB_DRIVER_FAILED_LOAD:
162 case CM_PROB_DRIVER_SERVICE_KEY_INVALID:
163 case CM_PROB_LEGACY_SERVICE_NO_DEVICES:
164 case CM_PROB_DUPLICATE_DEVICE:
165 case CM_PROB_FAILED_POST_START:
166 case CM_PROB_HALTED:
167 case CM_PROB_HELD_FOR_EJECT:
168 case CM_PROB_DRIVER_BLOCKED:
169 case CM_PROB_REGISTRY_TOO_LARGE:
170 default:
171 {
172 /* FIXME - troubleshoot the device */
173 break;
174 }
175 }
176 }
177
178 return Ret;
179 }
180
181
182 /***************************************************************************
183 * NAME EXPORTED
184 * DeviceProblemWizardA
185 *
186 * DESCRIPTION
187 * Calls the device problem wizard
188 *
189 * ARGUMENTS
190 * hWndParent: Handle to the parent window
191 * lpMachineName: Machine Name, NULL is the local machine
192 * lpDeviceID: Specifies the device, also see NOTEs
193 *
194 * RETURN VALUE
195 * TRUE: if no errors occured
196 * FALSE: if errors occured
197 *
198 * @implemented
199 */
200 BOOL
201 WINAPI
202 DeviceProblemWizardA(IN HWND hWndParent OPTIONAL,
203 IN LPCSTR lpMachineName OPTIONAL,
204 IN LPCSTR lpDeviceID)
205 {
206 LPWSTR lpMachineNameW = NULL;
207 LPWSTR lpDeviceIDW = NULL;
208 BOOL Ret = FALSE;
209
210 if (lpMachineName != NULL)
211 {
212 if (!(lpMachineNameW = ConvertMultiByteToUnicode(lpMachineName,
213 CP_ACP)))
214 {
215 goto Cleanup;
216 }
217 }
218 if (lpDeviceID != NULL)
219 {
220 if (!(lpDeviceIDW = ConvertMultiByteToUnicode(lpDeviceID,
221 CP_ACP)))
222 {
223 goto Cleanup;
224 }
225 }
226
227 Ret = DeviceProblemWizardW(hWndParent,
228 lpMachineNameW,
229 lpDeviceIDW);
230
231 Cleanup:
232 if (lpMachineNameW != NULL)
233 {
234 HeapFree(GetProcessHeap(),
235 0,
236 lpMachineNameW);
237 }
238 if (lpDeviceIDW != NULL)
239 {
240 HeapFree(GetProcessHeap(),
241 0,
242 lpDeviceIDW);
243 }
244
245 return Ret;
246 }
247
248
249 /***************************************************************************
250 * NAME EXPORTED
251 * DeviceProblemWizardW
252 *
253 * DESCRIPTION
254 * Calls the device problem wizard
255 *
256 * ARGUMENTS
257 * hWndParent: Handle to the parent window
258 * lpMachineName: Machine Name, NULL is the local machine
259 * lpDeviceID: Specifies the device, also see NOTEs
260 *
261 * RETURN VALUE
262 * TRUE: if no errors occured
263 * FALSE: if errors occured
264 *
265 * @unimplemented
266 */
267 BOOL
268 WINAPI
269 DeviceProblemWizardW(IN HWND hWndParent OPTIONAL,
270 IN LPCWSTR lpMachineName OPTIONAL,
271 IN LPCWSTR lpDeviceID)
272 {
273 HDEVINFO hDevInfo;
274 SP_DEVINFO_DATA DevInfoData;
275 HINSTANCE hComCtl32;
276 CONFIGRET cr;
277 HMACHINE hMachine;
278 BOOL Ret = FALSE;
279
280 if (lpDeviceID == NULL)
281 {
282 SetLastError(ERROR_INVALID_PARAMETER);
283 return FALSE;
284 }
285
286 /* dynamically load comctl32 */
287 hComCtl32 = LoadAndInitComctl32();
288 if (hComCtl32 != NULL)
289 {
290 hDevInfo = SetupDiCreateDeviceInfoListEx(NULL,
291 hWndParent,
292 lpMachineName,
293 NULL);
294 if (hDevInfo != INVALID_HANDLE_VALUE)
295 {
296 cr = CM_Connect_Machine(lpMachineName,
297 &hMachine);
298 if (cr == CR_SUCCESS)
299 {
300 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
301 if (SetupDiOpenDeviceInfo(hDevInfo,
302 lpDeviceID,
303 hWndParent,
304 0,
305 &DevInfoData))
306 {
307 Ret = ShowDeviceProblemWizard(hWndParent,
308 hDevInfo,
309 &DevInfoData,
310 hMachine);
311 }
312
313 CM_Disconnect_Machine(hMachine);
314 }
315
316 SetupDiDestroyDeviceInfoList(hDevInfo);
317 }
318
319 FreeLibrary(hComCtl32);
320 }
321
322 return Ret;
323 }