Example #1
0
static LPWSTR get_source_id( HINF hinf, PINFCONTEXT context, PCWSTR filename )
{
    WCHAR Section[MAX_PATH];
    DWORD size;
    LPWSTR source_id;

    if (!SetupDiGetActualSectionToInstallW(hinf, source_disks_files, Section, MAX_PATH, NULL, NULL))
        return NULL;

    if (!SetupFindFirstLineW( hinf, Section, filename, context ) &&
        !SetupFindFirstLineW( hinf, source_disks_files, filename, context ))
        return NULL;

    if (!SetupGetStringFieldW( context, 1, NULL, 0, &size ))
        return NULL;

    if (!(source_id = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) )))
        return NULL;

    if (!SetupGetStringFieldW( context, 1, source_id, size, NULL ))
    {
        HeapFree( GetProcessHeap(), 0, source_id );
        return NULL;
    }

    if (!SetupDiGetActualSectionToInstallW(hinf, source_disks_names, Section, MAX_PATH, NULL, NULL))
    {
        HeapFree( GetProcessHeap(), 0, source_id );
        return NULL;
    }

    if (!SetupFindFirstLineW( hinf, Section, source_id, context ) &&
        !SetupFindFirstLineW( hinf, source_disks_names, source_id, context ))
    {
        HeapFree( GetProcessHeap(), 0, source_id );
        return NULL;
    }
    return source_id;
}
Example #2
0
BOOL WINAPI SetupGetSourceInfoW( HINF hinf, UINT source_id, UINT info,
                                 PWSTR buffer, DWORD buffer_size, LPDWORD required_size )
{
    WCHAR Section[MAX_PATH];
    INFCONTEXT ctx;
    WCHAR source_id_str[11];
    static const WCHAR fmt[] = {'%','d',0};
    DWORD index;

    TRACE("%p, %d, %d, %p, %d, %p\n", hinf, source_id, info, buffer, buffer_size,
          required_size);

    sprintfW( source_id_str, fmt, source_id );

    if (!SetupDiGetActualSectionToInstallW(hinf, source_disks_names, Section, MAX_PATH, NULL, NULL))
        return FALSE;

    if (!SetupFindFirstLineW( hinf, Section, source_id_str, &ctx ) &&
        !SetupFindFirstLineW( hinf, source_disks_names, source_id_str, &ctx ))
        return FALSE;

    switch (info)
    {
    case SRCINFO_PATH:          index = 4; break;
    case SRCINFO_TAGFILE:       index = 2; break;
    case SRCINFO_DESCRIPTION:   index = 1; break;
    default:
        WARN("unknown info level: %d\n", info);
        return FALSE;
    }

    if (SetupGetStringFieldW( &ctx, index, buffer, buffer_size, required_size ))
        return TRUE;

    if (required_size) *required_size = 1;
    if (buffer)
    {
        if (buffer_size >= 1) buffer[0] = 0;
        else
        {
            SetLastError( ERROR_INSUFFICIENT_BUFFER );
            return FALSE;
        }
    }
    return TRUE;
}
Example #3
0
DWORD WINAPI
NetClassInstaller(
	IN DI_FUNCTION InstallFunction,
	IN HDEVINFO DeviceInfoSet,
	IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
{
	SP_DRVINFO_DATA_W DriverInfoData;
	SP_DRVINFO_DETAIL_DATA_W DriverInfoDetail;
	WCHAR SectionName[LINE_LEN];
	HINF hInf = INVALID_HANDLE_VALUE;
	INFCONTEXT InfContext;
	UINT ErrorLine;
	INT CharacteristicsInt;
	DWORD Characteristics;
	LPWSTR BusType = NULL;
	RPC_STATUS RpcStatus;
	UUID Uuid;
	LPWSTR UuidRpcString = NULL;
	LPWSTR UuidString = NULL;
	LONG rc;
	DWORD dwLength;

	if (InstallFunction != DIF_INSTALLDEVICE)
		return ERROR_DI_DO_DEFAULT;

	DPRINT("%lu %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);

	/* Get driver info details */
	DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA_W);
	if (!SetupDiGetSelectedDriverW(DeviceInfoSet, DeviceInfoData, &DriverInfoData))
	{
		rc = GetLastError();
		DPRINT("SetupDiGetSelectedDriverW() failed with error 0x%lx\n", rc);
		goto cleanup;
	}
	DriverInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA_W);
	if (!SetupDiGetDriverInfoDetailW(DeviceInfoSet, DeviceInfoData, &DriverInfoData, &DriverInfoDetail, sizeof(DriverInfoDetail), NULL)
	 && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
	{
		rc = GetLastError();
		DPRINT("SetupDiGetDriverInfoDetailW() failed with error 0x%lx\n", rc);
		goto cleanup;
	}
	hInf = SetupOpenInfFileW(DriverInfoDetail.InfFileName, NULL, INF_STYLE_WIN4, &ErrorLine);
	if (hInf == INVALID_HANDLE_VALUE)
	{
		rc = GetLastError();
		DPRINT("SetupOpenInfFileW() failed with error 0x%lx\n", rc);
		goto cleanup;
	}
	if (!SetupDiGetActualSectionToInstallW(hInf, DriverInfoDetail.SectionName, SectionName, LINE_LEN, NULL, NULL))
	{
		rc = GetLastError();
		DPRINT("SetupDiGetActualSectionToInstallW() failed with error 0x%lx\n", rc);
		goto cleanup;
	}

	/* Get Characteristics and BusType (optional) from .inf file */
	if (!SetupFindFirstLineW(hInf, SectionName, L"Characteristics", &InfContext))
	{
		rc = GetLastError();
		DPRINT("Unable to find key %S in section %S of file %S (error 0x%lx)\n",
			L"Characteristics", SectionName, DriverInfoDetail.InfFileName, rc);
		goto cleanup;
	}
	if (!SetupGetIntField(&InfContext, 1, &CharacteristicsInt))
	{
		rc = GetLastError();
		DPRINT("SetupGetIntField() failed with error 0x%lx\n", rc);
		goto cleanup;
	}
	Characteristics = (DWORD)CharacteristicsInt;
	if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NET))
	{
		if (SetupFindFirstLineW(hInf, SectionName, L"BusType", &InfContext))
		{
			if (!SetupGetStringFieldW(&InfContext, 1, NULL, 0, &dwLength))
			{
				rc = GetLastError();
				DPRINT("SetupGetStringFieldW() failed with error 0x%lx\n", rc);
				goto cleanup;
			}
			BusType = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
			if (!BusType)
			{
				DPRINT("HeapAlloc() failed\n");
				rc = ERROR_NOT_ENOUGH_MEMORY;
				goto cleanup;
			}
			if (!SetupGetStringFieldW(&InfContext, 1, BusType, dwLength, NULL))
			{
				rc = GetLastError();
				DPRINT("SetupGetStringFieldW() failed with error 0x%lx\n", rc);
				goto cleanup;
			}
		}
	}

	/* Create a new UUID */
	RpcStatus = UuidCreate(&Uuid);
	if (RpcStatus != RPC_S_OK && RpcStatus != RPC_S_UUID_LOCAL_ONLY)
	{
		DPRINT("UuidCreate() failed with RPC status 0x%lx\n", RpcStatus);
		rc = ERROR_GEN_FAILURE;
		goto cleanup;
	}
	RpcStatus = UuidToStringW(&Uuid, &UuidRpcString);
	if (RpcStatus != RPC_S_OK)
	{
		DPRINT("UuidToStringW() failed with RPC status 0x%lx\n", RpcStatus);
		rc = ERROR_GEN_FAILURE;
		goto cleanup;
	}

	/* Add curly braces around Uuid */
	UuidString = HeapAlloc(GetProcessHeap(), 0, (2 + wcslen(UuidRpcString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
	if (!UuidString)
	{
		DPRINT("HeapAlloc() failed\n");
		rc = ERROR_NOT_ENOUGH_MEMORY;
		goto cleanup;
	}
	wcscpy(UuidString, L"{");
	wcscat(UuidString, UuidRpcString);
	wcscat(UuidString, L"}");

	if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NET))
		rc = InstallNetDevice(DeviceInfoSet, DeviceInfoData, UuidString, Characteristics, BusType);
	else if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NETCLIENT))
		rc = InstallNetClient();
	else if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NETSERVICE))
		rc = InstallNetService();
	else if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NETTRANS))
		rc = InstallNetTransport();
	else
	{
		DPRINT("Invalid class guid\n");
		rc = ERROR_GEN_FAILURE;
	}

cleanup:
	if (hInf != INVALID_HANDLE_VALUE)
		SetupCloseInfFile(hInf);
	if (UuidRpcString != NULL)
		RpcStringFreeW(&UuidRpcString);
	HeapFree(GetProcessHeap(), 0, BusType);
	HeapFree(GetProcessHeap(), 0, UuidString);

	if (rc == ERROR_SUCCESS)
		rc = ERROR_DI_DO_DEFAULT;
	DPRINT("Returning 0x%lx\n", rc);
	return rc;
}
Example #4
0
VOID
InstallDeviceData(IN HDEVINFO DeviceInfoSet,
                  IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
{
    HKEY hKey = NULL;
    HINF hInf = INVALID_HANDLE_VALUE;
    SP_DRVINFO_DATA DriverInfoData;
    PSP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
    WCHAR InfSectionWithExt[256];
    BYTE buffer[2048];
    DWORD dwRequired;

    TRACE("InstallDeviceData()\n");

    hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
                                   DeviceInfoData,
                                   DICS_FLAG_GLOBAL,
                                   0,
                                   DIREG_DRV,
                                   NULL,
                                   NULL);
    if (hKey == NULL)
        goto done;

    DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
    if (!SetupDiGetSelectedDriverW(DeviceInfoSet,
                                   DeviceInfoData,
                                   &DriverInfoData))
    {
        goto done;
    }

    DriverInfoDetailData = (PSP_DRVINFO_DETAIL_DATA)buffer;
    DriverInfoDetailData->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
    if (!SetupDiGetDriverInfoDetailW(DeviceInfoSet,
                                     DeviceInfoData,
                                     &DriverInfoData,
                                     DriverInfoDetailData,
                                     2048,
                                     &dwRequired))
    {
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
            goto done;
    }

    TRACE("Inf file name: %S\n", DriverInfoDetailData->InfFileName);

    hInf = SetupOpenInfFileW(DriverInfoDetailData->InfFileName,
                             NULL,
                             INF_STYLE_WIN4,
                             NULL);
    if (hInf == INVALID_HANDLE_VALUE)
        goto done;

    TRACE("Section name: %S\n", DriverInfoDetailData->SectionName);

    SetupDiGetActualSectionToInstallW(hInf,
                                      DriverInfoDetailData->SectionName,
                                      InfSectionWithExt,
                                      256,
                                      NULL,
                                      NULL);

    TRACE("InfSectionWithExt: %S\n", InfSectionWithExt);

    SetupInstallFromInfSectionW(NULL,
                                hInf,
                                InfSectionWithExt,
                                SPINST_REGISTRY,
                                hKey,
                                NULL,
                                0,
                                NULL,
                                NULL,
                                NULL,
                                NULL);

    TRACE("Done\n");

done:;
    if (hKey != NULL)
        RegCloseKey(hKey);

    if (hInf != INVALID_HANDLE_VALUE)
        SetupCloseInfFile(hInf);
}