From 8449d9f5ead7673afcfa662dc924ab51df7a7185 Mon Sep 17 00:00:00 2001 From: AngryGamer Date: Tue, 2 Jul 2019 06:40:28 -0700 Subject: [PATCH] Add more OS information to debug info Close #5869, close #5872 --- .../src/WinControls/AboutDlg/AboutDlg.cpp | 83 ++++++++++++++++++- .../src/WinControls/AboutDlg/AboutDlg.h | 1 + 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index 6e3272cd0..7e9bca8e9 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -161,13 +161,88 @@ INT_PTR CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM / _debugInfoStr += (doLocalConf ? TEXT("ON") : TEXT("OFF")); _debugInfoStr += TEXT("\r\n"); - // OS version - _debugInfoStr += TEXT("OS : "); - _debugInfoStr += (NppParameters::getInstance())->getWinVersionStr(); + // OS information + HKEY hKey; + DWORD dataSize = 0; + + TCHAR szProductName[96] = {'\0'}; + TCHAR szCurrentBuildNumber[32] = {'\0'}; + TCHAR szReleaseId[32] = {'\0'}; + DWORD dwUBR = 0; + TCHAR szUBR[12] = TEXT("0"); + + // NOTE: RegQueryValueExW is not guaranteed to return null-terminated strings + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + dataSize = sizeof(szProductName); + RegQueryValueExW(hKey, TEXT("ProductName"), NULL, NULL, reinterpret_cast(szProductName), &dataSize); + szProductName[sizeof(szProductName) / sizeof(TCHAR) - 1] = '\0'; + + dataSize = sizeof(szReleaseId); + RegQueryValueExW(hKey, TEXT("ReleaseId"), NULL, NULL, reinterpret_cast(szReleaseId), &dataSize); + szReleaseId[sizeof(szReleaseId) / sizeof(TCHAR) - 1] = '\0'; + + dataSize = sizeof(szCurrentBuildNumber); + RegQueryValueExW(hKey, TEXT("CurrentBuildNumber"), NULL, NULL, reinterpret_cast(szCurrentBuildNumber), &dataSize); + szCurrentBuildNumber[sizeof(szCurrentBuildNumber) / sizeof(TCHAR) - 1] = '\0'; + + dataSize = sizeof(DWORD); + if (RegQueryValueExW(hKey, TEXT("UBR"), NULL, NULL, reinterpret_cast(&dwUBR), &dataSize) == ERROR_SUCCESS) + { + generic_sprintf(szUBR, TEXT("%u"), dwUBR); + } + + RegCloseKey(hKey); + } + + // Get alternative OS information + if (szProductName[0] == '\0') + { + generic_sprintf(szProductName, TEXT("%s"), (NppParameters::getInstance())->getWinVersionStr().c_str()); + } + if (szCurrentBuildNumber[0] == '\0') + { + DWORD dwVersion = GetVersion(); + if (dwVersion < 0x80000000) + { + generic_sprintf(szCurrentBuildNumber, TEXT("%u"), HIWORD(dwVersion)); + } + } + + _debugInfoStr += TEXT("OS Name : "); + _debugInfoStr += szProductName; _debugInfoStr += TEXT(" ("); _debugInfoStr += (NppParameters::getInstance())->getWinVerBitStr(); - _debugInfoStr += TEXT(")"); + _debugInfoStr += TEXT(") "); _debugInfoStr += TEXT("\r\n"); + + if (szReleaseId[0] != '\0') + { + _debugInfoStr += TEXT("OS Version : "); + _debugInfoStr += szReleaseId; + _debugInfoStr += TEXT("\r\n"); + } + + if (szCurrentBuildNumber[0] != '\0') + { + _debugInfoStr += TEXT("OS Build : "); + _debugInfoStr += szCurrentBuildNumber; + _debugInfoStr += TEXT("."); + _debugInfoStr += szUBR; + _debugInfoStr += TEXT("\r\n"); + } + + // Detect WINE + PWINEGETVERSION pWGV = (PWINEGETVERSION)GetProcAddress(GetModuleHandle(TEXT("ntdll.dll")), "wine_get_version"); + if (pWGV != NULL) + { + TCHAR szWINEVersion[32]; + generic_sprintf(szWINEVersion, TEXT("%hs"), pWGV()); + + _debugInfoStr += TEXT("WINE : "); + _debugInfoStr += szWINEVersion; + _debugInfoStr += TEXT("\r\n"); + } // Plugins _debugInfoStr += TEXT("Plugins : "); diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h index cc5f1476b..92790c24e 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h @@ -90,6 +90,7 @@ protected: virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); private: + typedef const CHAR * (__cdecl * PWINEGETVERSION)(); generic_string _debugInfoStr; bool _isAdmin = false; generic_string _loadedPlugins;