Browse Source

Clean up DisplaySystemVersion() to avoid hsStrcpy, and add Windows 8.1

to the known versions decoder.
Michael Hansen 11 years ago
parent
commit
5b6b886b55
  1. 65
      Sources/Plasma/CoreLib/HeadSpin.cpp
  2. 2
      Sources/Plasma/CoreLib/HeadSpin.h
  3. 14
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp

65
Sources/Plasma/CoreLib/HeadSpin.cpp

@ -436,15 +436,13 @@ char *hsWStringToString( const wchar_t *str )
// Microsoft SAMPLE CODE // Microsoft SAMPLE CODE
// returns array of allocated version info strings or nil // returns array of allocated version info strings or nil
// //
char** DisplaySystemVersion() std::vector<plString> DisplaySystemVersion()
{ {
// TODO: I so want to std::vector<plString> this, but that requires
// including more headers in HeadSpin.h :(
#if HS_BUILD_FOR_WIN32 #if HS_BUILD_FOR_WIN32
#ifndef VER_SUITE_PERSONAL #ifndef VER_SUITE_PERSONAL
#define VER_SUITE_PERSONAL 0x200 #define VER_SUITE_PERSONAL 0x200
#endif #endif
hsTArray<char*> versionStrs; std::vector<plString> versionStrs;
OSVERSIONINFOEX osvi; OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx; BOOL bOsVersionInfoEx;
@ -461,7 +459,7 @@ char** DisplaySystemVersion()
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
return FALSE; return std::vector<plString>();
} }
switch (osvi.dwPlatformId) switch (osvi.dwPlatformId)
@ -471,22 +469,25 @@ char** DisplaySystemVersion()
// Test for the product. // Test for the product.
if ( osvi.dwMajorVersion <= 4 ) if ( osvi.dwMajorVersion <= 4 )
versionStrs.Append(hsStrcpy("Microsoft Windows NT ")); versionStrs.push_back("Microsoft Windows NT ");
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
versionStrs.Append(hsStrcpy ("Microsoft Windows 2000 ")); versionStrs.push_back("Microsoft Windows 2000 ");
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
versionStrs.Append(hsStrcpy ("Microsoft Windows XP ")); versionStrs.push_back("Microsoft Windows XP ");
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 )
versionStrs.Append(hsStrcpy ("Microsoft Windows Vista ")); versionStrs.push_back("Microsoft Windows Vista ");
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 ) if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 )
versionStrs.Append(hsStrcpy ("Microsoft Windows 7 ")); versionStrs.push_back("Microsoft Windows 7 ");
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 ) if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 )
versionStrs.Append(hsStrcpy ("Microsoft Windows 8 ")); versionStrs.push_back("Microsoft Windows 8 ");
if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 3 )
versionStrs.push_back("Microsoft Windows 8.1 ");
// Test for product type. // Test for product type.
@ -495,19 +496,19 @@ char** DisplaySystemVersion()
if ( osvi.wProductType == VER_NT_WORKSTATION ) if ( osvi.wProductType == VER_NT_WORKSTATION )
{ {
if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
versionStrs.Append(hsStrcpy ( "Personal " )); versionStrs.push_back("Personal ");
else else
versionStrs.Append(hsStrcpy ( "Professional " )); versionStrs.push_back("Professional ");
} }
else if ( osvi.wProductType == VER_NT_SERVER ) else if ( osvi.wProductType == VER_NT_SERVER )
{ {
if( osvi.wSuiteMask & VER_SUITE_DATACENTER ) if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
versionStrs.Append(hsStrcpy ( "DataCenter Server " )); versionStrs.push_back("DataCenter Server ");
else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE ) else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
versionStrs.Append(hsStrcpy ( "Advanced Server " )); versionStrs.push_back("Advanced Server ");
else else
versionStrs.Append(hsStrcpy ( "Server " )); versionStrs.push_back("Server ");
} }
} }
else else
@ -523,28 +524,28 @@ char** DisplaySystemVersion()
(LPBYTE) szProductType, &dwBufLen); (LPBYTE) szProductType, &dwBufLen);
RegCloseKey( hKey ); RegCloseKey( hKey );
if ( lstrcmpi( "WINNT", szProductType) == 0 ) if ( lstrcmpi( "WINNT", szProductType) == 0 )
versionStrs.Append(hsStrcpy( "Professional " )); versionStrs.push_back("Professional ");
if ( lstrcmpi( "LANMANNT", szProductType) == 0 ) if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
versionStrs.Append(hsStrcpy( "Server " )); versionStrs.push_back("Server ");
if ( lstrcmpi( "SERVERNT", szProductType) == 0 ) if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
versionStrs.Append(hsStrcpy( "Advanced Server " )); versionStrs.push_back("Advanced Server ");
} }
// Display version, service pack (if any), and build number. // Display version, service pack (if any), and build number.
if ( osvi.dwMajorVersion <= 4 ) if ( osvi.dwMajorVersion <= 4 )
{ {
versionStrs.Append(hsStrcpy (plString::Format("version %d.%d %s (Build %d)\n", versionStrs.push_back(plString::Format("version %d.%d %s (Build %d)\n",
osvi.dwMajorVersion, osvi.dwMajorVersion,
osvi.dwMinorVersion, osvi.dwMinorVersion,
osvi.szCSDVersion, osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF).c_str())); osvi.dwBuildNumber & 0xFFFF));
} }
else else
{ {
versionStrs.Append(hsStrcpy (plString::Format("%s (Build %d)\n", versionStrs.push_back(plString::Format("%s (Build %d)\n",
osvi.szCSDVersion, osvi.szCSDVersion,
osvi.dwBuildNumber & 0xFFFF).c_str())); osvi.dwBuildNumber & 0xFFFF));
} }
break; break;
@ -552,34 +553,32 @@ char** DisplaySystemVersion()
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
{ {
versionStrs.Append(hsStrcpy ("Microsoft Windows 95 ")); versionStrs.push_back("Microsoft Windows 95 ");
if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' ) if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
versionStrs.Append(hsStrcpy("OSR2 " )); versionStrs.push_back("OSR2 ");
} }
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
{ {
versionStrs.Append(hsStrcpy ("Microsoft Windows 98 ")); versionStrs.push_back("Microsoft Windows 98 ");
if ( osvi.szCSDVersion[1] == 'A' ) if ( osvi.szCSDVersion[1] == 'A' )
versionStrs.Append(hsStrcpy("SE " )); versionStrs.push_back("SE ");
} }
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
{ {
versionStrs.Append(hsStrcpy ("Microsoft Windows Me ")); versionStrs.push_back("Microsoft Windows Me ");
} }
break; break;
case VER_PLATFORM_WIN32s: case VER_PLATFORM_WIN32s:
versionStrs.Append(hsStrcpy ("Microsoft Win32s ")); versionStrs.push_back("Microsoft Win32s ");
break; break;
} }
versionStrs.Append(nil); // terminator return versionStrs;
return versionStrs.DetachArray();
#else #else
return nil; return std::vector<plString>();
#endif #endif
} }

2
Sources/Plasma/CoreLib/HeadSpin.h

@ -438,8 +438,6 @@ inline float hsRadiansToDegrees(float rad) { return float(rad * (180 / M_PI)); }
#define hsFopen(name, mode) fopen(name, mode) #define hsFopen(name, mode) fopen(name, mode)
char** DisplaySystemVersion();
/************************ Debug/Error Macros **************************/ /************************ Debug/Error Macros **************************/
typedef void (*hsDebugMessageProc)(const char message[]); typedef void (*hsDebugMessageProc)(const char message[]);

14
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp

@ -300,18 +300,14 @@ bool plNetClientMgr::Log(const char* str) const
// //
// Display OS version info for log // Display OS version info for log
// //
extern std::vector<plString> DisplaySystemVersion();
void plNetClientMgr::IDumpOSVersionInfo() const void plNetClientMgr::IDumpOSVersionInfo() const
{ {
DebugMsg("*** OS Info"); DebugMsg("*** OS Info");
char** versionStrs = DisplaySystemVersion(); std::vector<plString> versionStrs = DisplaySystemVersion();
int i=0; for (auto version = versionStrs.begin(); version != versionStrs.end(); ++version)
while(versionStrs && versionStrs[i]) DebugMsg(version->c_str());
{
DebugMsg(versionStrs[i]);
delete [] versionStrs[i];
i++;
}
delete [] versionStrs;
} }
// //

Loading…
Cancel
Save