#include "OptionsMgr.h"
#include "TempFile.h"
#include "UniFile.h"
+#include "RegKey.h"
BOOL NTAPI IsMerge7zEnabled();
DWORD NTAPI VersionOf7z(BOOL bLocal = FALSE);
paths_CreateIfNeeded(sFileName);
m_sFileName = paths_ConcatPath(sFileName, _T("WinMerge.txt"));
-#ifdef _UNICODE
if (!m_pfile->OpenCreateUtf8(m_sFileName))
-#else
- if (!m_pfile->OpenCreate(m_sFileName))
-#endif
{
const UniFile::UniError &err = m_pfile->GetLastUniError();
sError = err.GetError();
return false;
}
-#ifdef _UNICODE
m_pfile->SetBom(true);
m_pfile->WriteBom();
-#endif
// Begin log
FileWriteString(_T("WinMerge configuration log\r\n"));
return true;
}
-/** @brief osvi.wProductType that works with MSVC6 headers */
-static BYTE GetProductTypeFromOsvc(const OSVERSIONINFOEX & osvi)
-{
- // wServicePackMinor (2 bytes)
- // wSuiteMask (2 bytes)
- // wProductType (1 byte)
- const BYTE * ptr = reinterpret_cast<const BYTE *>(&osvi.wServicePackMinor);
- return ptr[4];
-}
-
-/** @brief osvi.wSuiteMask that works with MSVC6 headers */
-static WORD GetSuiteMaskFromOsvc(const OSVERSIONINFOEX & osvi)
-{
- // wServicePackMinor (2 bytes)
- // wSuiteMask (2 bytes)
- const WORD * ptr = reinterpret_cast<const WORD *>(&osvi.wServicePackMinor);
- return ptr[1];
-}
-
-/**
- * @brief Extract any helpful product details from version info
- */
-static String GetProductFromOsvi(const OSVERSIONINFOEX & osvi)
-{
- String sProduct;
- BYTE productType = GetProductTypeFromOsvc(osvi);
- WORD suiteMask = GetSuiteMaskFromOsvc(osvi);
-
- // Test for the workstation type.
- if ( productType == VER_NT_WORKSTATION )
- {
- if( osvi.dwMajorVersion == 4 )
- sProduct += _T( "Workstation 4.0 ");
- else if( suiteMask & VER_SUITE_PERSONAL )
- sProduct += _T( "Home Edition " );
- else
- sProduct += _T( "Professional " );
- }
-
- // Test for the server type.
- else if ( productType == VER_NT_SERVER )
- {
- if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
- {
- if( suiteMask & VER_SUITE_DATACENTER )
- sProduct += _T( "Datacenter Edition " );
- else if( suiteMask & VER_SUITE_ENTERPRISE )
- sProduct += _T( "Enterprise Edition " );
- else if ( suiteMask == VER_SUITE_BLADE )
- sProduct += _T( "Web Edition " );
- else
- sProduct += _T( "Standard Edition " );
- }
-
- else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
- {
- if( suiteMask & VER_SUITE_DATACENTER )
- sProduct += _T( "Datacenter Server " );
- else if( suiteMask & VER_SUITE_ENTERPRISE )
- sProduct += _T( "Advanced Server " );
- else
- sProduct += _T( "Server " );
- }
-
- else // Windows NT 4.0
- {
- if( suiteMask & VER_SUITE_ENTERPRISE )
- sProduct += _T("Server 4.0, Enterprise Edition " );
- else
- sProduct += _T( "Server 4.0 " );
- }
- }
- return sProduct;
-}
-
-#define REGBUFSIZE 1024
-/**
- * @brief Extract any helpful product details from registry (for WinNT)
- */
-static String GetNtProductFromRegistry(const OSVERSIONINFOEX & osvi)
-{
- String sProduct;
-
- HKEY hKey;
- TCHAR szProductType[REGBUFSIZE];
- DWORD dwBufLen = sizeof(szProductType)/sizeof(szProductType[0]);
- LONG lRet;
-
- lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- _T("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"),
- 0, KEY_QUERY_VALUE, &hKey );
- if( lRet != ERROR_SUCCESS )
- return _T("");
-
- lRet = RegQueryValueEx( hKey, _T("ProductType"), NULL, NULL,
- (LPBYTE) szProductType, &dwBufLen);
- RegCloseKey( hKey );
-
- if( (lRet != ERROR_SUCCESS) || (dwBufLen > REGBUFSIZE) )
- return _T("");
-
- if ( _tcsicmp( _T("WINNT"), szProductType) == 0 )
- sProduct = _T( "Workstation " );
- if ( _tcsicmp( _T("LANMANNT"), szProductType) == 0 )
- sProduct = _T( "Server " );
- if ( _tcsicmp( _T("SERVERNT"), szProductType) == 0 )
- sProduct = _T( "Advanced Server " );
-
- String ver = string_format( _T("%d.%d "), osvi.dwMajorVersion, osvi.dwMinorVersion );
- sProduct += ver;
- return sProduct;
-}
-
/**
* @brief Parse Windows version data to string.
- * See info about how to determine Windows versions from URL:
- * http://msdn.microsoft.com/en-us/library/ms724833(VS.85).aspx
* @return String describing Windows version.
*/
String CConfigLog::GetWindowsVer() const
{
- OSVERSIONINFOEX osvi;
- String sVersion;
-
- // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
- // If that fails, try using the OSVERSIONINFO structure.
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-
- if( !GetVersionEx ((OSVERSIONINFO *) &osvi) )
- {
- osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
- if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
- return _T("");
- }
-
- switch (osvi.dwPlatformId)
- {
- // Test for the Windows NT product family.
- case VER_PLATFORM_WIN32_NT:
-
- // Test for the specific product family.
- if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
- sVersion = _T("Microsoft Windows Server 2003 family, ");
- else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
- sVersion = _T("Microsoft Windows XP ");
- else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
- sVersion = _T("Microsoft Windows 2000 ");
- else if ( osvi.dwMajorVersion <= 4 )
- sVersion = _T("Microsoft Windows NT ");
- else if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- sVersion = _T("Microsoft Windows Vista ");
- else
- sVersion = _T("Microsoft Windows Server 2008 ");
- }
- else if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 )
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- sVersion = _T("Microsoft Windows 7 ");
- else
- sVersion = _T("Microsoft Windows Server 2008 R2 ");
- }
- else if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 )
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- sVersion = _T("Microsoft Windows 8 ");
- else
- sVersion = _T("Microsoft Windows Server 2012 ");
- }
- else
- sVersion = string_format(_T("[? WindowsNT %d.%d] "),
- osvi.dwMajorVersion, osvi.dwMinorVersion);
-
- if (osvi.dwOSVersionInfoSize == sizeof(OSVERSIONINFOEX))
- {
- // Test for specific product on Windows NT 4.0 SP6 and later.
- String sProduct = GetProductFromOsvi(osvi);
- sVersion += sProduct;
- }
- else
- {
- // Test for specific product on Windows NT 4.0 SP5 and earlier
- String sProduct = GetNtProductFromRegistry(osvi);
- sVersion += sProduct;
- }
-
- // Display service pack (if any) and build number.
- if( osvi.dwMajorVersion == 4 &&
- _tcsicmp( osvi.szCSDVersion, _T("Service Pack 6") ) == 0 )
- {
- HKEY hKey;
- LONG lRet;
-
- // Test for SP6 versus SP6a.
- lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
- _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"),
- 0, KEY_QUERY_VALUE, &hKey );
- String ver;
- if( lRet == ERROR_SUCCESS )
- ver = string_format(_T("Service Pack 6a (Build %d)"), osvi.dwBuildNumber & 0xFFFF );
- else // Windows NT 4.0 prior to SP6a
- {
- ver = string_format(_T("%s (Build %d)"),
- osvi.szCSDVersion,
- osvi.dwBuildNumber & 0xFFFF);
- }
-
- sVersion += ver;
- RegCloseKey( hKey );
- }
- else // Windows NT 3.51 and earlier or Windows 2000 and later
- {
- String ver = string_format( _T("%s (Build %d)"),
- osvi.szCSDVersion,
- osvi.dwBuildNumber & 0xFFFF);
- sVersion += ver;
- }
- break;
-
- // Test for the Windows 95 product family.
- case VER_PLATFORM_WIN32_WINDOWS:
-
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
- {
- sVersion = _T("Microsoft Windows 95 ");
- if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
- sVersion += _T("OSR2 " );
- }
- else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
- {
- sVersion = _T("Microsoft Windows 98 ");
- if ( osvi.szCSDVersion[1] == 'A' )
- sVersion += _T("SE " );
- }
- else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
- {
- sVersion = _T("Microsoft Windows Millennium Edition");
- }
- else
- {
- sVersion = string_format(_T("[? Windows9x %d.%d] "),
- osvi.dwMajorVersion, osvi.dwMinorVersion);
- }
- break;
-
- case VER_PLATFORM_WIN32s:
- sVersion = _T("Microsoft Win32s\r\n");
- break;
-
- default:
- sVersion = string_format(_T(" [? Windows? %d.%d] "),
- osvi.dwMajorVersion, osvi.dwMinorVersion);
- }
- return sVersion;
+ CRegKeyEx key;
+ if (key.QueryRegMachine(_T("Software\\Microsoft\\Windows NT\\CurrentVersion")))
+ return key.ReadString(_T("ProductName"), _T("Unknown OS"));
+ return _T("Unknown OS");
}
/**
{
String flags;
-#ifdef _DEBUG
- flags += _T(" _DEBUG ");
-#endif
-
-#ifdef NDEBUG
- flags += _T(" NDEBUG ");
-#endif
-
-#ifdef UNICODE
- flags += _T(" UNICODE ");
-#endif
-
-#ifdef _UNICODE
- flags += _T(" _UNICODE ");
-#endif
-
-#ifdef _MBCS
- flags += _T(" _MBCS ");
-#endif
-
#ifdef WIN64
flags += _T(" WIN64 ");
#endif