2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: lib/cpl/desk/classinst.c
5 * PURPOSE: Display class installer
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
16 DisplayClassInstaller(
17 IN DI_FUNCTION InstallFunction
,
18 IN HDEVINFO DeviceInfoSet
,
19 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
21 SP_DEVINSTALL_PARAMS InstallParams
;
22 SP_DRVINFO_DATA DriverInfoData
;
23 HINF hInf
= INVALID_HANDLE_VALUE
;
24 TCHAR SectionName
[MAX_PATH
];
25 TCHAR ServiceName
[MAX_SERVICE_NAME_LEN
];
26 SP_DRVINFO_DETAIL_DATA DriverInfoDetailData
;
27 HKEY hDriverKey
= INVALID_HANDLE_VALUE
;
28 HKEY hSettingsKey
= INVALID_HANDLE_VALUE
;
29 HKEY hServicesKey
= INVALID_HANDLE_VALUE
;
30 HKEY hServiceKey
= INVALID_HANDLE_VALUE
;
31 HKEY hDeviceSubKey
= INVALID_HANDLE_VALUE
;
36 if (InstallFunction
!= DIF_INSTALLDEVICE
)
37 return ERROR_DI_DO_DEFAULT
;
39 /* Set DI_NEEDRESTART flag */
40 InstallParams
.cbSize
= sizeof(SP_DEVINSTALL_PARAMS
);
41 result
= SetupDiGetDeviceInstallParams(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
45 DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc
);
49 InstallParams
.Flags
|= DI_NEEDRESTART
;
51 result
= SetupDiSetDeviceInstallParams(DeviceInfoSet
, DeviceInfoData
, &InstallParams
);
55 DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc
);
59 /* Get .inf file name and section name */
60 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
61 result
= SetupDiGetSelectedDriver(DeviceInfoSet
, DeviceInfoData
, &DriverInfoData
);
65 DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc
);
69 DriverInfoDetailData
.cbSize
= sizeof(SP_DRVINFO_DETAIL_DATA
);
70 result
= SetupDiGetDriverInfoDetail(
71 DeviceInfoSet
, DeviceInfoData
,
72 &DriverInfoData
, &DriverInfoDetailData
,
73 sizeof(SP_DRVINFO_DETAIL_DATA
), NULL
);
74 if (!result
&& GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
77 DPRINT("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", rc
);
81 hInf
= SetupOpenInfFile(DriverInfoDetailData
.InfFileName
, NULL
, INF_STYLE_WIN4
, NULL
);
82 if (hInf
== INVALID_HANDLE_VALUE
)
85 DPRINT("SetupOpenInfFile() failed with error 0x%lx\n", rc
);
89 result
= SetupDiGetActualSectionToInstall(
90 hInf
, DriverInfoDetailData
.SectionName
,
91 SectionName
, MAX_PATH
- _tcslen(_T(".SoftwareSettings")), NULL
, NULL
);
95 DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc
);
98 _tcscat(SectionName
, _T(".SoftwareSettings"));
100 /* Do normal install */
101 result
= SetupDiInstallDevice(DeviceInfoSet
, DeviceInfoData
);
105 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc
);
109 /* Open driver registry key and create Settings subkey */
110 hDriverKey
= SetupDiOpenDevRegKey(
111 DeviceInfoSet
, DeviceInfoData
,
112 DICS_FLAG_GLOBAL
, 0, DIREG_DRV
,
114 if (hDriverKey
== INVALID_HANDLE_VALUE
)
117 DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc
);
121 hDriverKey
, L
"Settings",
122 0, NULL
, REG_OPTION_NON_VOLATILE
,
123 #if _WIN32_WINNT >= 0x502
124 KEY_READ
| KEY_WRITE
,
128 NULL
, &hSettingsKey
, &disposition
);
129 if (rc
!= ERROR_SUCCESS
)
131 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
135 /* Install .SoftwareSettings to Settings subkey */
136 result
= SetupInstallFromInfSection(
137 InstallParams
.hwndParent
, hInf
, SectionName
,
138 SPINST_REGISTRY
, hSettingsKey
,
144 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
148 /* Get service name and open service registry key */
149 result
= SetupDiGetDeviceRegistryProperty(
150 DeviceInfoSet
, DeviceInfoData
,
152 (PBYTE
)ServiceName
, MAX_SERVICE_NAME_LEN
* sizeof(TCHAR
), NULL
);
156 DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc
);
161 HKEY_LOCAL_MACHINE
, _T("SYSTEM\\CurrentControlSet\\Services"),
162 0, KEY_ENUMERATE_SUB_KEYS
, &hServicesKey
);
163 if (rc
!= ERROR_SUCCESS
)
165 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
169 hServicesKey
, ServiceName
,
170 0, KEY_CREATE_SUB_KEY
, &hServiceKey
);
171 if (rc
!= ERROR_SUCCESS
)
173 DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc
);
177 /* Create a Device0 subkey (FIXME: do a loop to find a free number?) */
179 hServiceKey
, _T("Device0"), 0, NULL
,
180 REG_OPTION_NON_VOLATILE
, KEY_SET_VALUE
, NULL
,
181 &hDeviceSubKey
, &disposition
);
182 if (rc
!= ERROR_SUCCESS
)
184 DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc
);
187 if (disposition
!= REG_CREATED_NEW_KEY
)
189 rc
= ERROR_GEN_FAILURE
;
190 DPRINT("RegCreateKeyEx() failed\n");
194 /* Install SoftwareSettings section */
195 /* Yes, we're installing this section for the second time.
196 * We don't want to create a link to Settings subkey */
197 result
= SetupInstallFromInfSection(
198 InstallParams
.hwndParent
, hInf
, SectionName
,
199 SPINST_REGISTRY
, hDeviceSubKey
,
205 DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc
);
209 /* FIXME: install OpenGLSoftwareSettings section */
214 if (hInf
!= INVALID_HANDLE_VALUE
)
215 SetupCloseInfFile(hInf
);
216 if (hDriverKey
!= INVALID_HANDLE_VALUE
)
217 RegCloseKey(hDriverKey
);
218 if (hSettingsKey
!= INVALID_HANDLE_VALUE
)
219 RegCloseKey(hSettingsKey
);
220 if (hServicesKey
!= INVALID_HANDLE_VALUE
)
221 RegCloseKey(hServicesKey
);
222 if (hServiceKey
!= INVALID_HANDLE_VALUE
)
223 RegCloseKey(hServiceKey
);
224 if (hDeviceSubKey
!= INVALID_HANDLE_VALUE
)
225 RegCloseKey(hDeviceSubKey
);