mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-06-04 13:54:26 +00:00
[idd] helper: detect if system has GPU
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "CNotifyWindow.h"
|
||||
#include "CConfigWindow.h"
|
||||
#include "Devices.h"
|
||||
#include <CDebug.h>
|
||||
#include <windowsx.h>
|
||||
#include <strsafe.h>
|
||||
@@ -161,6 +162,14 @@ void CNotifyWindow::registerIcon()
|
||||
|
||||
if (!Shell_NotifyIcon(NIM_SETVERSION, &m_iconData))
|
||||
DEBUG_ERROR_HR(GetLastError(), "Shell_NotifyIcon(NIM_SETVERSION)");
|
||||
|
||||
bool hasGPU;
|
||||
if (!checkGPU(hasGPU))
|
||||
DEBUG_ERROR("Failed to check if the system has a GPU");
|
||||
else if (hasGPU)
|
||||
DEBUG_INFO("GPU identified");
|
||||
else
|
||||
DEBUG_INFO("System has no GPU");
|
||||
}
|
||||
|
||||
HWND CNotifyWindow::hwndDialog()
|
||||
|
||||
106
idd/LGIddHelper/Devices.cpp
Normal file
106
idd/LGIddHelper/Devices.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "Devices.h"
|
||||
#include <windows.h>
|
||||
#include <devguid.h>
|
||||
#include <setupapi.h>
|
||||
#include <CDebug.h>
|
||||
|
||||
inline static bool wprefix(const wchar_t *pre, const wchar_t *str)
|
||||
{
|
||||
return wcsncmp(pre, str, wcslen(pre)) == 0;
|
||||
}
|
||||
|
||||
bool checkGPU(bool &found)
|
||||
{
|
||||
found = false;
|
||||
|
||||
HDEVINFO hDevInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_DISPLAY, NULL, NULL, DIGCF_PRESENT);
|
||||
if (hDevInfo == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DEBUG_WARN_HR(GetLastError(), L"SetupDiGetClassDevsW");
|
||||
return false;
|
||||
}
|
||||
|
||||
SP_DEVINFO_DATA devInfo = { 0 };
|
||||
devInfo.cbSize = sizeof devInfo;
|
||||
|
||||
for (DWORD dwIndex = 0; SetupDiEnumDeviceInfo(hDevInfo, dwIndex, &devInfo); ++dwIndex)
|
||||
{
|
||||
DWORD dwSizeRequired;
|
||||
DWORD dwPropertyType;
|
||||
SetupDiGetDeviceRegistryPropertyW(hDevInfo, &devInfo, SPDRP_HARDWAREID, &dwPropertyType, NULL, 0, &dwSizeRequired);
|
||||
|
||||
DWORD dwLastError = GetLastError();
|
||||
if (dwLastError == ERROR_INVALID_DATA)
|
||||
continue;
|
||||
else if (dwLastError != ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
DEBUG_WARN_HR(GetLastError(), L"SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID) size calculation");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (dwPropertyType != REG_MULTI_SZ)
|
||||
{
|
||||
DEBUG_WARN(L"SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID) returned wrong type");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
LPWSTR lpBuffer = (LPWSTR)malloc(dwSizeRequired);
|
||||
if (!lpBuffer)
|
||||
{
|
||||
DEBUG_WARN(L"failed to allocate memory for SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID)");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!SetupDiGetDeviceRegistryPropertyW(hDevInfo, &devInfo, SPDRP_HARDWAREID, &dwPropertyType, (PBYTE)lpBuffer, dwSizeRequired, NULL))
|
||||
{
|
||||
DEBUG_WARN_HR(GetLastError(), L"SetupDiGetDeviceRegistryPropertyW(SPDRP_HARDWAREID) for real");
|
||||
free(lpBuffer);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for (LPWSTR lpHwId = lpBuffer; *lpHwId; lpHwId += wcslen(lpBuffer) + 1)
|
||||
{
|
||||
if (
|
||||
wprefix(L"PCI\\VEN_10DE&", lpHwId) || // Nvidia
|
||||
wprefix(L"PCI\\VEN_1002&", lpHwId) || // AMD
|
||||
wprefix(L"PCI\\VEN_8086&", lpHwId) // Intel
|
||||
)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(lpBuffer);
|
||||
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
|
||||
SetupDiDestroyDeviceInfoList(hDevInfo);
|
||||
return true;
|
||||
|
||||
fail:
|
||||
SetupDiDestroyDeviceInfoList(hDevInfo);
|
||||
return false;
|
||||
}
|
||||
23
idd/LGIddHelper/Devices.h
Normal file
23
idd/LGIddHelper/Devices.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Looking Glass
|
||||
* Copyright © 2017-2026 The Looking Glass Authors
|
||||
* https://looking-glass.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
bool checkGPU(bool &found);
|
||||
@@ -190,6 +190,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
|
||||
<ClCompile Include="CStaticWidget.cpp" />
|
||||
<ClCompile Include="CWidget.cpp" />
|
||||
<ClCompile Include="CWindow.cpp" />
|
||||
<ClCompile Include="Devices.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="UIHelpers.cpp" />
|
||||
</ItemGroup>
|
||||
@@ -205,6 +206,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
|
||||
<ClInclude Include="CRegistrySettings.h" />
|
||||
<ClInclude Include="CStaticWidget.h" />
|
||||
<ClInclude Include="CWidget.h" />
|
||||
<ClInclude Include="Devices.h" />
|
||||
<ClInclude Include="UIHelpers.h" />
|
||||
<ClInclude Include="CWindow.h" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -53,6 +53,16 @@
|
||||
<ClCompile Include="CGroupBox.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="$(SolutionDir)LGCommon\*.cpp" />
|
||||
<ClCompile Include="CButton.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CEditWidget.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Devices.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
|
||||
@@ -94,6 +104,18 @@
|
||||
<ClInclude Include="CGroupBox.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
|
||||
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
|
||||
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
|
||||
<ClInclude Include="CButton.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CEditWidget.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Devices.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
Reference in New Issue
Block a user