From ff187406a691cdcec2dbb08f0a571a04f3e81cf5 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Mon, 28 Apr 2008 21:47:43 +0000 Subject: [PATCH] - enumerate driver files, driver version and driver time svn path=/trunk/; revision=33184 --- reactos/base/applications/dxdiag/display.c | 149 +++++++++++++++++++++ reactos/base/applications/dxdiag/network.c | 4 +- reactos/base/applications/dxdiag/precomp.h | 4 + 3 files changed, 155 insertions(+), 2 deletions(-) diff --git a/reactos/base/applications/dxdiag/display.c b/reactos/base/applications/dxdiag/display.c index 17565348c72..289283b7d52 100644 --- a/reactos/base/applications/dxdiag/display.c +++ b/reactos/base/applications/dxdiag/display.c @@ -11,6 +11,150 @@ #include #include +BOOL +GetFileModifyTime(LPCWSTR pFullPath, WCHAR * szTime, int szTimeSize) +{ + HANDLE hFile; + FILETIME AccessTime; + SYSTEMTIME SysTime, LocalTime; + UINT Length; + + hFile = CreateFileW(pFullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); + if (!hFile) + return FALSE; + + if (!GetFileTime(hFile, NULL, NULL, &AccessTime)) + { + CloseHandle(hFile); + return FALSE; + } + CloseHandle(hFile); + + if (!FileTimeToSystemTime(&AccessTime, &SysTime)) + return FALSE; + + if (!SystemTimeToTzSpecificLocalTime(NULL, &SysTime, &LocalTime)) + return FALSE; + + Length = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &LocalTime, NULL, szTime, szTimeSize); + szTime[Length-1] = L' '; + return GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT, &LocalTime, NULL, &szTime[Length], szTimeSize-Length); +} + + + +static UINT WINAPI +DriverFilesCallback(IN PVOID Context, + IN UINT Notification, + IN UINT_PTR Param1, + IN UINT_PTR Param2) +{ + LPCWSTR pFile; + LPWSTR pBuffer; + LPCWSTR pFullPath = (LPCWSTR)Param1; + WCHAR szVer[30]; + LRESULT Length, fLength; + HWND * hDlgCtrls = (HWND *)Context; + + if (wcsstr(pFullPath, L"\\DRIVERS\\")) + { + /* exclude files from drivers dir to have failsafe file version/date information */ + return NO_ERROR; + } + + pFile = wcsrchr(pFullPath, L'\\'); + if (!pFile) + return NO_ERROR; + + pFile++; + fLength = wcslen(pFile) + 1; + + Length = SendMessageW(hDlgCtrls[0], WM_GETTEXTLENGTH, 0, 0) + 1; + pBuffer = HeapAlloc(GetProcessHeap(), 0, (Length + fLength) * sizeof(WCHAR)); + if (!pBuffer) + return ERROR_OUTOFMEMORY; + + Length = SendMessageW(hDlgCtrls[0], WM_GETTEXT, Length, (LPARAM)pBuffer); + if (Length) + { + pBuffer[Length++] = L','; + } + else + { + /* set file version */ + if (GetFileVersion(pFullPath, szVer)) + SendMessageW(hDlgCtrls[1], WM_SETTEXT, 0, (LPARAM)szVer); + /* set file time */ + if (GetFileModifyTime(pFullPath, szVer, sizeof(szVer)/sizeof(WCHAR))) + SendMessageW(hDlgCtrls[2], WM_SETTEXT, 0, (LPARAM)szVer); + } + + wcscpy(&pBuffer[Length], pFile); + SendMessageW(hDlgCtrls[0], WM_SETTEXT, 0, (LPARAM)pBuffer); + HeapFree(GetProcessHeap(), 0, pBuffer); + return NO_ERROR; +} + +VOID +EnumerateDrivers(PVOID Context, HDEVINFO hList, PSP_DEVINFO_DATA pInfoData) +{ + HSPFILEQ hQueue; + SP_DEVINSTALL_PARAMS DeviceInstallParams = {0}; + SP_DRVINFO_DATA DriverInfoData; + DWORD Result; + + DeviceInstallParams.cbSize = sizeof(DeviceInstallParams); + if (!SetupDiGetDeviceInstallParamsW(hList, pInfoData, &DeviceInstallParams)) + return; + + DeviceInstallParams.FlagsEx |= (DI_FLAGSEX_INSTALLEDDRIVER | DI_FLAGSEX_ALLOWEXCLUDEDDRVS); + if (!SetupDiSetDeviceInstallParams(hList, pInfoData, &DeviceInstallParams)) + return; + + if (!SetupDiBuildDriverInfoList(hList, pInfoData, SPDIT_CLASSDRIVER)) + return; + + DriverInfoData.cbSize = sizeof(DriverInfoData); + if (!SetupDiEnumDriverInfoW(hList, pInfoData, SPDIT_CLASSDRIVER, 0, &DriverInfoData)) + return; + + DriverInfoData.cbSize = sizeof(DriverInfoData); + if (!SetupDiSetSelectedDriverW(hList, pInfoData, &DriverInfoData)) + return; + + hQueue = SetupOpenFileQueue(); + if (hQueue == (HSPFILEQ)INVALID_HANDLE_VALUE) + return; + + DeviceInstallParams.cbSize = sizeof(DeviceInstallParams); + if (!SetupDiGetDeviceInstallParamsW(hList, pInfoData, &DeviceInstallParams)) + { + SetupCloseFileQueue(hQueue); + return; + } + + DeviceInstallParams.FileQueue = hQueue; + DeviceInstallParams.Flags |= DI_NOVCP; + + if (!SetupDiSetDeviceInstallParamsW(hList, pInfoData, &DeviceInstallParams)) + { + SetupCloseFileQueue(hQueue); + return; + } + + if(!SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES, hList, pInfoData)) + { + SetupCloseFileQueue(hQueue); + return; + } + + + /* enumerate the driver files */ + SetupScanFileQueueW(hQueue, SPQ_SCAN_USE_CALLBACK, NULL, DriverFilesCallback, Context, &Result); + SetupCloseFileQueue(hQueue); +} + + static BOOL InitializeDialog(HWND hwndDlg) @@ -22,6 +166,7 @@ InitializeDialog(HWND hwndDlg) WCHAR szText[100]; WCHAR szFormat[30]; HKEY hKey; + HWND hDlgCtrls[3]; DWORD dwMemory; DEVMODE DevMode; @@ -108,6 +253,10 @@ InitializeDialog(HWND hwndDlg) /* FIXME * we currently enumerate only the first adapter */ + hDlgCtrls[0] = GetDlgItem(hwndDlg, IDC_STATIC_ADAPTER_DRIVER); + hDlgCtrls[1] = GetDlgItem(hwndDlg, IDC_STATIC_ADAPTER_VERSION); + hDlgCtrls[2] = GetDlgItem(hwndDlg, IDC_STATIC_ADAPTER_DATE); + EnumerateDrivers(hDlgCtrls, hInfo, &InfoData); break; } diff --git a/reactos/base/applications/dxdiag/network.c b/reactos/base/applications/dxdiag/network.c index 90d6f2705e8..5875392184e 100644 --- a/reactos/base/applications/dxdiag/network.c +++ b/reactos/base/applications/dxdiag/network.c @@ -98,9 +98,9 @@ FindProviderIndex(LPCWSTR szGuid, DIRECTPLAY_GUID * PreDefProviders) } return UINT_MAX; } -static + BOOL -GetFileVersion(WCHAR * szAppName, WCHAR * szVer) +GetFileVersion(LPCWSTR szAppName, WCHAR * szVer) { UINT VerSize; DWORD DummyHandle; diff --git a/reactos/base/applications/dxdiag/precomp.h b/reactos/base/applications/dxdiag/precomp.h index 20c9088c7f5..5607482dcfc 100644 --- a/reactos/base/applications/dxdiag/precomp.h +++ b/reactos/base/applications/dxdiag/precomp.h @@ -4,6 +4,7 @@ #define DIRECTINPUT_VERSION 0x0800 #define DIRECTSOUND_VERSION 0x0800 #define D3D_OVERLOADS +#define _SETUPAPI_VER _WIN32_WINNT #include #include @@ -41,4 +42,7 @@ BOOL GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPW /* DirectDraw tests */ BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr); + +BOOL GetFileVersion(LPCWSTR szAppName, WCHAR * szVer); +BOOL GetFileModifyTime(LPCWSTR pFullPath, WCHAR * szTime, int szTimeSize); #endif