func()

in plugins/internal/discovery/device_discovery.go [191:333]


func (d *DeviceDiscovery) getDevice(device int) (*Device, error) {

	// Attempt to retrieve the device ID
	id, err := d.getDeviceID(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the device description
	description, err := d.getDeviceDescription(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the device driver registry key
	registry, err := d.getDeviceDriverRegistryKey(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the device driver store path
	driverStore, err := d.getDeviceDriverStorePath(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the device location path
	location, err := d.getDeviceLocationPath(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the device vendor
	vendor, err := d.getDeviceVendor(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the device adapter LUID
	luid, err := d.getDeviceAdapterLUID(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the integrated device hardware flag
	integrated, err := d.isDeviceIntegrated(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the detachable device hardware flag
	detachable, err := d.isDeviceDetachable(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the display support flag
	display, err := d.doesDeviceSupportDisplay(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the compute support flag
	compute, err := d.doesDeviceSupportCompute(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the number of additional runtime files for System32
	numRuntimeFiles, err := d.getNumRuntimeFiles(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the list of additional runtime files for System32
	runtimeFiles := []*RuntimeFile{}
	for file := 0; file < int(numRuntimeFiles); file += 1 {

		// Attempt to retrieve the source path for the file
		sourcePath, err := d.getRuntimeFileSource(device, file)
		if err != nil {
			return nil, err
		}

		// Attempt to retrieve the destination filename for the file
		destinationFilename, err := d.getRuntimeFileDestination(device, file)
		if err != nil {
			return nil, err
		}

		// Add the file details to the list
		runtimeFiles = append(runtimeFiles, &RuntimeFile{
			SourcePath:          sourcePath,
			DestinationFilename: destinationFilename,
		})
	}

	// Attempt to retrieve the number of additional runtime files for SysWOW64
	numRuntimeFilesWow64, err := d.getNumRuntimeFilesWow64(device)
	if err != nil {
		return nil, err
	}

	// Attempt to retrieve the list of additional runtime files for System32
	runtimeFilesWow64 := []*RuntimeFile{}
	for file := 0; file < int(numRuntimeFilesWow64); file += 1 {

		// Attempt to retrieve the source path for the file
		sourcePath, err := d.getRuntimeFileSourceWow64(device, file)
		if err != nil {
			return nil, err
		}

		// Attempt to retrieve the destination filename for the file
		destinationFilename, err := d.getRuntimeFileDestinationWow64(device, file)
		if err != nil {
			return nil, err
		}

		// Add the file details to the list
		runtimeFilesWow64 = append(runtimeFilesWow64, &RuntimeFile{
			SourcePath:          sourcePath,
			DestinationFilename: destinationFilename,
		})
	}

	// Construct a Device object from the retrieved data
	return &Device{
		ID:                id,
		Description:       description,
		DriverRegistryKey: registry,
		DriverStorePath:   driverStore,
		LocationPath:      location,
		RuntimeFiles:      runtimeFiles,
		RuntimeFilesWow64: runtimeFilesWow64,
		Vendor:            vendor,
		AdapterLUID:       luid,
		IsIntegrated:      integrated,
		IsDetachable:      detachable,
		SupportsDisplay:   display,
		SupportsCompute:   compute,
	}, nil
}