hxwinver.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:30k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxtypes.h"
  36. #ifdef _WINDOWS
  37. #include <windows.h>
  38. #include <stdlib.h>             // needed for _MAX_PATH
  39. #include <string.h>             // needed for strXXX() functions
  40. #endif
  41. #ifdef _MACINTOSH
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #ifndef _MAC_MACHO
  46. #include "OpenTransport.h"
  47. #endif
  48. //#include "productversion.r"
  49. #endif
  50. #if defined(HELIX_CONFIG_NOSTATICS)
  51. # include "globals/hxglobals.h"
  52. #endif
  53. #include "hxassert.h"
  54. #include "hxwinver.h"
  55. #include "dbcs.h"
  56. //#include "hlxclib/stdio.h"
  57. #ifdef _WIN32
  58. #include "hxdllldr.h"
  59. #endif
  60. #ifdef _UNIX
  61. #include <stdlib.h>
  62. #ifndef _VXWORKS
  63. #include <sys/utsname.h>
  64. #endif  // VXWORKS
  65. #endif
  66. #include "hxstrutl.h"
  67. #include "hxheap.h"
  68. #ifdef _DEBUG
  69. #undef HX_THIS_FILE
  70. static const char HX_THIS_FILE[] = __FILE__;
  71. #endif
  72. #ifdef _WINDOWS
  73. // Helper function for Win32.
  74. #if defined(_WIN32)
  75. BOOL IsCoProcessorPresentInWinNT(void);
  76. #else
  77. extern "C" int FAR PASCAL Is586( void );
  78. #endif
  79. #if defined(_WIN32) || defined(_WINDOWS)
  80. BOOL ExtractDistributionCode(char* pDistBuffer, HMODULE hModule);
  81. #endif
  82. #endif //_WINDOWS
  83. // Helper functions for macintosh
  84. #if defined(_MACINTOSH) || defined(_MAC_UNIX)
  85. void    GetMacSystemVersion(UINT16      *major, UINT16  *minor, UINT16  *release);
  86. #if !defined(_CARBON) && !defined(_MAC_UNIX)
  87. BOOL    IsPPC(void);
  88. BOOL    HasFPU(void);
  89. BOOL    HasOpenTransport (void);
  90. #endif
  91. #endif
  92. /*
  93. ** DWORD HXGetWinVer( HXVERSIONINFO *pVersionInfo )
  94. *
  95. *  PARAMETERS:
  96. *              pVersionInfo : A pointer to the version info struct to receive the
  97. *                             results.  (Can be NULL, in which case our only side
  98. *                             effect is our return value).
  99. *
  100. *  DESCRIPTION:
  101. *              Gets information on the Windows platform and version we are running on.
  102. *
  103. *  RETURNS:
  104. *              A flag indicating the platform we are running on.
  105. *
  106. *              If this is a 16bit build of a Helix module, then
  107. *              one of the following values is possible:
  108. *
  109. *                      HX_PLATFORM_WINNT
  110. *                      HX_PLATFORM_WIN95
  111. *                      HX_PLATFORM_WIN16
  112. *
  113. *              If this is a 32bit build of a Helix module, then
  114. *              one of the following values is possible:
  115. *
  116. *                      HX_PLATFORM_WINNT
  117. *                      HX_PLATFORM_WIN95
  118. *                      HX_PLATFORM_WIN32S
  119. *
  120. *  NOTES:
  121. *    The behavior of the GetVersion() API is totally different under
  122. *    16bit and 32bit builds. As such we have been forced to implement
  123. *    this function differently for each compiler version.
  124. *
  125. */
  126. ULONG32 HXGetWinVer( HXVERSIONINFO* lpVersionInfo )
  127. {
  128.     HXVERSIONINFO       rVersionInfo;
  129.     // Initialize Defaults!
  130.     rVersionInfo.dwPlatformId  = HX_PLATFORM_UNKNOWN;
  131.     rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
  132.     rVersionInfo.wMajorVersion = 0;
  133.     rVersionInfo.wMinorVersion = 0;
  134.     rVersionInfo.wReleaseVersion = 0;
  135.     rVersionInfo.bFPUAvailable = FALSE;
  136. #ifdef _WINDOWS ////////// WINDOWS SPECIFIC //////////
  137. #ifdef _WIN32
  138.     OSVERSIONINFO osVersionInfo;
  139.     memset(&osVersionInfo, 0, sizeof(OSVERSIONINFO));
  140.     osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  141.     GetVersionEx(&osVersionInfo);
  142.     rVersionInfo.wMajorVersion = (UINT16)(osVersionInfo.dwMajorVersion);
  143.     rVersionInfo.wMinorVersion = (UINT16)(osVersionInfo.dwMinorVersion);
  144.     rVersionInfo.wReleaseVersion = (UINT16)(osVersionInfo.dwBuildNumber);
  145.     BOOL bIsNT = (osVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
  146. #else
  147.     ULONG32 dwVersion = GetVersion();
  148.     rVersionInfo.wMajorVersion = (WORD)(LOBYTE( LOWORD( dwVersion ) ));
  149.     rVersionInfo.wMinorVersion = (WORD)(HIBYTE( LOWORD( dwVersion ) ));
  150.     BOOL bIsNT = ((GetWinFlags() & 0x4000) == 0x4000);
  151. #endif
  152.     if (bIsNT)
  153.     {
  154.         // Windows NT
  155.         rVersionInfo.dwPlatformId = HX_PLATFORM_WINNT;
  156.     }
  157. #ifdef _WIN32
  158.     // In a 32bit build, we call GetVersionEx:
  159.     // Win95 returns MajorVersion 4, MinorVersion 0
  160.     // Win98 returns MajorVersion 4, MinorVersion 10
  161.     //
  162.     else if (rVersionInfo.wMajorVersion < 4)
  163.     {
  164.         // Win32s
  165.         rVersionInfo.dwPlatformId = HX_PLATFORM_WIN32S;
  166.     }
  167.     else if (rVersionInfo.wMajorVersion == 4)
  168.     {
  169.         if (rVersionInfo.wMinorVersion < 10)
  170.         {
  171.             // Win95
  172.             rVersionInfo.dwPlatformId = HX_PLATFORM_WIN95;
  173.         }
  174.         else        {
  175.             // Windows 98
  176.             rVersionInfo.dwPlatformId = HX_PLATFORM_WIN98;
  177.         }
  178.     }
  179. #else
  180.     // In a 16bit build, we call GetVersion:
  181.     // Win95 returns MajorVersion 3, MinorVersion 95
  182.     // Win98 returns MajorVersion ??, MinorVersion ??
  183.     //
  184.     else if (rVersionInfo.wMajorVersion == 3)
  185.     {
  186.         if (rVersionInfo.wMinorVersion < 95)
  187.         {
  188.             // Win16
  189.             rVersionInfo.dwPlatformId = HX_PLATFORM_WIN16;
  190.         }
  191.         else if (rVersionInfo.wMinorVersion < 98)
  192.         {
  193.             // Windows 98
  194.             rVersionInfo.dwPlatformId = HX_PLATFORM_WIN95;
  195.         }
  196.         // XXXBJP need to confirm minorVersion > 95 in 16-bit Win98
  197.         else 
  198.         {
  199.             // Windows 98
  200.             rVersionInfo.dwPlatformId = HX_PLATFORM_WIN98;
  201.         }
  202.     }
  203. #endif
  204.     // Don't bother with any of the rest of this code, if no
  205.     // struct was passed in!!!!!
  206.     if (lpVersionInfo)
  207.     {
  208.         // Determine processor and FPU capabilities...
  209. #if defined(_WIN32)
  210.         SYSTEM_INFO     sysInfo;
  211.         GetSystemInfo(&sysInfo);
  212.         switch (sysInfo.wProcessorArchitecture)
  213.         {
  214.            case PROCESSOR_ARCHITECTURE_INTEL:
  215.            {
  216.                rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
  217.                // Only Newer versions of NT correctly supports wProcessorLevel.
  218.                if       (
  219.                    bIsNT
  220.                    &&
  221.                    (
  222.                        (rVersionInfo.wMajorVersion > 3)
  223.                        ||
  224.                        (rVersionInfo.wMajorVersion == 3 && rVersionInfo.wMinorVersion >= 50)
  225.                        )
  226.                    )
  227.                {
  228.                    int nVerGreaterThan486 = (sysInfo.wProcessorLevel - 4);
  229.                    if (nVerGreaterThan486 < 0)
  230.                    {
  231.                        rVersionInfo.dwMachineType = HX_MACHINE_TOOSLOW;
  232.                    }
  233.                    else if (nVerGreaterThan486 == 0)
  234.                    {
  235.                        rVersionInfo.dwMachineType = HX_MACHINE_486;
  236.                    }
  237.                    else if (nVerGreaterThan486 == 1)
  238.                    {
  239.                        rVersionInfo.dwMachineType = HX_MACHINE_586;
  240.                    }
  241.                    else if (nVerGreaterThan486 == 2)
  242.                    {
  243.                        rVersionInfo.dwMachineType = HX_MACHINE_686;
  244.                    }
  245.                    else
  246.                    {
  247.                        rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
  248.                    }
  249.                }
  250.                else
  251.                {
  252.                    // Win95, Win32s, and old versions of NT don't correctly support
  253.                    // Processor level, so instead we look at dwProcessorType
  254.                    switch (sysInfo.dwProcessorType)
  255.                    {
  256.                       case PROCESSOR_INTEL_386:      rVersionInfo.dwMachineType = HX_MACHINE_TOOSLOW;  break;
  257.                       case PROCESSOR_INTEL_486:      rVersionInfo.dwMachineType = HX_MACHINE_486;      break;
  258.                       case PROCESSOR_INTEL_PENTIUM:  rVersionInfo.dwMachineType = HX_MACHINE_586;      break;
  259.                       default:                       rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;  break;
  260.                    }
  261.                }
  262.            }
  263.            break;
  264.            case PROCESSOR_ARCHITECTURE_MIPS:
  265.            {
  266.                rVersionInfo.dwMachineType = HX_MACHINE_MIPS;
  267.            }
  268.            break;
  269.            case PROCESSOR_ARCHITECTURE_ALPHA:
  270.            {
  271.                rVersionInfo.dwMachineType = HX_MACHINE_ALPHA;
  272.            }
  273.            break;
  274.            case PROCESSOR_ARCHITECTURE_PPC:
  275.            {
  276.                rVersionInfo.dwMachineType = HX_MACHINE_PPC;
  277.            }
  278.            break;
  279.            default:
  280.            {
  281.                rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
  282.            }
  283.            break;
  284.         }
  285.         rVersionInfo.bFPUAvailable = IsCoProcessorPresentInWinNT();
  286. #else
  287.         DWORD dwWinFlags = GetWinFlags();
  288.         if      (
  289.             (dwWinFlags & WF_CPU386)
  290.             ||
  291.             (dwWinFlags & WF_CPU286)
  292.             ||
  293.             (dwWinFlags & WF_CPU186)
  294.             ||
  295.             (dwWinFlags & WF_CPU086)
  296.             )
  297.         {
  298.             rVersionInfo.dwMachineType = HX_MACHINE_TOOSLOW;
  299.         }
  300.         if (dwWinFlags & WF_CPU486)
  301.         {
  302. #ifdef _WIN16
  303.             //=-=w16.3 Is586() asserts pentium.obj; must be fixed; #ifdefed to TRUE
  304.             int nVerGreaterThan486 = TRUE;
  305. #else
  306.             int nVerGreaterThan486 = Is586();
  307. #endif
  308.             switch(nVerGreaterThan486)
  309.             {
  310.                case 0:  rVersionInfo.dwMachineType = HX_MACHINE_486;     break;
  311.                case 1:  rVersionInfo.dwMachineType = HX_MACHINE_586;     break;
  312.                case 2:  rVersionInfo.dwMachineType = HX_MACHINE_686;     break;
  313.                default: rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN; break;
  314.             }
  315.         }
  316.         if (dwWinFlags & WF_80x87)
  317.         {
  318.             rVersionInfo.bFPUAvailable = TRUE;
  319.         }
  320. #endif
  321.     }
  322. ////////// END WINDOWS SPECIFIC //////////
  323. ////////// START MACINTOSH SPECIFIC CODE//////////
  324. #elif defined(_MACINTOSH) || defined(_MAC_UNIX)
  325. #if defined(_CARBON) || defined(_MAC_UNIX)
  326.     rVersionInfo.dwPlatformId  = HX_PLATFORM_MACOT;
  327.     rVersionInfo.dwMachineType = HX_MACHINE_PPC;
  328.     rVersionInfo.bFPUAvailable = FALSE;
  329. #else
  330.     if (HasOpenTransport())
  331.         rVersionInfo.dwPlatformId  = HX_PLATFORM_MACOT;
  332.     else
  333.         rVersionInfo.dwPlatformId  = HX_PLATFORM_MACTCP;
  334.     if (IsPPC())
  335.         rVersionInfo.dwMachineType = HX_MACHINE_PPC;
  336.     else
  337.         rVersionInfo.dwMachineType = HX_MACHINE_68K;
  338.     rVersionInfo.bFPUAvailable = HasFPU();
  339. #endif
  340.     GetMacSystemVersion(&rVersionInfo.wMajorVersion,
  341.                         &rVersionInfo.wMinorVersion,
  342.                         &rVersionInfo.wReleaseVersion);
  343. ////////// END MACINTOSH SPECIFIC CODE////////////
  344. #elif defined(_UNIX)
  345.     struct utsname osInfo;   // structure to hold uname info
  346.     if (uname(&osInfo) != -1)
  347.     {
  348.         double nVersionNum = atof(osInfo.release);  // version number
  349.         char *pPeriod = NULL;
  350.         rVersionInfo.wMajorVersion = (UINT16)nVersionNum;
  351.         if (pPeriod = strchr(osInfo.release,'.'))
  352.             rVersionInfo.wMinorVersion = atoi(pPeriod+1);
  353.         // CODE FOR LINUX
  354. #ifdef _LINUX
  355.         // These are defaults, they are not 100% correct but they shouldn't be needed
  356.         rVersionInfo.dwPlatformId = HX_PLATFORM_LINUX;
  357.         rVersionInfo.dwMachineType = HX_MACHINE_586;
  358.         // CODE FOR SOLARIS
  359. #elif _SOLARIS
  360.         // These are defaults, they are not 100% correct but they shouldn't be needed
  361.         rVersionInfo.dwPlatformId = HX_PLATFORM_SOLARIS;
  362.         rVersionInfo.dwMachineType = HX_MACHINE_SPARC;
  363.         // do platform mapping
  364.         if (!strcasecmp("SunOS",osInfo.sysname))
  365.         {
  366.             if (nVersionNum > 5.0)
  367.                 rVersionInfo.dwPlatformId = HX_PLATFORM_SOLARIS;
  368.             else
  369.                 rVersionInfo.dwPlatformId = HX_PLATFORM_SUNOS;
  370.         }
  371.         // do machine mapping
  372.         if (!strcasecmp("sun4m",osInfo.machine))
  373.             rVersionInfo.dwMachineType = HX_MACHINE_SPARC;
  374.         // CODE FOR IRIX
  375. #elif _IRIX
  376.         rVersionInfo.dwPlatformId = HX_PLATFORM_IRIX;
  377.         rVersionInfo.dwMachineType = HX_MACHINE_MIPS;
  378.         // CODE FOR SUNOS
  379. #elif _SUNOS
  380.         // These are defaults, they are not 100% correct but they shouldn't be needed
  381.         rVersionInfo.dwPlatformId = HX_PLATFORM_SUNOS;
  382.         rVersionInfo.dwMachineType = HX_MACHINE_SPARC;
  383.         // do platform mapping
  384.         if (!strcasecmp("SunOS",osInfo.sysname))
  385.         {
  386.             if (nVersionNum > 5.0)
  387.                 rVersionInfo.dwPlatformId = HX_PLATFORM_SOLARIS;
  388.             else
  389.                 rVersionInfo.dwPlatformId = HX_PLATFORM_SUNOS;
  390.         }
  391.         // do machine mapping
  392.         if (!strcasecmp("sun4m",osInfo.machine))
  393.             rVersionInfo.dwMachineType = HX_MACHINE_SPARC;
  394. #else
  395.         rVersionInfo.dwPlatformId = HX_PLATFORM_UNKNOWN;
  396.         rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
  397. #endif
  398.     }
  399.     rVersionInfo.bFPUAvailable = TRUE;
  400. ////////// END UNIX SPECIFIC CODE////////////
  401. #elif defined(_SYMBIAN)
  402.     
  403.     rVersionInfo.dwPlatformId  = HX_PLATFORM_SYMBIAN;
  404. #ifdef __WINS__    
  405.     rVersionInfo.dwMachineType = HX_MACHINE_SYMEMULATOR;
  406. #else
  407.     rVersionInfo.dwMachineType = HX_MACHINE_ARM;
  408. #endif
  409.     //XXGFW need to not hard code this.
  410.     rVersionInfo.wMajorVersion   = 6;
  411.     rVersionInfo.wMinorVersion   = 1;
  412.     rVersionInfo.wReleaseVersion = 0;
  413.     rVersionInfo.bFPUAvailable   = FALSE;
  414.     
  415. #elif defined(_OPENWAVE)
  416.     
  417.     rVersionInfo.dwPlatformId  = HX_PLATFORM_OPENWAVE;
  418. #ifdef _OPENWAVE_SIMULATOR
  419.     rVersionInfo.dwMachineType = HX_MACHINE_OWEMULATOR;
  420. #else
  421.     rVersionInfo.dwMachineType = HX_MACHINE_ARM;
  422. #endif
  423.     // XXXSAB need to not hard code this.
  424.     rVersionInfo.wMajorVersion   = 6;
  425.     rVersionInfo.wMinorVersion   = 1;
  426.     rVersionInfo.wReleaseVersion = 0;
  427.     rVersionInfo.bFPUAvailable   = FALSE;
  428.     
  429. #else
  430. #error Add your platform code here!
  431. #endif
  432.     if (lpVersionInfo)
  433.     {
  434.         *lpVersionInfo = rVersionInfo;
  435.     }
  436.     return( rVersionInfo.dwPlatformId );
  437. }
  438. /*
  439.  *      const char* HXGetOSName( ULONG32 nPlatformID)
  440.  *
  441.  *  PARAMETERS:
  442.  *              nPlatformID:    A platformID (defined in hxwinver.h)
  443.  *
  444.  *  DESCRIPTION:
  445.  *              Returns an OS string. Indicates the OS, not the build of
  446.  *      the player.
  447.  *
  448.  *  RETURNS:
  449.  *              pointer to static const buffer containing OS string.
  450.  */
  451. const char* HXGetOSName(ULONG32 nPlatformID)
  452. {
  453.     const char* strResult = NULL;
  454.     switch (nPlatformID)
  455.     {
  456.        case (HX_PLATFORM_WIN16) :
  457.            strResult="Win16";
  458.            break;
  459.        case (HX_PLATFORM_WIN32S) :
  460.            strResult="Win32S";
  461.            break;
  462.        case (HX_PLATFORM_WIN95) :
  463.            strResult="Win95";
  464.            break;
  465.        case (HX_PLATFORM_WIN98) :
  466.            strResult="Win98";
  467.            break;
  468.        case (HX_PLATFORM_WINNT) :
  469.            strResult="WinNT";
  470.            break;
  471.        case (HX_PLATFORM_MACOT) :
  472.            strResult="MacOT";
  473.            break;
  474.        case (HX_PLATFORM_MACTCP) :
  475.            strResult="MacTCP";
  476.            break;
  477.        case (HX_PLATFORM_LINUX) :
  478.            strResult="Linux";
  479.            break;
  480.        case (HX_PLATFORM_SOLARIS) :
  481.            strResult="Solaris";
  482.            break;
  483.        case (HX_PLATFORM_IRIX) :
  484.            strResult="Irix";
  485.            break;
  486.        case (HX_PLATFORM_SUNOS) :
  487.            strResult="SunOS";
  488.            break;
  489.        case (HX_PLATFORM_SYMBIAN):
  490.            strResult="Symbian";
  491.            break;
  492.        case (HX_PLATFORM_UNKNOWN) :
  493.        default:
  494.            strResult="UNK";
  495.            break;
  496.     }
  497.     return(strResult);
  498. }
  499. /*
  500.  *      const char* HXGetMachName(ULONG32 nMachineType)
  501.  *
  502.  *  PARAMETERS:
  503.  *              nMachineType:   A machine ID (defined in hxwinver.h)
  504.  *
  505.  *  DESCRIPTION:
  506.  *              Returns a Machine string. Indicates the installed CPU,
  507.  *      not the build of the player.
  508.  *
  509.  *  RETURNS:
  510.  *              pointer to static const buffer containing Machine string.
  511.  */
  512. const char* HXGetMachName(ULONG32 nMachineType)
  513. {
  514.     const char* pProcName = NULL;
  515.     switch (nMachineType)
  516.     {
  517.        case HX_MACHINE_486:
  518.            pProcName = "486";
  519.            break;
  520.        case HX_MACHINE_586:
  521.            pProcName = "586";
  522.            break;
  523.        case HX_MACHINE_686:
  524.            pProcName = "686";
  525.            break;
  526.        case HX_MACHINE_PPC:
  527.            pProcName = "PPC";
  528.            break;
  529.        case HX_MACHINE_68K:
  530.            pProcName = "68K";
  531.            break;
  532.        case HX_MACHINE_ALPHA:
  533.            pProcName = "Alpha";
  534.            break;
  535.        case HX_MACHINE_MIPS:
  536.            pProcName = "Mips";
  537.            break;
  538.        case HX_MACHINE_SPARC:
  539.            pProcName = "Sparc";
  540.            break;
  541.        case HX_MACHINE_TOOSLOW:
  542.            pProcName = "SLOW";
  543.            break;
  544.        case HX_MACHINE_ARM:
  545.            pProcName = "ARM";
  546.            break;
  547.        case HX_MACHINE_SYMEMULATOR:
  548.            pProcName = "SymbianEmulator";
  549.            break;
  550.  
  551.        case HX_MACHINE_UNKNOWN:
  552.        default:
  553.            pProcName = "UNK";
  554.            break;
  555.     }
  556.     return(pProcName);
  557. }
  558. /*
  559.  *      const char* HXGetVerEncodedName( HXVERSIONINFO* pVersionInfo,
  560.  *                                      const char* pProductName, const char* pProductVer,
  561.  *                                      const char* pDistCode)
  562.  *
  563.  *  PARAMETERS:
  564.  *              pVersionInfo :  A pointer to the version info struct to receive the
  565.  *                                              results.
  566.  *
  567.  *              pProductName :  A pointer to the name of the product like play16 for
  568.  *                                              the 16bit compiled player or plug32 for the 32bit
  569.  *                                              compiled plugin.
  570.  *
  571.  *              pProductVer :   A pointer to the string form of the version of the
  572.  *                                              product like 2.0b3.
  573.  *
  574.  *              pDistCode       :       A pointer to the string form of the version of the
  575.  *                                              distribution code like PN01 for the player.
  576.  *
  577.  *  DESCRIPTION:    
  578.  *              Returns a standard formatted encoded platform string.
  579.  *
  580.  *  RETURNS:
  581.  *              pointer to temporary buffer containing the encoded string.
  582.  */
  583. const char* HXGetVerEncodedName
  584. (
  585.     HXVERSIONINFO* pVersionInfo,
  586.     const char* pProductName,
  587.     const char* pProductVer,
  588.     const char* pLanguage,
  589.     const char* pDistCode
  590.     )
  591. {
  592. #if defined(HELIX_CONFIG_NOSTATICS)
  593.     static const char _szEncodedName = '';
  594.     char*& szEncodedName = HXGlobalCharArray::Get(&_szEncodedName, MAX_ENCODED_NAME, "" );
  595. #else
  596.     static char szEncodedName[MAX_ENCODED_NAME]; /* Flawfinder: ignore */
  597. #endif        
  598.     HX_ASSERT_VALID_READ_PTR(pVersionInfo);
  599.     HX_ASSERT_VALID_READ_PTR(pProductName);
  600.     HX_ASSERT_VALID_READ_PTR(pProductVer);
  601.     HX_ASSERT_VALID_READ_PTR(pLanguage);
  602.     HX_ASSERT_VALID_READ_PTR(pDistCode);
  603.     const char* pOSName = "UNK";
  604.     const char* pProcName = "UNK";
  605.     // Calculate OS Name from
  606.     pOSName = HXGetOSName(pVersionInfo->dwPlatformId);
  607.     // CPU/Process/machine. same thing...
  608.     pProcName = HXGetMachName(pVersionInfo->dwMachineType);
  609. #ifdef _MACINTOSH
  610.     // Macintosh OS version currently includes a wReleaseVersion number.
  611.     SafeSprintf(szEncodedName,MAX_ENCODED_NAME,"%s_%d.%d.%d_%s_%s_%s_%s_%s%s",
  612.                 pOSName,
  613.                 pVersionInfo->wMajorVersion,
  614.                 pVersionInfo->wMinorVersion,
  615.                 pVersionInfo->wReleaseVersion,
  616.                 pProductVer,
  617.                 pProductName,
  618.                 pDistCode,
  619.                 pLanguage,
  620.                 pProcName,
  621.                 (pVersionInfo->bFPUAvailable ? "" : "_No-FPU")
  622.                 );
  623. #else
  624.     // WINDOWS and UNIX
  625.     SafeSprintf(szEncodedName,MAX_ENCODED_NAME, "%s_%d.%d_%s_%s_%s_%s_%s%s",
  626.                 pOSName,
  627.                 pVersionInfo->wMajorVersion,
  628.                 pVersionInfo->wMinorVersion,
  629.                 pProductVer,
  630.                 pProductName,
  631.                 pDistCode,
  632.                 pLanguage,
  633.                 pProcName,
  634.                 (pVersionInfo->bFPUAvailable ? "" : "_No-FPU")
  635.                 );
  636. #endif
  637.     return szEncodedName;
  638. };
  639. //      Code From:
  640. //
  641. //      PSS ID Number: Q124207
  642. //
  643. //      Authored 21-Dec-1994                    Last modified 05-Jan-1995
  644. //
  645. //      The information in this article applies to:
  646. //
  647. //      - Microsoft Win32 Software Development Kit (SDK) for Windows NT
  648. //      versions 3.1 and 3.5
  649. #if defined(_WIN32) 
  650. BOOL IsCoProcessorPresentInWinNT(void)
  651. {
  652. #if !defined(WIN32_PLATFORM_PSPC)
  653.     HKEY hKey;
  654.     SYSTEM_INFO SystemInfo;
  655.     
  656.     // return FALSE if we are not running under Windows NT
  657.     // this should be expanded to cover alternative Win32 platforms
  658.     
  659.     if(!(GetVersion() & 0x7FFFFFFF))
  660.     {
  661.         return(FALSE); // We can't tell, assume it doesn't
  662.     }
  663.     
  664.     // we return TRUE if we're not running on x86
  665.     // other CPUs have built in floating-point, with no registry entry
  666.     GetSystemInfo(&SystemInfo);
  667.     if(SystemInfo.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_INTEL)
  668.     {
  669.         return(TRUE);
  670.     }
  671.     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  672.                     "HARDWARE\DESCRIPTION\System\FloatingPointProcessor",
  673.                     0,
  674.                     KEY_EXECUTE,
  675.                     &hKey) != ERROR_SUCCESS)
  676.     {
  677.         // GetLastError() will indicate ERROR_RESOURCE_DATA_NOT_FOUND
  678.         // if we can't find the key.  This indicates no coprocessor present
  679.         return(FALSE);
  680.     }
  681.     RegCloseKey(hKey);
  682.     return(TRUE);
  683. #else /*!defined(WIN32_PLATFORM_PSPC) */
  684.     return FALSE;
  685. #endif /* !defined(WIN32_PLATFORM_PSPC) */
  686. }
  687. #endif
  688. ///////////////////////////////////////////////////////////////////////
  689. //
  690. //      FUNCTION:
  691. //
  692. //              HXExtractDistributionCode()
  693. //
  694. //      Description:
  695. //
  696. //              Extracts the distribution code resource from the version
  697. //              information of the module.
  698. //
  699. //
  700. BOOL HXExtractDistributionCode(char* pDistBuffer, UINT32 ulDistBufferLen, void* hMod)
  701. {
  702.     BOOL        bOk = FALSE;
  703. #if (defined(_WIN32) || defined(_WINDOWS)) && !defined(WIN32_PLATFORM_PSPC)
  704.     // load version.dll
  705.     HINSTANCE               hLib = NULL;
  706.     VERQUERYVALUE           _pVerQueryValue = NULL;
  707.     GETFILEVERSIONINFO      _pGetFileVersionInfo = NULL;
  708.     GETFILEVERSIONINFOSIZE  _pGetFileVersionInfoSize = NULL;
  709.     if (hLib = HXLoadLibrary("version.dll"))
  710.     {
  711.         _pVerQueryValue = (VERQUERYVALUE)GetProcAddress(hLib, "VerQueryValueA");
  712.         _pGetFileVersionInfo = (GETFILEVERSIONINFO)GetProcAddress(hLib, "GetFileVersionInfoA");
  713.         _pGetFileVersionInfoSize = (GETFILEVERSIONINFOSIZE)GetProcAddress(hLib, "GetFileVersionInfoSizeA");
  714.     }
  715.     if (_pVerQueryValue         &&
  716.         _pGetFileVersionInfo    &&
  717.         _pGetFileVersionInfoSize)
  718.     {
  719.         HINSTANCE hModule = (HINSTANCE)(long)hMod;
  720.         DWORD   dwVerInfoSize;
  721.         DWORD   dwVerHnd;
  722.         char    szFullPath[_MAX_PATH+1]; /* Flawfinder: ignore */
  723.         if (GetModuleFileName(hModule,szFullPath, _MAX_PATH))
  724.         {
  725.             dwVerInfoSize = _pGetFileVersionInfoSize(szFullPath, &dwVerHnd);
  726.             if (dwVerInfoSize)
  727.             {
  728.                 LPSTR   lpstrVffInfo;             // Pointer to block to hold info
  729.                 HANDLE  hMem;                     // handle to mem alloc'ed
  730.                 // Get a block big enough to hold version info
  731.                 hMem          = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  732.                 lpstrVffInfo  = (char *)GlobalLock(hMem);
  733.                 if(_pGetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo ))
  734.                 {
  735.                     char    szGetName[_MAX_PATH]; /* Flawfinder: ignore */
  736.                     UINT    VersionLen;
  737.                     LPSTR   lpVersion;
  738.                     BOOL    bRetCode;
  739.                     SafeStrCpy(szGetName, "\VarFileInfo\Translation", _MAX_PATH);
  740.                     bRetCode = _pVerQueryValue(lpstrVffInfo, szGetName,
  741.                                                (void FAR* FAR*)&lpVersion, &VersionLen);
  742.                     char TransNumber[10]; /* Flawfinder: ignore */
  743.                     wsprintf(TransNumber, "%8lx", *(long *)lpVersion);
  744.                     char *pSpace = HXFindChar(TransNumber, ' ');
  745.                     while(pSpace)
  746.                     {
  747.                         *pSpace = '0';
  748.                         pSpace = (char*)HXFindChar(TransNumber, ' ');
  749.                     }
  750.                     SafeStrCpy(szGetName, "\StringFileInfo\", _MAX_PATH);
  751.                     SafeStrCat(szGetName, TransNumber + 4, _MAX_PATH);
  752.                     TransNumber[4] = 0;
  753.                     SafeStrCat(szGetName, TransNumber, _MAX_PATH);
  754.                     SafeStrCat(szGetName, "\DistCode", _MAX_PATH);
  755.                     bRetCode = _pVerQueryValue(lpstrVffInfo, szGetName,
  756.                                                (void FAR* FAR*)&lpVersion, &VersionLen);
  757.                     if ( bRetCode && VersionLen && lpVersion)
  758.                     {
  759.                         SafeStrCpy(pDistBuffer,lpVersion, ulDistBufferLen);
  760.                         bOk = TRUE;
  761.                     }
  762.                 }
  763.                 // Let go of the memory
  764.                 GlobalUnlock(hMem);
  765.                 GlobalFree(hMem);
  766.             }
  767.         }
  768.         if (!bOk)
  769.         {
  770.             SafeStrCpy(pDistBuffer,"UNK", ulDistBufferLen);
  771.         }
  772.     }
  773.     HXFreeLibrary("version.dll");
  774. #elif defined (_MACINTOSH)
  775.     // dist code stored in STR 1000 resource of application
  776.     INT16 strResId = 1000;
  777.     StringHandle hStr = ::GetString(strResId);
  778.     if (hStr)
  779.     {
  780.         if ((*hStr)[0] < ulDistBufferLen)
  781.         {
  782.             strncpy(pDistBuffer,(char*)*hStr+1,(*hStr)[0]); /* Flawfinder: ignore */
  783.             pDistBuffer[(*hStr)[0]] = 0;
  784.         }
  785.         ::ReleaseResource((Handle)hStr);
  786.         bOk = TRUE;
  787.     }
  788.     else
  789.     {
  790.         SafeStrCpy(pDistBuffer,"UNK", ulDistBufferLen);
  791.     }
  792.     
  793. #endif // defined(_WIN32) || defined(_WINDOWS)
  794.     return bOk;
  795. }
  796. #if defined(_MACINTOSH) || defined(_MAC_UNIX)
  797. // Support functions for HXGetWinVer for Macintosh
  798. #if !defined(_CARBON) && !defined(_MAC_UNIX) // Carbon code runs only on PPC processors with OT so runtime checks are pointless
  799. BOOL
  800. HasOpenTransport (void)
  801. {
  802.     OSErr   theErr = noErr;
  803.     LONG32  result;
  804.     Boolean hasOT = FALSE;
  805.     theErr = Gestalt(gestaltOpenTpt, &result);
  806.     hasOT = theErr == noErr &&
  807.         (result & gestaltOpenTptPresentMask) != 0 &&
  808.         (result & gestaltOpenTptTCPPresentMask) != 0;
  809.     return hasOT;
  810. }
  811. BOOL
  812. HasFPU(void)
  813. {
  814.     long    theFPU;
  815.     /* Determine the coprocessor type */
  816.     Gestalt(gestaltFPUType, &theFPU);
  817.     if(theFPU == gestaltNoFPU)
  818.         return FALSE;
  819.     return TRUE;
  820. }
  821. BOOL
  822. IsPPC(void) {
  823.     long    theCPU;
  824.     Gestalt(gestaltNativeCPUtype, &theCPU);
  825.     if (theCPU >= gestaltCPU601) return(TRUE);
  826.     return(FALSE);
  827. }
  828. #endif // !_CARBON
  829. static UINT16 
  830. BCDtoDecimal(UINT16 bcd)
  831. {
  832.     UINT16 decimal;
  833.     decimal =            1 * ((bcd & 0x000F) >> 0)
  834.         +   10 * ((bcd & 0x00F0) >> 4) 
  835.         +  100 * ((bcd & 0x0F00) >> 8) 
  836.         + 1000 * ((bcd & 0xF000) >> 12); 
  837.     return decimal;
  838. }
  839. void
  840. GetMacSystemVersion(UINT16 *major, UINT16 *minor, UINT16 *release)
  841. {
  842.     long    gestVer;
  843.     UINT16  ver, bigRev, littleRev;
  844.     OSErr err = Gestalt(gestaltSystemVersion, &gestVer); // returns a BCD number, like 0x00001015 for 10.1.5
  845.     if (err == noErr)
  846.     {
  847.         ver =       BCDtoDecimal((gestVer & 0x0000FF00) >> 8);
  848.         bigRev =    BCDtoDecimal((gestVer & 0x000000F0) >> 4);
  849.         littleRev = BCDtoDecimal((gestVer & 0x0000000F));
  850.     }
  851.     else
  852.     {
  853.         ver = bigRev = littleRev = 0;
  854.     }
  855.         
  856. //don't want to include mathlib in plugin
  857. //      ::sprintf(s,"%ld.%ld.%ld",ver,majorRev,minorRev);
  858. //      ver += 0x30; majorRev += 0x30; minorRev += 0x30;  // GR 7/4/02 why was this converting to ascii? (the conversion would fail for numbers over 9 anyway)
  859.     if (major)      *major = ver;
  860.     if (minor)      *minor = bigRev;
  861.     if (release)    *release = littleRev;
  862. }
  863. #endif // _MACINTOSH