hxwinver.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:31k
源码类别:

Symbian

开发平台:

Visual C++

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