display the "Reinstall Driver" button in case the installation previously failed
[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_DISABLED:
54 {
55 /* FIXME - display the "Enable Device" wizard */
56 break;
57 }
58
59 case CM_PROB_FAILED_INSTALL:
60 {
61 /* FIXME - display the driver installation wizard */
62 break;
63 }
64
65 default:
66 {
67 /* FIXME - troubleshoot the device */
68 break;
69 }
70 }
71 }
72
73 return Ret;
74 }
75
76
77 /***************************************************************************
78 * NAME EXPORTED
79 * DeviceProblemWizardA
80 *
81 * DESCRIPTION
82 * Calls the device problem wizard
83 *
84 * ARGUMENTS
85 * hWndParent: Handle to the parent window
86 * lpMachineName: Machine Name, NULL is the local machine
87 * lpDeviceID: Specifies the device, also see NOTEs
88 *
89 * RETURN VALUE
90 * TRUE: if no errors occured
91 * FALSE: if errors occured
92 *
93 * @implemented
94 */
95 BOOL
96 WINAPI
97 DeviceProblemWizardA(IN HWND hWndParent OPTIONAL,
98 IN LPCSTR lpMachineName OPTIONAL,
99 IN LPCSTR lpDeviceID)
100 {
101 LPWSTR lpMachineNameW = NULL;
102 LPWSTR lpDeviceIDW = NULL;
103 BOOL Ret = FALSE;
104
105 if (lpMachineName != NULL)
106 {
107 if (!(lpMachineNameW = ConvertMultiByteToUnicode(lpMachineName,
108 CP_ACP)))
109 {
110 goto Cleanup;
111 }
112 }
113 if (lpDeviceID != NULL)
114 {
115 if (!(lpDeviceIDW = ConvertMultiByteToUnicode(lpDeviceID,
116 CP_ACP)))
117 {
118 goto Cleanup;
119 }
120 }
121
122 Ret = DeviceProblemWizardW(hWndParent,
123 lpMachineNameW,
124 lpDeviceIDW);
125
126 Cleanup:
127 if (lpMachineNameW != NULL)
128 {
129 HeapFree(GetProcessHeap(),
130 0,
131 lpMachineNameW);
132 }
133 if (lpDeviceIDW != NULL)
134 {
135 HeapFree(GetProcessHeap(),
136 0,
137 lpDeviceIDW);
138 }
139
140 return Ret;
141 }
142
143
144 /***************************************************************************
145 * NAME EXPORTED
146 * DeviceProblemWizardW
147 *
148 * DESCRIPTION
149 * Calls the device problem wizard
150 *
151 * ARGUMENTS
152 * hWndParent: Handle to the parent window
153 * lpMachineName: Machine Name, NULL is the local machine
154 * lpDeviceID: Specifies the device, also see NOTEs
155 *
156 * RETURN VALUE
157 * TRUE: if no errors occured
158 * FALSE: if errors occured
159 *
160 * @unimplemented
161 */
162 BOOL
163 WINAPI
164 DeviceProblemWizardW(IN HWND hWndParent OPTIONAL,
165 IN LPCWSTR lpMachineName OPTIONAL,
166 IN LPCWSTR lpDeviceID)
167 {
168 HDEVINFO hDevInfo;
169 SP_DEVINFO_DATA DevInfoData;
170 HINSTANCE hComCtl32;
171 CONFIGRET cr;
172 HMACHINE hMachine;
173 BOOL Ret = FALSE;
174
175 if (lpDeviceID == NULL)
176 {
177 SetLastError(ERROR_INVALID_PARAMETER);
178 return FALSE;
179 }
180
181 /* dynamically load comctl32 */
182 hComCtl32 = LoadAndInitComctl32();
183 if (hComCtl32 != NULL)
184 {
185 hDevInfo = SetupDiCreateDeviceInfoListEx(NULL,
186 hWndParent,
187 lpMachineName,
188 NULL);
189 if (hDevInfo != INVALID_HANDLE_VALUE)
190 {
191 cr = CM_Connect_Machine(lpMachineName,
192 &hMachine);
193 if (cr == CR_SUCCESS)
194 {
195 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
196 if (SetupDiOpenDeviceInfo(hDevInfo,
197 lpDeviceID,
198 hWndParent,
199 0,
200 &DevInfoData))
201 {
202 Ret = ShowDeviceProblemWizard(hWndParent,
203 hDevInfo,
204 &DevInfoData,
205 hMachine);
206 }
207
208 CM_Disconnect_Machine(hMachine);
209 }
210
211 SetupDiDestroyDeviceInfoList(hDevInfo);
212 }
213
214 FreeLibrary(hComCtl32);
215 }
216
217 return Ret;
218 }