ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

classinst.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Display Control Panel
00004  * FILE:            dll/cpl/desk/classinst.c
00005  * PURPOSE:         Display class installer
00006  *
00007  * PROGRAMMERS:     Hervé Poussineau (hpoussin@reactos.org)
00008  */
00009 
00010 #include "desk.h"
00011 
00012 //#define NDEBUG
00013 #include <debug.h>
00014 
00015 DWORD WINAPI
00016 DisplayClassInstaller(
00017     IN DI_FUNCTION InstallFunction,
00018     IN HDEVINFO DeviceInfoSet,
00019     IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
00020 {
00021     SP_DEVINSTALL_PARAMS InstallParams;
00022     SP_DRVINFO_DATA DriverInfoData;
00023     HINF hInf = INVALID_HANDLE_VALUE;
00024     TCHAR SectionName[MAX_PATH];
00025     TCHAR ServiceName[MAX_SERVICE_NAME_LEN];
00026     SP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
00027     HKEY hDriverKey = INVALID_HANDLE_VALUE; /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
00028     HKEY hSettingsKey = NULL;
00029     HKEY hServicesKey = NULL;
00030     HKEY hServiceKey = NULL;
00031     HKEY hDeviceSubKey = NULL;
00032     DWORD disposition;
00033     BOOL result;
00034     LONG rc;
00035 
00036     if (InstallFunction != DIF_INSTALLDEVICE)
00037         return ERROR_DI_DO_DEFAULT;
00038 
00039     /* Set DI_DONOTCALLCONFIGMG flag */
00040     InstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
00041     result = SetupDiGetDeviceInstallParams(DeviceInfoSet, DeviceInfoData, &InstallParams);
00042     if (!result)
00043     {
00044         rc = GetLastError();
00045         DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc);
00046         goto cleanup;
00047     }
00048 
00049     InstallParams.Flags |= DI_DONOTCALLCONFIGMG;
00050 
00051     result = SetupDiSetDeviceInstallParams(DeviceInfoSet, DeviceInfoData, &InstallParams);
00052     if (!result)
00053     {
00054         rc = GetLastError();
00055         DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc);
00056         goto cleanup;
00057     }
00058 
00059     /* Do normal install */
00060     result = SetupDiInstallDevice(DeviceInfoSet, DeviceInfoData);
00061     if (!result)
00062     {
00063         rc = GetLastError();
00064         DPRINT("SetupDiInstallDevice() failed with error 0x%lx\n", rc);
00065         goto cleanup;
00066     }
00067 
00068     /* Get .inf file name and section name */
00069     DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
00070     result = SetupDiGetSelectedDriver(DeviceInfoSet, DeviceInfoData, &DriverInfoData);
00071     if (!result)
00072     {
00073         rc = GetLastError();
00074         DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc);
00075         goto cleanup;
00076     }
00077 
00078     DriverInfoDetailData.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
00079     result = SetupDiGetDriverInfoDetail(
00080         DeviceInfoSet, DeviceInfoData,
00081         &DriverInfoData, &DriverInfoDetailData,
00082         sizeof(SP_DRVINFO_DETAIL_DATA), NULL);
00083     if (!result && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
00084     {
00085         rc = GetLastError();
00086         DPRINT("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", rc);
00087         goto cleanup;
00088     }
00089 
00090     hInf = SetupOpenInfFile(DriverInfoDetailData.InfFileName, NULL, INF_STYLE_WIN4, NULL);
00091     if (hInf == INVALID_HANDLE_VALUE)
00092     {
00093         rc = GetLastError();
00094         DPRINT("SetupOpenInfFile() failed with error 0x%lx\n", rc);
00095         goto cleanup;
00096     }
00097 
00098     result = SetupDiGetActualSectionToInstall(
00099         hInf, DriverInfoDetailData.SectionName,
00100         SectionName, MAX_PATH - _tcslen(_T(".SoftwareSettings")), NULL, NULL);
00101     if (!result)
00102     {
00103         rc = GetLastError();
00104         DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc);
00105         goto cleanup;
00106     }
00107     _tcscat(SectionName, _T(".SoftwareSettings"));
00108 
00109     /* Open driver registry key and create Settings subkey */
00110     hDriverKey = SetupDiOpenDevRegKey(
00111         DeviceInfoSet, DeviceInfoData,
00112         DICS_FLAG_GLOBAL, 0, DIREG_DRV,
00113         KEY_CREATE_SUB_KEY);
00114     if (hDriverKey == INVALID_HANDLE_VALUE)
00115     {
00116         rc = GetLastError();
00117         DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc);
00118         goto cleanup;
00119     }
00120     rc = RegCreateKeyEx(
00121         hDriverKey, L"Settings",
00122         0, NULL, REG_OPTION_NON_VOLATILE,
00123 #if _WIN32_WINNT >= 0x502
00124         KEY_READ | KEY_WRITE,
00125 #else
00126         KEY_ALL_ACCESS,
00127 #endif
00128         NULL, &hSettingsKey, &disposition);
00129     if (rc != ERROR_SUCCESS)
00130     {
00131         DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc);
00132         goto cleanup;
00133     }
00134 
00135     /* Install .SoftwareSettings to Settings subkey */
00136     result = SetupInstallFromInfSection(
00137         InstallParams.hwndParent, hInf, SectionName,
00138         SPINST_REGISTRY, hSettingsKey,
00139         NULL, 0, NULL, NULL,
00140         NULL, NULL);
00141     if (!result)
00142     {
00143         rc = GetLastError();
00144         DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc);
00145         goto cleanup;
00146     }
00147 
00148     /* Get service name and open service registry key */
00149     result = SetupDiGetDeviceRegistryProperty(
00150         DeviceInfoSet, DeviceInfoData,
00151         SPDRP_SERVICE, NULL,
00152         (PBYTE)ServiceName, MAX_SERVICE_NAME_LEN * sizeof(TCHAR), NULL);
00153     if (!result)
00154     {
00155         rc = GetLastError();
00156         DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc);
00157         goto cleanup;
00158     }
00159 
00160     rc = RegOpenKeyEx(
00161         HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services"),
00162         0, KEY_ENUMERATE_SUB_KEYS, &hServicesKey);
00163     if (rc != ERROR_SUCCESS)
00164     {
00165         DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc);
00166         goto cleanup;
00167     }
00168     rc = RegOpenKeyEx(
00169         hServicesKey, ServiceName,
00170         0, KEY_CREATE_SUB_KEY, &hServiceKey);
00171     if (rc != ERROR_SUCCESS)
00172     {
00173         DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc);
00174         goto cleanup;
00175     }
00176 
00177     /* Create a Device0 subkey (FIXME: do a loop to find a free number?) */
00178     rc = RegCreateKeyEx(
00179         hServiceKey, _T("Device0"), 0, NULL,
00180         REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL,
00181         &hDeviceSubKey, &disposition);
00182     if (rc != ERROR_SUCCESS)
00183     {
00184         DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc);
00185         goto cleanup;
00186     }
00187     if (disposition != REG_CREATED_NEW_KEY)
00188     {
00189         rc = ERROR_GEN_FAILURE;
00190         DPRINT("RegCreateKeyEx() failed\n");
00191         goto cleanup;
00192     }
00193 
00194     /* Install SoftwareSettings section */
00195     /* Yes, we're installing this section for the second time.
00196      * We don't want to create a link to Settings subkey */
00197     result = SetupInstallFromInfSection(
00198         InstallParams.hwndParent, hInf, SectionName,
00199         SPINST_REGISTRY, hDeviceSubKey,
00200         NULL, 0, NULL, NULL,
00201         NULL, NULL);
00202     if (!result)
00203     {
00204         rc = GetLastError();
00205         DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc);
00206         goto cleanup;
00207     }
00208 
00209     /* FIXME: install OpenGLSoftwareSettings section */
00210 
00211     rc = ERROR_SUCCESS;
00212 
00213 cleanup:
00214     if (hInf != INVALID_HANDLE_VALUE)
00215         SetupCloseInfFile(hInf);
00216     if (hDriverKey != INVALID_HANDLE_VALUE)
00217     {
00218         /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
00219         RegCloseKey(hDriverKey);
00220     }
00221     if (hSettingsKey != NULL)
00222         RegCloseKey(hSettingsKey);
00223     if (hServicesKey != NULL)
00224         RegCloseKey(hServicesKey);
00225     if (hServiceKey != NULL)
00226         RegCloseKey(hServiceKey);
00227     if (hDeviceSubKey != NULL)
00228         RegCloseKey(hDeviceSubKey);
00229 
00230     return rc;
00231 }

Generated on Sun May 27 2012 04:20:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.