From c66233dc1570278bfe61349c727421e738bbd2cb Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Thu, 17 Jan 2008 03:41:59 +0000 Subject: [PATCH] Add driver version and date. --- panda/src/display/displayInformation.cxx | 79 ++++++++++++ panda/src/display/displayInformation.h | 18 +++ panda/src/windisplay/winDetectDx.h | 146 ++++++++++++++++++++++- 3 files changed, 239 insertions(+), 4 deletions(-) diff --git a/panda/src/display/displayInformation.cxx b/panda/src/display/displayInformation.cxx index c9a61642c5..37e7194b9f 100644 --- a/panda/src/display/displayInformation.cxx +++ b/panda/src/display/displayInformation.cxx @@ -101,6 +101,15 @@ DisplayInformation() { _vendor_id = 0; _device_id = 0; + _driver_product = 0; + _driver_version = 0; + _driver_sub_version = 0; + _driver_build = 0; + + _driver_date_month = 0; + _driver_date_day = 0; + _driver_date_year = 0; + _cpu_id_version = 1; _cpu_id_size = 0; _cpu_id_data = 0; @@ -441,6 +450,76 @@ get_device_id() { return _device_id; } +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_product +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_product() { + return _driver_product; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_version +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_version() { + return _driver_version; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_sub_version +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_sub_version() { + return _driver_sub_version; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_build +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_build() { + return _driver_build; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_date_month +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_date_month() { + return _driver_date_month; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_date_day +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_date_day() { + return _driver_date_day; +} + +//////////////////////////////////////////////////////////////////// +// Function: DisplayInformation::get_driver_date_year +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +int DisplayInformation:: +get_driver_date_year() { + return _driver_date_year; +} + //////////////////////////////////////////////////////////////////// // Function: DisplayInformation::get_cpu_id_version // Access: Published diff --git a/panda/src/display/displayInformation.h b/panda/src/display/displayInformation.h index 679762e89a..8d9076e393 100644 --- a/panda/src/display/displayInformation.h +++ b/panda/src/display/displayInformation.h @@ -86,6 +86,15 @@ PUBLISHED: int get_vendor_id(); int get_device_id(); + int get_driver_product(); + int get_driver_version(); + int get_driver_sub_version(); + int get_driver_build(); + + int get_driver_date_month(); + int get_driver_date_day(); + int get_driver_date_year(); + int get_cpu_id_version(); int get_cpu_id_size(); unsigned int get_cpu_id_data(int index); @@ -138,6 +147,15 @@ public: int _vendor_id; int _device_id; + int _driver_product; + int _driver_version; + int _driver_sub_version; + int _driver_build; + + int _driver_date_month; + int _driver_date_day; + int _driver_date_year; + int _cpu_id_version; int _cpu_id_size; unsigned int *_cpu_id_data; diff --git a/panda/src/windisplay/winDetectDx.h b/panda/src/windisplay/winDetectDx.h index 5b672750ac..28568e2973 100644 --- a/panda/src/windisplay/winDetectDx.h +++ b/panda/src/windisplay/winDetectDx.h @@ -24,6 +24,18 @@ typedef struct { } DISPLAY_FORMAT; +typedef union +{ + struct + { + unsigned int day : 8; + unsigned int month : 8; + unsigned int year : 16; + }; + DWORD whql; +} +WHQL; + static DISPLAY_FORMAT display_format_array [ ] = { D3DFMT_X8R8G8B8, 32, FALSE, D3DFMT_R5G6B5, 16, FALSE, @@ -79,6 +91,28 @@ static LRESULT CALLBACK window_procedure (HWND hwnd, UINT msg, WPARAM wparam, LP return DefWindowProc(hwnd, msg, wparam, lparam); } +static DWORD print_GetLastError (char *message_prefix) +{ + LPVOID ptr; + DWORD error; + + ptr = 0; + error = GetLastError ( ); + if (FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + error, + MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ), + (LPTSTR)&ptr, + 0, NULL)) + { + cout << "ERROR: "<< message_prefix << " result = " << (char*) ptr << "\n"; + LocalFree( ptr ); + } + + return error; +} + static int get_display_information (DisplaySearchParameters &display_search_parameters, DisplayInformation *display_information) { int debug = false; @@ -111,6 +145,15 @@ static int get_display_information (DisplaySearchParameters &display_search_para int vendor_id; int device_id; + int product; + int version; + int sub_version; + int build; + + int month; + int day; + int year; + success = false; window_width = 0; window_height = 0; @@ -138,6 +181,15 @@ static int get_display_information (DisplaySearchParameters &display_search_para vendor_id = 0; device_id = 0; + + product = 0; + version = 0; + sub_version = 0; + build = 0; + + month = 0; + day = 0; + year = 0; HMODULE d3d_dll; DIRECT_3D_CREATE Direct3DCreate; @@ -196,17 +248,95 @@ static int get_display_information (DisplaySearchParameters &display_search_para d3d_adapter_identifier.Revision; d3d_adapter_identifier.DeviceIdentifier; d3d_adapter_identifier.WHQLLevel; + + if (debug) { + printf ("Driver: %s\n", d3d_adapter_identifier.Driver); + printf ("Description: %s\n", d3d_adapter_identifier.Description); + } + + char system_directory [MAX_PATH]; + char dll_file_path [MAX_PATH]; + + // find the dll in the system directory if possible and get the date of the file + if (GetSystemDirectory (system_directory, MAX_PATH) > 0) { + if (debug) { + printf ("system_directory = %s \n", system_directory); + } + sprintf (dll_file_path, "%s\\%s", system_directory, d3d_adapter_identifier.Driver); + + intptr_t find; + struct _finddata_t find_data; + + find = _findfirst (dll_file_path, &find_data); + if (find != -1) { + struct tm *dll_time; + + dll_time = localtime(&find_data.time_write); + + month = dll_time -> tm_mon + 1; + day = dll_time -> tm_mday; + year = dll_time -> tm_year + 1900; + + if (debug) { + printf ("Driver Date: %d/%d/%d\n", month, day, year); + } + + _findclose (find); + } + } /* - printf ("Driver = %s\n", d3d_adapter_identifier.Driver); - printf ("Description = %s\n", d3d_adapter_identifier.Description); + HMODULE driver_dll; + + driver_dll = LoadLibrary (d3d_adapter_identifier.Driver); + if (driver_dll) + { + DWORD length; + TCHAR file_path [MAX_PATH]; - printf ("VendorId = 0x%x\n", d3d_adapter_identifier.VendorId); - printf ("DeviceId = 0x%x\n", d3d_adapter_identifier.DeviceId); + length = GetModuleFileName(driver_dll, file_path, MAX_PATH); + if (length > 0) + { + printf ("DLL file path = %s \n", file_path); + } + else + { + printf ("ERROR: could not get GetModuleFileName for %s \n", d3d_adapter_identifier.Driver); + } + + FreeLibrary (driver_dll); + } + else + { + print_GetLastError (""); + printf ("ERROR: could not load = %s \n", d3d_adapter_identifier.Driver); + } */ + + if (debug) { + printf ("VendorId = 0x%x\n", d3d_adapter_identifier.VendorId); + printf ("DeviceId = 0x%x\n", d3d_adapter_identifier.DeviceId); + } vendor_id = d3d_adapter_identifier.VendorId; device_id = d3d_adapter_identifier.DeviceId; + + product = HIWORD(d3d_adapter_identifier.DriverVersion.HighPart); + version = LOWORD(d3d_adapter_identifier.DriverVersion.HighPart); + sub_version = HIWORD(d3d_adapter_identifier.DriverVersion.LowPart); + build = LOWORD(d3d_adapter_identifier.DriverVersion.LowPart); + + if (debug) { + printf ("DRIVER VERSION: %d.%d.%d.%d \n", product, version, sub_version, build); + } + + WHQL whql; + + whql.whql= d3d_adapter_identifier.WHQLLevel; + + if (debug) { + printf ("WHQL: %d %d %d \n", whql.day, whql.day, whql.year); + } } if (direct_3d -> GetDeviceCaps (adapter, device_type, &d3d_caps) == D3D_OK) { @@ -535,6 +665,14 @@ static int get_display_information (DisplaySearchParameters &display_search_para display_information -> _texture_memory = texture_memory; display_information -> _vendor_id = vendor_id; display_information -> _device_id = device_id; + display_information -> _driver_product = product; + display_information -> _driver_version = version; + display_information -> _driver_sub_version = sub_version; + display_information -> _driver_build = build; + + display_information -> _driver_date_month = month; + display_information -> _driver_date_day = day; + display_information -> _driver_date_year = year; } // memory