hxwinver.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,014 行 · 第 1/3 页

CPP
1,014
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxwinver.cpp,v 1.11.24.4 2004/07/09 01:48:16 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

#include "hxtypes.h"

#ifdef _WINDOWS
#include <windows.h>
#include <stdlib.h>             // needed for _MAX_PATH
#include <string.h>             // needed for strXXX() functions
#endif

#ifdef _MACINTOSH
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _MAC_MACHO
#include "OpenTransport.h"
#endif
//#include "productversion.r"
#endif

#if defined(HELIX_CONFIG_NOSTATICS)
# include "globals/hxglobals.h"
#endif
#include "hxassert.h"
#include "hxwinver.h"
#include "dbcs.h"
//#include "hlxclib/stdio.h"

#ifdef _WIN32
#include "hxdllldr.h"
#endif

#ifdef _UNIX
#include <stdlib.h>
#ifndef _VXWORKS
#include <sys/utsname.h>
#endif  // VXWORKS
#endif
#include "hxstrutl.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif

#ifdef _WINDOWS
// Helper function for Win32.
#if defined(_WIN32)
BOOL IsCoProcessorPresentInWinNT(void);
#else
extern "C" int FAR PASCAL Is586( void );
#endif
#if defined(_WIN32) || defined(_WINDOWS)
BOOL ExtractDistributionCode(char* pDistBuffer, HMODULE hModule);
#endif
#endif //_WINDOWS

// Helper functions for macintosh
#if defined(_MACINTOSH) || defined(_MAC_UNIX)
void    GetMacSystemVersion(UINT16      *major, UINT16  *minor, UINT16  *release);

#if !defined(_CARBON) && !defined(_MAC_UNIX)
BOOL    IsPPC(void);
BOOL    HasFPU(void);
BOOL    HasOpenTransport (void);
#endif
#endif

/*
** DWORD HXGetWinVer( HXVERSIONINFO *pVersionInfo )
*
*  PARAMETERS:
*              pVersionInfo : A pointer to the version info struct to receive the
*                             results.  (Can be NULL, in which case our only side
*                             effect is our return value).
*
*  DESCRIPTION:
*              Gets information on the Windows platform and version we are running on.
*
*  RETURNS:
*              A flag indicating the platform we are running on.
*
*              If this is a 16bit build of a Helix module, then
*              one of the following values is possible:
*
*                      HX_PLATFORM_WINNT
*                      HX_PLATFORM_WIN95
*                      HX_PLATFORM_WIN16
*
*              If this is a 32bit build of a Helix module, then
*              one of the following values is possible:
*
*                      HX_PLATFORM_WINNT
*                      HX_PLATFORM_WIN95
*                      HX_PLATFORM_WIN32S
*
*  NOTES:
*    The behavior of the GetVersion() API is totally different under
*    16bit and 32bit builds. As such we have been forced to implement
*    this function differently for each compiler version.
*
*/

ULONG32 HXGetWinVer( HXVERSIONINFO* lpVersionInfo )
{
    HXVERSIONINFO       rVersionInfo;

    // Initialize Defaults!
    rVersionInfo.dwPlatformId  = HX_PLATFORM_UNKNOWN;
    rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
    rVersionInfo.wMajorVersion = 0;
    rVersionInfo.wMinorVersion = 0;
    rVersionInfo.wReleaseVersion = 0;
    rVersionInfo.bFPUAvailable = FALSE;

#ifdef _WINDOWS ////////// WINDOWS SPECIFIC //////////

#ifdef _WIN32
    OSVERSIONINFO osVersionInfo;
    memset(&osVersionInfo, 0, sizeof(OSVERSIONINFO));
    osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osVersionInfo);
    rVersionInfo.wMajorVersion = (UINT16)(osVersionInfo.dwMajorVersion);
    rVersionInfo.wMinorVersion = (UINT16)(osVersionInfo.dwMinorVersion);
    rVersionInfo.wReleaseVersion = (UINT16)(osVersionInfo.dwBuildNumber);
    BOOL bIsNT = (osVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
#else
    ULONG32 dwVersion = GetVersion();
    rVersionInfo.wMajorVersion = (WORD)(LOBYTE( LOWORD( dwVersion ) ));
    rVersionInfo.wMinorVersion = (WORD)(HIBYTE( LOWORD( dwVersion ) ));
    BOOL bIsNT = ((GetWinFlags() & 0x4000) == 0x4000);
#endif


    if (bIsNT)
    {
        // Windows NT
        rVersionInfo.dwPlatformId = HX_PLATFORM_WINNT;
    }

#ifdef _WIN32
    // In a 32bit build, we call GetVersionEx:
    // Win95 returns MajorVersion 4, MinorVersion 0
    // Win98 returns MajorVersion 4, MinorVersion 10
    //
    else if (rVersionInfo.wMajorVersion < 4)
    {
        // Win32s
        rVersionInfo.dwPlatformId = HX_PLATFORM_WIN32S;
    }
    else if (rVersionInfo.wMajorVersion == 4)
    {
        if (rVersionInfo.wMinorVersion < 10)
        {
            // Win95
            rVersionInfo.dwPlatformId = HX_PLATFORM_WIN95;
        }
        else        {
            // Windows 98
            rVersionInfo.dwPlatformId = HX_PLATFORM_WIN98;
        }
    }
#else
    // In a 16bit build, we call GetVersion:
    // Win95 returns MajorVersion 3, MinorVersion 95
    // Win98 returns MajorVersion ??, MinorVersion ??
    //
    else if (rVersionInfo.wMajorVersion == 3)
    {
        if (rVersionInfo.wMinorVersion < 95)
        {
            // Win16
            rVersionInfo.dwPlatformId = HX_PLATFORM_WIN16;
        }
        else if (rVersionInfo.wMinorVersion < 98)
        {
            // Windows 98
            rVersionInfo.dwPlatformId = HX_PLATFORM_WIN95;
        }
        // XXXBJP need to confirm minorVersion > 95 in 16-bit Win98
        else 
        {
            // Windows 98
            rVersionInfo.dwPlatformId = HX_PLATFORM_WIN98;
        }
    }
#endif

    // Don't bother with any of the rest of this code, if no
    // struct was passed in!!!!!

    if (lpVersionInfo)
    {
        // Determine processor and FPU capabilities...
#if defined(_WIN32)
        SYSTEM_INFO     sysInfo;
        GetSystemInfo(&sysInfo);

        switch (sysInfo.wProcessorArchitecture)
        {
           case PROCESSOR_ARCHITECTURE_INTEL:
           {
               rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;

               // Only Newer versions of NT correctly supports wProcessorLevel.
               if       (
                   bIsNT
                   &&
                   (
                       (rVersionInfo.wMajorVersion > 3)
                       ||
                       (rVersionInfo.wMajorVersion == 3 && rVersionInfo.wMinorVersion >= 50)
                       )
                   )
               {
                   int nVerGreaterThan486 = (sysInfo.wProcessorLevel - 4);
                   if (nVerGreaterThan486 < 0)
                   {
                       rVersionInfo.dwMachineType = HX_MACHINE_TOOSLOW;
                   }
                   else if (nVerGreaterThan486 == 0)
                   {
                       rVersionInfo.dwMachineType = HX_MACHINE_486;
                   }
                   else if (nVerGreaterThan486 == 1)
                   {
                       rVersionInfo.dwMachineType = HX_MACHINE_586;
                   }
                   else if (nVerGreaterThan486 == 2)
                   {
                       rVersionInfo.dwMachineType = HX_MACHINE_686;
                   }
                   else
                   {
                       rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
                   }
               }
               else
               {
                   // Win95, Win32s, and old versions of NT don't correctly support
                   // Processor level, so instead we look at dwProcessorType
                   switch (sysInfo.dwProcessorType)
                   {
                      case PROCESSOR_INTEL_386:      rVersionInfo.dwMachineType = HX_MACHINE_TOOSLOW;  break;
                      case PROCESSOR_INTEL_486:      rVersionInfo.dwMachineType = HX_MACHINE_486;      break;
                      case PROCESSOR_INTEL_PENTIUM:  rVersionInfo.dwMachineType = HX_MACHINE_586;      break;
                      default:                       rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;  break;
                   }
               }
           }
           break;

           case PROCESSOR_ARCHITECTURE_MIPS:
           {
               rVersionInfo.dwMachineType = HX_MACHINE_MIPS;
           }
           break;

           case PROCESSOR_ARCHITECTURE_ALPHA:
           {
               rVersionInfo.dwMachineType = HX_MACHINE_ALPHA;
           }
           break;

           case PROCESSOR_ARCHITECTURE_PPC:
           {
               rVersionInfo.dwMachineType = HX_MACHINE_PPC;
           }
           break;

           default:
           {
               rVersionInfo.dwMachineType = HX_MACHINE_UNKNOWN;
           }
           break;
        }

        rVersionInfo.bFPUAvailable = IsCoProcessorPresentInWinNT();

#else
        DWORD dwWinFlags = GetWinFlags();
        if      (
            (dwWinFlags & WF_CPU386)
            ||
            (dwWinFlags & WF_CPU286)
            ||
            (dwWinFlags & WF_CPU186)
            ||
            (dwWinFlags & WF_CPU086)
            )

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?