Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
5.8 KiB

  1. /*======================================================================================//
  2. | //
  3. |Copyright (c) 1998 Sequent Computer Systems, Incorporated. All rights reserved. //
  4. | //
  5. |File Name: version.cpp //
  6. | //
  7. |Description: //
  8. | //
  9. |Created: Paul Skoglund 09-1998 //
  10. | //
  11. |Rev History: //
  12. | //
  13. |=======================================================================================*/
  14. #include "..\SERVICE\ProcConSvc.h"
  15. CVersion::CVersion(HINSTANCE hInst) : m_hInst(hInst), m_bInitializedOK(FALSE), m_fixedLen( 0 )
  16. {
  17. memset(&szFileVersion, 0, sizeof(szFileVersion) );
  18. memset(&szProductVersion, 0, sizeof(szProductVersion) );
  19. memset(&szFileFlags, 0, sizeof(szFileFlags) );
  20. memset(&m_fixed_info, 0, sizeof(m_fixed_info) );
  21. m_bDebug = m_bPatched = m_bPreRelease = m_bPrivateBuild = m_bSpecialBuild = FALSE;
  22. TCHAR szFileName[_MAX_PATH + 1] = { 0 };
  23. PCULONG32 dwBogus = 0;
  24. PCULONG32 dwSize = 0;
  25. LPVOID hMem = NULL;
  26. if ( GetModuleFileName(hInst, szFileName, ENTRY_COUNT(szFileName)) &&
  27. (dwSize = GetFileVersionInfoSize(szFileName, &dwBogus)) &&
  28. (hMem = new BYTE[dwSize]) )
  29. {
  30. if (GetFileVersionInfo(szFileName, NULL, dwSize, hMem) )
  31. {
  32. void *p;
  33. if (VerQueryValue( hMem, _T("\\"), &p, &m_fixedLen) )
  34. {
  35. memcpy( &m_fixed_info, p, sizeof(m_fixed_info) );
  36. m_bInitializedOK = ParseFixedInfo();
  37. }
  38. LoadStringFileInfo(hMem);
  39. }
  40. delete [] hMem;
  41. }
  42. }
  43. BOOL CVersion::LoadStringFileInfo(LPVOID hMem)
  44. {
  45. #ifndef UNICODE
  46. #error "what code-page to use? window-multilingual? 0x04e4"
  47. #endif
  48. UINT uLen;
  49. TCHAR buf[128];
  50. TCHAR *info;
  51. // it is my understanding that the string below are identified with the same english string under each language
  52. // $$ confirm? yes/no
  53. struct
  54. {
  55. TCHAR *name;
  56. tstring *target;
  57. } table[] = {
  58. { _T("CompanyName"), &strCompanyName }, { _T("FileDescription"), &strFileDescription },
  59. { _T("FileVersion"), &strFileVersion }, { _T("InternalName"), &strInternalName },
  60. { _T("LegalCopyright"), &strLegalCopyright}, { _T("OriginalFilename"),&strOriginalFilename },
  61. { _T("ProductName"), &strProductName }, { _T("ProductVersion"), &strProductVersion },
  62. { _T("Comments"), &strComments }, { _T("LegalTrademarks"), &strLegalTrademarks },
  63. { _T("PrivateBuild"), &strPrivateBuild }, { _T("SpecialBuild"), &strSpecialBuild }
  64. };
  65. buf[ENTRY_COUNT(buf) - 1] = 0; //insure null termination
  66. for (int i = 0; i < ENTRY_COUNT(table); i++)
  67. {
  68. // MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
  69. _sntprintf(buf, ENTRY_COUNT(buf) -1 , _T("\\StringFileInfo\\%04hx04b0\\%s"), GetUserDefaultLangID(), table[i].name);
  70. if (VerQueryValue( hMem, buf, (void **) &info, &uLen) )
  71. {
  72. *(table[i].target) = info;
  73. }
  74. }
  75. return TRUE;
  76. }
  77. BOOL CVersion::ParseFixedInfo( void )
  78. {
  79. assert( m_fixedLen == sizeof(VS_FIXEDFILEINFO) );
  80. if(m_fixedLen != sizeof(VS_FIXEDFILEINFO) )
  81. return FALSE;
  82. _stprintf(szFileVersion, _T("%hu.%hu.%hu.%hu"),
  83. HIWORD(m_fixed_info.dwFileVersionMS),
  84. LOWORD(m_fixed_info.dwFileVersionMS),
  85. HIWORD(m_fixed_info.dwFileVersionLS),
  86. LOWORD(m_fixed_info.dwFileVersionLS));
  87. _stprintf(szProductVersion, _T("%hu.%hu.%hu.%hu"),
  88. HIWORD(m_fixed_info.dwProductVersionMS),
  89. LOWORD(m_fixed_info.dwProductVersionMS),
  90. HIWORD(m_fixed_info.dwProductVersionLS),
  91. LOWORD(m_fixed_info.dwProductVersionLS));
  92. if ((m_fixed_info.dwFileFlagsMask & VS_FF_DEBUG) &&
  93. (m_fixed_info.dwFileFlags & VS_FF_DEBUG) )
  94. {
  95. m_bDebug = TRUE;
  96. }
  97. if ((m_fixed_info.dwFileFlagsMask & VS_FF_PRERELEASE) &&
  98. (m_fixed_info.dwFileFlags & VS_FF_PRERELEASE) )
  99. {
  100. m_bPreRelease = TRUE;
  101. }
  102. if ((m_fixed_info.dwFileFlagsMask & VS_FF_PATCHED ) &&
  103. (m_fixed_info.dwFileFlags & VS_FF_PATCHED ) )
  104. {
  105. m_bPatched = TRUE;
  106. }
  107. if ((m_fixed_info.dwFileFlagsMask & VS_FF_PRIVATEBUILD ) &&
  108. (m_fixed_info.dwFileFlags & VS_FF_PRIVATEBUILD ) )
  109. {
  110. m_bPrivateBuild = TRUE;
  111. }
  112. if ((m_fixed_info.dwFileFlagsMask & VS_FF_SPECIALBUILD ) &&
  113. (m_fixed_info.dwFileFlags & VS_FF_SPECIALBUILD) )
  114. {
  115. m_bSpecialBuild = TRUE;
  116. }
  117. TCHAR *start = szFileFlags;
  118. int len = 0;
  119. int remaining_len = ENTRY_COUNT(szFileFlags) - 1; // length in characters not bytes!
  120. int flags[] = {VS_FF_PATCHED, VS_FF_DEBUG, VS_FF_PRERELEASE, 0 };
  121. int ids[] = {IDS_PATCHED, IDS_DEBUG, IDS_BETA, 0 };
  122. assert(ENTRY_COUNT(flags) == ENTRY_COUNT(ids));
  123. for (int i = 0; flags[i], ids[i]; i++)
  124. {
  125. if ((m_fixed_info.dwFileFlagsMask & flags[i]) &&
  126. (m_fixed_info.dwFileFlags & flags[i]) && remaining_len > 1)
  127. {
  128. if (remaining_len)
  129. {
  130. remaining_len--;
  131. *start = _T(' ');
  132. start++;
  133. }
  134. // $$ if 4th parameter, maxbuffer = 0, LoadString doesn't return zero as advertised
  135. // reported to MS 9/29/1998
  136. len = ::LoadString(m_hInst, ids[i], start, remaining_len);
  137. start += len;
  138. remaining_len -= len;
  139. }
  140. }
  141. return TRUE;
  142. }