Changeset 797


Ignore:
Timestamp:
Oct 19, 2010, 1:11:10 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Implemented QSysInfo::os2Version() (closes #66).

Location:
trunk/src/corelib/global
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/global/qglobal.cpp

    r769 r797  
    10391039    \o \l MacintoshVersion specifies the version of the Macintosh
    10401040       operating system on which the application is run (Mac only).
     1041    \o \l os2Version() specifies the version of the OS/2
     1042       operating system on which the application is run (OS/2 only).
    10411043    \endlist
    10421044
    10431045    Some constants are defined only on certain platforms. You can use
    1044     the preprocessor symbols Q_WS_WIN and Q_WS_MAC to test that
    1045     the application is compiled under Windows or Mac.
     1046    the preprocessor symbols Q_WS_WIN, Q_OS_MAC and Q_OS_OS2 to test that the
     1047    application is compiled under Windows, Mac or OS/2.
    10461048
    10471049    \sa QLibraryInfo
     
    10921094    Returns the version of the S60 SDK system on which the
    10931095    application is run (S60 only).
     1096*/
     1097
     1098/*!
     1099    \fn QSysInfo::Os2Version QSysInfo::os2Version()
     1100    \since 4.6
     1101
     1102    Returns the version of the OS/2 operating system on which the
     1103    application is run (OS/2 only).
    10941104*/
    10951105
     
    12191229
    12201230    \sa SymbianVersion, WinVersion, MacVersion
     1231*/
     1232
     1233/*!
     1234    \enum QSysInfo::Os2Version
     1235
     1236    This enum provides symbolic names for the various versions of the
     1237    OS/2 operating system. On OS/2, the
     1238    QSysInfo::os2Version() function gives the version of the system on
     1239    which the application is run.
     1240
     1241    Original IBM OS/2 systems:
     1242
     1243    \value OV_Unknown  An unknown and currently unsupported OS/2 version
     1244    \value OV_2_0      OS/2 2.0 (unsupported)
     1245    \value OV_2_1      OS/2 2.1 (unsupported)
     1246    \value OV_2_11     OS/2 2.11 (unsupported)
     1247    \value OV_3_0      OS/2 3.0, corresponds to Warp 3 (unsupported)
     1248    \value OV_4_0      OS/2 4.0, corresponds to Warp 4 also known as Merlin
     1249    \value OV_4_5      OS/2 4.1, corresponds to Warp 4.5 also known as Aurora
     1250    \value OV_4_52     OS/2 4.1, corresponds to Warp 4.52 also known as WSeB
     1251
     1252    \value OV_WARP3    Symbolic name for OV_3_0
     1253    \value OV_WARP4    Symbolic name for OV_4_0
     1254    \value OV_WARP45   Symbolic name for OV_4_5
     1255
     1256    \value OV_MERLIN   Codename for OV_4_0
     1257    \value OV_AURORA   Codename for OV_4_5
     1258    \value OV_WSEB     Codename for OV_4_52
     1259
     1260    Serenity eComStation systems:
     1261
     1262    \value OV_ECS_Unknown       An unknown and currently unsupported
     1263                                eComStation version
     1264    \value OV_ECS_1_0           eComStation 1.0
     1265    \value OV_ECS_1_1           eComStation 1.1
     1266    \value OV_ECS_1_2           eComStation 1.2
     1267    \value OV_ECS_2_0           eComStation 2.0 (either any of RCs or GA)
     1268
     1269    The following masks can be used for detecting properties common to a group
     1270    of versions:
     1271
     1272    \value OV_WARP3     Set if the version represents an OS/2 Warp 3 system
     1273    \value OV_WARP4     Set if the version represents an OS/2 Warp 4 system
     1274    \value OV_WARP      Set if the version is either of the OS/2 Warp systems
     1275    \value OV_ECS       Set if the version represents an eComStation system
     1276
     1277    \sa WinVersion, SymbianVersion, MacVersion
    12211278*/
    12221279
     
    18941951#endif // ifdef Q_OS_SYMBIAN
    18951952
     1953#ifdef Q_OS_OS2
     1954
     1955// Returns a version number of the component taken directly from its SYSLEVEL
     1956// file (see http://www.edm2.com/index.php/Using_SYSLEVEL_Files_in_Your_Applications
     1957// for more information about SYSLEVEL file internals)
     1958static bool getSyslevelVersion(const QByteArray &fileName, char (*version)[2])
     1959{
     1960    bool success = false;
     1961    FILE *f = fopen(fileName, "rb");
     1962    if (!f)
     1963        return success;
     1964    // go to the char d_version[2] field of the SYSLEVEL data structure
     1965    if ((success = fseek(f, 0x28, SEEK_SET) == 0)) {
     1966        // read in two bytes
     1967        success = fread(*version, 1, 2, f) == 2;
     1968    }
     1969    fclose(f);
     1970    return success;
     1971}
     1972
     1973QSysInfo::Os2Version QSysInfo::os2Version()
     1974{
     1975    static QSysInfo::Os2Version os2ver = OV_Unknown;
     1976    static bool os2VerSet = false;
     1977
     1978    if (os2VerSet)
     1979        return os2ver;
     1980    os2VerSet = true;
     1981
     1982    // detect the basic version number
     1983    ULONG buf[3];
     1984    if (DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_REVISION,
     1985                        &buf, sizeof(buf)) != NO_ERROR)
     1986        return os2ver;
     1987
     1988    if (buf[0] != 20) // QSV_VERSION_MAJOR
     1989        return os2ver;
     1990
     1991    switch (buf[1]) { // QSV_VERSION_MINOR
     1992        case 00: os2ver = OV_2_0; return os2ver;
     1993        case 10: os2ver = OV_2_1; return os2ver;
     1994        case 11: os2ver = OV_2_11; return os2ver;
     1995        case 30: os2ver = OV_3_0; return os2ver;
     1996        case 40: os2ver = OV_4_0; return os2ver;
     1997        case 45: break;
     1998        default: return os2ver;
     1999    }
     2000
     2001    if (DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
     2002                        &buf, sizeof(buf)) != NO_ERROR)
     2003        return os2ver;
     2004
     2005    // See http://ewiki.ecomstation.nl/HowToDetectVersion on how to detect
     2006    // an eComStation version
     2007
     2008    // read SYSLEVEL.OS2
     2009    QByteArray fn = QByteArray("A:\\OS2\\INSTALL\\SYSLEVEL.OS2");
     2010    fn.data()[0] += buf[0] - 1;
     2011    char sys_os2_ver[2];
     2012    if (!getSyslevelVersion(fn, &sys_os2_ver))
     2013        return os2ver;
     2014
     2015    // read SYSLEVEL.ECS
     2016    fn = QByteArray("A:\\OS2\\INSTALL\\SYSLEVEL.ECS");
     2017    fn.data()[0] += buf[0] - 1;
     2018    char sys_ecs_ver[2];
     2019    if (!getSyslevelVersion(fn, &sys_ecs_ver)) {
     2020        // no or broken SYSLEVEL.ECS, it's either eCS 1.1 or below or non-eCS
     2021        bool have_ecsreg = false;
     2022        bool have_ecsreg11 = false;
     2023        fn = QByteArray("A:\\OS2\\ECSREG.INI");
     2024        fn.data()[0] += buf[0] - 1;
     2025        have_ecsreg = access(fn, F_OK) == 0;
     2026        fn = QByteArray("A:\\OS2\\ECSREG11.INI");
     2027        fn.data()[0] += buf[0] - 1;
     2028        have_ecsreg11 = access(fn, F_OK) == 0;
     2029        // detect eCS 1.1
     2030        if (have_ecsreg && have_ecsreg11)
     2031            return os2ver = OV_ECS_1_1;
     2032        // detect eCS 1.0
     2033        if (have_ecsreg)
     2034            return os2ver = OV_ECS_1_0;
     2035        // detect WSeB (4.52)
     2036        if (sys_os2_ver[0] == 0x45 &&sys_os2_ver[1] == 0x02)
     2037            return os2ver = OV_4_52;
     2038        // fallback to Aurora (QSV_VERSION_MINOR is 45 here)
     2039        return os2ver = OV_4_5;
     2040    }
     2041
     2042    // detect eCS >= 1.2
     2043    if (sys_ecs_ver[0] == 0x12 && sys_ecs_ver[1] == 0x00)
     2044        return os2ver = OV_ECS_1_2;
     2045    if (sys_ecs_ver[0] == 0x20 && sys_ecs_ver[1] == 0x00)
     2046        return os2ver = OV_ECS_2_0;
     2047
     2048    return os2ver = OV_ECS_Unknown;
     2049}
     2050
     2051static QSysInfo::Os2Version os2verDummy = QSysInfo::os2Version();
     2052
     2053#endif // ifdef Q_OS_OS2
     2054
    18962055/*!
    18972056    \macro void Q_ASSERT(bool test)
  • trunk/src/corelib/global/qglobal.h

    r769 r797  
    15211521    static S60Version s60Version();
    15221522#endif
     1523#ifdef Q_OS_OS2
     1524    enum Os2Version {
     1525        /* OS/2 version */
     1526        OV_Unknown  = 0x00000000,
     1527        OV_2_0      = 0x00000001,
     1528        OV_2_1      = 0x00000002,
     1529        OV_2_11     = 0x00000003,
     1530        OV_3_0      = 0x01000000,
     1531        OV_4_0      = 0x02040000,
     1532        OV_4_5      = 0x02040500,
     1533        OV_4_52     = 0x02040502,
     1534
     1535        /* OS/2 codenames */
     1536        OV_MERLIN   = OV_4_0,
     1537        OV_AURORA   = OV_4_5,
     1538        OV_WSEB     = OV_4_52,
     1539
     1540        /* eComStation version */
     1541        OV_ECS_Unknown  = 0x06000000,
     1542        OV_ECS_1_0      = 0x06010000,
     1543        OV_ECS_1_1      = 0x06010100,
     1544        OV_ECS_1_2      = 0x06010200,
     1545        OV_ECS_2_0      = 0x06020000,
     1546
     1547        /* version masks */
     1548        OV_WARP3        = 0x01000000,
     1549        OV_WARP4        = 0x02000000,
     1550        OV_WARP         = OV_WARP3 | OV_WARP4,
     1551        OV_ECS          = 0x04000000,
     1552    };
     1553    static Os2Version os2Version();
     1554#endif
    15231555};
    15241556
Note: See TracChangeset for help on using the changeset viewer.