Files
itgmania212121/stepmania/src/archutils/Win32/VideoDriverInfo.cpp
T

146 lines
4.3 KiB
C++
Raw Normal View History

2003-05-26 23:36:17 +00:00
#include "global.h"
#include "VideoDriverInfo.h"
#include "RageUtil.h"
#include "RageLog.h"
2004-04-25 03:49:05 +00:00
#include "RegistryAccess.h"
2005-11-23 22:47:47 +00:00
#include <windows.h>
2003-05-26 23:36:17 +00:00
2005-11-23 22:47:47 +00:00
// this will not work on 95 and NT because of EnumDisplayDevices
CString GetPrimaryVideoName()
2003-05-26 23:36:17 +00:00
{
typedef BOOL (WINAPI* pfnEnumDisplayDevices)(PVOID,DWORD,PDISPLAY_DEVICE,DWORD);
pfnEnumDisplayDevices EnumDisplayDevices;
2005-11-23 22:47:47 +00:00
HINSTANCE hInstUser32;
2003-05-26 23:36:17 +00:00
2005-11-23 22:47:47 +00:00
hInstUser32 = LoadLibrary( "User32.DLL" );
2003-05-26 23:36:17 +00:00
if( !hInstUser32 )
return CString();
2003-05-26 23:36:17 +00:00
// VC6 don't have a stub to static link with, so link dynamically.
EnumDisplayDevices = (pfnEnumDisplayDevices)GetProcAddress(hInstUser32,"EnumDisplayDevicesA");
if( EnumDisplayDevices == NULL )
{
FreeLibrary(hInstUser32);
return CString();
2003-05-26 23:36:17 +00:00
}
CString sPrimaryDeviceName;
2005-11-23 22:47:47 +00:00
for( int i=0; true; ++i )
2003-05-26 23:36:17 +00:00
{
DISPLAY_DEVICE dd;
ZERO( dd );
dd.cb = sizeof(dd);
if( !EnumDisplayDevices(NULL, i, &dd, 0) )
break;
if( dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE )
{
sPrimaryDeviceName = (char*)dd.DeviceString;
break;
}
}
2005-11-23 22:47:47 +00:00
FreeLibrary( hInstUser32 );
2003-05-26 23:36:17 +00:00
return sPrimaryDeviceName;
}
2003-05-28 18:37:49 +00:00
CString GetPrimaryVideoDriverName()
2003-05-26 23:36:17 +00:00
{
const CString sPrimaryDeviceName = GetPrimaryVideoName();
2003-05-28 18:36:44 +00:00
if( sPrimaryDeviceName != "" )
return sPrimaryDeviceName;
LOG->Warn("GetPrimaryVideoName failed; renderer selection may be wrong");
2003-05-26 23:36:17 +00:00
2003-05-28 18:36:44 +00:00
VideoDriverInfo info;
if( !GetVideoDriverInfo(0, info) )
return "(ERROR DETECTING VIDEO DRIVER)";
2003-05-26 23:36:17 +00:00
2003-05-28 18:36:44 +00:00
return info.sDescription;
2003-05-26 23:36:17 +00:00
}
/* Get info for the given card number. Return false if that card doesn't exist. */
2005-11-23 22:47:47 +00:00
bool GetVideoDriverInfo( int iCardno, VideoDriverInfo &info )
2003-05-26 23:36:17 +00:00
{
OSVERSIONINFO version;
2005-11-23 22:47:47 +00:00
version.dwOSVersionInfoSize = sizeof(version);
2003-05-26 23:36:17 +00:00
GetVersionEx(&version);
const bool bIsWin9x = version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS;
2005-11-23 22:47:47 +00:00
static bool bInitialized=false;
static vector<CString> lst;
2005-11-23 22:47:47 +00:00
if( !bInitialized )
{
2005-11-23 22:47:47 +00:00
bInitialized = true;
2005-11-23 22:47:47 +00:00
const CString sTopKey = bIsWin9x?
2004-04-25 03:49:05 +00:00
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Class\\Display":
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}";
2005-11-23 22:47:47 +00:00
GetRegSubKeys( sTopKey, lst, ".*", false );
2005-11-23 22:47:47 +00:00
for( int i=lst.size()-1; i >= 0; --i )
{
/* Remove all keys that aren't four characters long ("Properties"). */
if( lst[i].size() != 4 )
{
lst.erase( lst.begin()+i );
continue;
}
2005-11-23 22:47:47 +00:00
lst[i] = sTopKey + "\\" + lst[i];
}
2005-11-23 22:47:47 +00:00
if( lst.size() == 0 )
{
LOG->Warn("GetVideoDriverInfo error: no cards found!");
return false;
}
}
2005-11-23 22:47:47 +00:00
while( iCardno < (int)lst.size() )
{
2005-11-23 22:47:47 +00:00
const CString sKey = lst[iCardno];
2004-04-25 03:49:05 +00:00
if( !GetRegValue( sKey, "DriverDesc", info.sDescription ) )
{
/* Remove this one from the list and ignore it, */
2005-11-23 22:47:47 +00:00
lst.erase( lst.begin()+iCardno );
continue;
}
2004-04-25 03:49:05 +00:00
GetRegValue( sKey, "DriverDate", info.sDate );
GetRegValue( sKey, "MatchingDeviceId", info.sDeviceID );
GetRegValue( sKey, "ProviderName", info.sProvider );
GetRegValue( sKey, bIsWin9x? "Ver":"DriverVersion", info.sVersion );
return true;
}
return false;
2003-05-26 23:36:17 +00:00
}
2004-05-15 20:13:19 +00:00
/*
* (c) 2002-2004 Chris Danford, Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/