File: fxosver.cpp

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (190 lines) | stat: -rw-r--r-- 6,732 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/********************************************************************************
*                                                                               *
*                O p e r a t i n g   S y s t e m   V e r s i o n                *
*                                                                               *
*********************************************************************************
* Copyright (C) 2022 by Jeroen van der Zijp.   All Rights Reserved.             *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"


/*
  Notes:
*/


using namespace FX;

/*******************************************************************************/

namespace FX {

extern FXAPI FXint __snprintf(FXchar* string,FXint length,const FXchar* format,...);

#if defined(WIN32)

// RtlGetVersion grabs the version information use it because
// GetVersionEx is now deprecated.
typedef LONG (WINAPI *PFN_RTLGETVERSION)(OSVERSIONINFOEXW*);

// Declare the stub function
static LONG WINAPI RtlGetVersionStub(OSVERSIONINFOEXW* osv);

// Pointer to RtlGetVersion, initially pointing to the stub function
static PFN_RTLGETVERSION fxRtlGetVersion=RtlGetVersionStub;

// Low-level routine to grab OS version
static LONG WINAPI RtlGetVersionStub(OSVERSIONINFOEXW* osv){
  if(fxRtlGetVersion==RtlGetVersionStub){
    HMODULE ntdllDll=GetModuleHandleA("ntdll.dll");
    FXASSERT(ntdllDll);
    fxRtlGetVersion=(PFN_RTLGETVERSION)GetProcAddress(ntdllDll,"RtlGetVersion");
    FXASSERT(fxRtlGetVersion);
    }
  return fxRtlGetVersion(osv);
  }


// Get operating system version string
FXival fxosversion(FXchar version[],FXival len){
  if(0<len){
    OSVERSIONINFOEXW osv;
    osv.dwOSVersionInfoSize=sizeof(osv);
    if(fxRtlGetVersion(&osv)==0){
      FXTRACE((100,"fxosversion: dwMajorVersion=%d\n",osv.dwMajorVersion));
      FXTRACE((100,"fxosversion: dwMinorVersion=%d\n",osv.dwMinorVersion));
      FXTRACE((100,"fxosversion: dwBuildNumber=%d\n",osv.dwBuildNumber));
      FXTRACE((100,"fxosversion: dwPlatformId=%d\n",osv.dwPlatformId));
      FXTRACE((100,"fxosversion: wServicePackMajor=%d\n",osv.wServicePackMajor));
      FXTRACE((100,"fxosversion: wServicePackMinor=%d\n",osv.wServicePackMinor));
      FXTRACE((100,"fxosversion: wSuiteMask=%d\n",osv.wSuiteMask));
      FXTRACE((100,"fxosversion: wProductType=%d\n",osv.wProductType));
      return __snprintf(version,len,"%d.%d.%d.%d",osv.dwMajorVersion,osv.dwMinorVersion,osv.dwBuildNumber,osv.dwPlatformId);
      }
    version[0]='\0';
    }
  return 0;
  }


#if 0

FXival fxosversion(FXchar version[],FXival len){
  if(0<len){
    TCHAR filename[MAXPATHLEN];
    DWORD n=GetSystemDirectoryW(filename,MAXPATHLEN);
    if(0<n){
      DWORD handle;
      wcscpy(filename+n,L"\\kernel32.dll");
      if(GetFileVersionInfoSizeW(filename,&handle)){
        VS_FIXEDFILEINFO ffi;
        if(GetFileVersionInfoW(filename,handle,size,data)){



VERSIONHELPERAPI IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor){
  OSVERSIONINFOEXW osvi;
  DWORDLONG dwlConditionMask = VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0,VER_MAJORVERSION,VER_GREATER_EQUAL),VER_MINORVERSION,VER_GREATER_EQUAL),VER_SERVICEPACKMAJOR,VER_GREATER_EQUAL);
  osvi.dwOSVersionInfoSize=sizeof(osvi);
  osvi.dwMajorVersion=wMajorVersion;
  osvi.dwMinorVersion=wMinorVersion;
  osvi.wServicePackMajor=wServicePackMajor;
  return VerifyVersionInfoW(&osvi,VER_MAJORVERSION|VER_MINORVERSION|VER_SERVICEPACKMAJOR,dwlConditionMask)!=FALSE;
  }





bool GetOSVersionString(WCHAR* version,size_t maxlen){
  WCHAR path[_MAX_PATH]={};

  if(!GetSystemDirectoryW(path,_MAX_PATH)) return false;

  wcscat_s( path, L"\\kernel32.dll" );

  //
  // Based on example code from this article
  // http://support.microsoft.com/kb/167597
  //

  DWORD handle;
#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
  DWORD len=GetFileVersionInfoSizeExW(FILE_VER_GET_NEUTRAL,path,&handle);
#else
  DWORD len=GetFileVersionInfoSizeW(path,&handle);
#endif
  if(!len) return false;

  std::unique_ptr<uint8_t> buff( new (std::nothrow) uint8_t[ len ] );

  if(!buff) return false;

#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
  if(!GetFileVersionInfoExW(FILE_VER_GET_NEUTRAL,path,0,len,buff.get() ) ) return false;
#else
  if(!GetFileVersionInfoW( path, 0, len, buff.get() ) ) return false;
#endif

  VS_FIXEDFILEINFO *vInfo=nullptr;
  UINT infoSize;

  if(!VerQueryValueW(buff.get(),L"\\",reinterpret_cast<LPVOID*>(&vInfo),&infoSize)) return false;

  if(!infoSize) return false;

  swprintf_s( version, maxlen, L"%u.%u.%u.%u",HIWORD( vInfo->dwFileVersionMS ),LOWORD(vInfo->dwFileVersionMS),HIWORD(vInfo->dwFileVersionLS),LOWORD(vInfo->dwFileVersionLS) );

  return true;
  }

#endif

#elif defined(HAVE_UNAME)

// Get operating system version string
FXival fxosversion(FXchar version[],FXival len){   // FIXME will change
  if(0<len){
    struct utsname buffer;
    if(uname(&buffer)==0){
      FXTRACE((100,"fxosversion: sysname=%s\n",buffer.sysname));
      FXTRACE((100,"fxosversion: nodename=%s\n",buffer.nodename));
      FXTRACE((100,"fxosversion: release=%s\n",buffer.release));
      FXTRACE((100,"fxosversion: version=%s\n",buffer.version));
      return fxstrlcpy(version,buffer.release,len);
      }
    //return __snprintf(version,len,"%d.%d.%d",LINUX_VERSION_MAJOR,LINUX_VERSION_PATCHLEVEL,LINUX_VERSION_SUBLEVEL);
    version[0]='\0';
    }
  return 0;
  }

#else

// Get operating system version string
FXival fxosversion(FXchar version[],FXival len){
  if(0<len){
    version[0]='\0';
    }
  return 0;
  }

#endif

}