WinFix.CPP 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Renegade Setup/Autorun/WinFix.CPP $*
  25. * *
  26. * $Author:: Maria_l $*
  27. * *
  28. * $Modtime:: 11/15/01 10:44a $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * Make_Identifier -- Creates a temporary string identifer. *
  35. * WindowsVersionInfo::WindowsVersionInfo -- Windows Version Info constructor. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #define STRICT
  38. #include <windows.h>
  39. #include <windowsx.h>
  40. #pragma hdrstop
  41. //#include <commctrl.h>
  42. //#include <winuser.h>
  43. #include <assert.h>
  44. #include <stdio.h>
  45. #include "winfix.h"
  46. #include "wnd_file.h"
  47. /***************************************************************************
  48. ** Windows Version Info global object.
  49. */
  50. WindowsVersionInfo WinVersion;
  51. /***********************************************************************************************
  52. * WindowsVersionInfo::WindowsVersionInfo -- Windows Version Info constructor. *
  53. * *
  54. * This routine will examine the system to determine the OS, version, and patch level of *
  55. * the current OS. *
  56. * *
  57. * INPUT: none *
  58. * *
  59. * OUTPUT: none *
  60. * *
  61. * WARNINGS: Don't try and use this class until after WinMain, because it won't be *
  62. * initialized until all the global objects have been constructed. *
  63. * *
  64. * HISTORY: *
  65. * 04/09/98 jdl : Created. *
  66. *=============================================================================================*/
  67. WindowsVersionInfo::WindowsVersionInfo(void) :
  68. WindowsVersion(0),
  69. MajorVersionNumber(0),
  70. MinorVersionNumber(0),
  71. RunningOSR2(0),
  72. BuildNumber(0),
  73. IsWin9x(false),
  74. IsWin95(false),
  75. IsWin98(false),
  76. IsWin2000(false),
  77. IsWinNT(false),
  78. IsWinXP(false)
  79. {
  80. OSVERSIONINFO version_info;
  81. VersionName[0] = '\0';
  82. AdditionalInfo[0] = '\0';
  83. //--------------------------------------------------------------------------
  84. // Start recording messages.
  85. //--------------------------------------------------------------------------
  86. Delete_Msg_File();
  87. Msg( __LINE__, __FILE__, "----------------------------------------------", NULL );
  88. Msg( __LINE__, __FILE__, "------------------ Setup -----------------", NULL );
  89. Msg( __LINE__, __FILE__, "----------------------------------------------", NULL );
  90. //--------------------------------------------------------------------------
  91. // Get the version info from the OS.
  92. //
  93. // typedef struct _OSVERSIONINFO{
  94. // DWORD dwOSVersionInfoSize;
  95. // DWORD dwMajorVersion;
  96. // DWORD dwMinorVersion;
  97. // DWORD dwBuildNumber;
  98. // DWORD dwPlatformId;
  99. // TCHAR szCSDVersion[ 128 ];
  100. // } OSVERSIONINFO;
  101. //
  102. // typedef struct _OSVERSIONINFOEX {
  103. // DWORD dwOSVersionInfoSize;
  104. // DWORD dwMajorVersion;
  105. // DWORD dwMinorVersion;
  106. // DWORD dwBuildNumber;
  107. // DWORD dwPlatformId;
  108. // TCHAR szCSDVersion[ 128 ];
  109. // WORD wServicePackMajor;
  110. // WORD wServicePackMinor;
  111. // WORD wSuiteMask;
  112. // BYTE wProductType;
  113. // BYTE wReserved;
  114. // } OSVERSIONINFOEX, *POSVERSIONINFOEX, *LPOSVERSIONINFOEX;
  115. //--------------------------------------------------------------------------
  116. ZeroMemory( &version_info, sizeof( version_info ));
  117. version_info.dwOSVersionInfoSize = sizeof( version_info );
  118. int result = GetVersionEx( &version_info );
  119. assert( result != 0 );
  120. //--------------------------------------------------------------------------
  121. // Save the major/minor version numbers
  122. //--------------------------------------------------------------------------
  123. MajorVersionNumber = (int)version_info.dwMajorVersion;
  124. MinorVersionNumber = (int)version_info.dwMinorVersion;
  125. WindowsVersion = ( MajorVersionNumber * 100 ) + MinorVersionNumber;
  126. //--------------------------------------------------------------------------
  127. // Save the build number
  128. //--------------------------------------------------------------------------
  129. BuildNumber = (int)version_info.dwBuildNumber;
  130. //--------------------------------------------------------------------------
  131. // Check for Win9x
  132. //--------------------------------------------------------------------------
  133. if ( version_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) {
  134. IsWin9x = true;
  135. if ( MajorVersionNumber == 4 && MinorVersionNumber == 0 ) {
  136. IsWin95 = true;
  137. }
  138. if (( MajorVersionNumber > 4 ) || (( MajorVersionNumber == 4 ) && ( MinorVersionNumber > 0 ))) {
  139. IsWin98 = true;
  140. }
  141. if ( LOWORD( version_info.dwPlatformId ) > 1000 ) {
  142. RunningOSR2 = TRUE;
  143. }
  144. }
  145. //--------------------------------------------------------------------------
  146. // Check for WinNT
  147. //--------------------------------------------------------------------------
  148. if ( version_info.dwPlatformId == VER_PLATFORM_WIN32_NT ) {
  149. IsWinNT = true;
  150. if (( MajorVersionNumber >= 5 ) && ( MinorVersionNumber >= 1 )) {
  151. IsWinXP = true;
  152. // if ( version_info.wSuiteMask == VER_SUITE_PERSONAL ) {
  153. // }
  154. } else if (( MajorVersionNumber == 5 ) && ( MinorVersionNumber == 0 )) {
  155. IsWin2000 = true;
  156. }
  157. // if( bOsVersionInfoEx )
  158. // {
  159. // if ( osvi.wProductType == VER_NT_WORKSTATION )
  160. // printf ( "Professional " );
  161. //
  162. // if ( osvi.wProductType == VER_NT_SERVER )
  163. // printf ( "Server " );
  164. // } else {
  165. #if( _DEBUG )
  166. HKEY hKey;
  167. char szProductType[80];
  168. DWORD dwBufLen;
  169. RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey );
  170. RegQueryValueEx( hKey, "ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
  171. RegCloseKey( hKey );
  172. if ( lstrcmpi( "WINNT", szProductType) == 0 )
  173. Msg( __LINE__, __FILE__, "WinNT Workstation." );
  174. if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
  175. Msg( __LINE__, __FILE__, "WinNT Server." );
  176. #endif
  177. // }
  178. }
  179. #ifdef DEV_VERSION
  180. //--------------------------------------------------------------------------
  181. // For developmental versions, just use the major & minor version #'s
  182. //--------------------------------------------------------------------------
  183. sprintf( VersionName, "%x.%x", MajorVersionNumber, MinorVersionNumber );
  184. #else
  185. //--------------------------------------------------------------------------
  186. // For final versions, trim 0's off the minor version
  187. //--------------------------------------------------------------------------
  188. unsigned short adjusted_minor;
  189. int i;
  190. adjusted_minor = MinorVersionNumber;
  191. for (i = 0; i < 4; i++) {
  192. if ((adjusted_minor & 0x000f) != 0) {
  193. break;
  194. }
  195. adjusted_minor >>= 4;
  196. }
  197. sprintf( VersionName, "%x.%x", MajorVersionNumber, adjusted_minor );
  198. #endif
  199. //--------------------------------------------------------------------------
  200. // Save off the additional version information string
  201. // (used to indicated additional info or patch level, i.e. for NT 4.0 SP3
  202. // it would contain the string 'Service Pack 3')
  203. //--------------------------------------------------------------------------
  204. strncpy( AdditionalInfo, version_info.szCSDVersion, sizeof(AdditionalInfo) - 1 );
  205. AdditionalInfo[sizeof(AdditionalInfo) - 1] = '\x0';
  206. //--------------------------------------------------------------------------
  207. // Send all info found to the debug output file.
  208. //--------------------------------------------------------------------------
  209. #if ( _DEBUG )
  210. Msg( __LINE__, __FILE__, "MajorVersionNumber = %d", MajorVersionNumber );
  211. Msg( __LINE__, __FILE__, "MinorVersionNumber = %d", MinorVersionNumber );
  212. Msg( __LINE__, __FILE__, "WindowsVersion = %d", WindowsVersion );
  213. Msg( __LINE__, __FILE__, "BuildNumber = %d", BuildNumber );
  214. Msg( __LINE__, __FILE__, "IsWin9x = %d", IsWin9x );
  215. Msg( __LINE__, __FILE__, "IsWin95 = %d", IsWin95 );
  216. Msg( __LINE__, __FILE__, "IsWin98 = %d", IsWin98 );
  217. Msg( __LINE__, __FILE__, "IsWin2000 = %d", IsWin2000 );
  218. Msg( __LINE__, __FILE__, "RunningOSR2 = %d", RunningOSR2 );
  219. Msg( __LINE__, __FILE__, "IsWinNT = %d", IsWinNT );
  220. Msg( __LINE__, __FILE__, "AdditionalInfo = %s", AdditionalInfo );
  221. Msg( __LINE__, __FILE__, "VersionName = %s", VersionName );
  222. #endif
  223. }
  224. /***********************************************************************************************
  225. * WindowsVersionInfo::Version_String -- Get the version number in human readable form *
  226. * *
  227. * INPUT: Nothing *
  228. * *
  229. * OUTPUT: Ptr to string containing version info *
  230. * *
  231. * WARNINGS: None *
  232. * *
  233. * HISTORY: *
  234. * 3/30/99 10:29PM ST : Created *
  235. *=============================================================================================*/
  236. char *WindowsVersionInfo::Version_String(void)
  237. {
  238. static char _ver95[] = {"Windows 95 "};
  239. static char _ver98[] = {"Windows 98 "};
  240. static char _verNT4[] = {"Windows NT 4 "};
  241. static char _verNT5[] = {"Windows 2000 "};
  242. static char _verXP[] = {"Windows XP "};
  243. static char _unknown[] = {"Unknown "};
  244. static char version[256];
  245. if (Is_Win95()) {
  246. strcpy (version, _ver95);
  247. }
  248. if (Is_Win98()) {
  249. strcpy (version, _ver98);
  250. }
  251. if (Is_WinNT()) {
  252. strcpy (version, _verNT4);
  253. }
  254. if (Is_WinNT5() || Is_Win_2000()) {
  255. strcpy (version, _verNT5);
  256. }
  257. if (Is_Win_XP()) {
  258. strcpy (version, _verXP);
  259. }
  260. strcat (version, AdditionalInfo);
  261. return (version);
  262. }
  263. /***************************************************************************
  264. * WindowsVersionClass::Version_Name -- returns version # as char string *
  265. * *
  266. * INPUT: *
  267. * none. *
  268. * *
  269. * OUTPUT: *
  270. * ptr to name *
  271. * *
  272. * WARNINGS: *
  273. * none. *
  274. * *
  275. * HISTORY: *
  276. * 10/30/1995 BRR : Created. *
  277. *=========================================================================*/
  278. char * WindowsVersionInfo::Version_Name(void)
  279. {
  280. return ( VersionName );
  281. }
  282. /****************************************************************************
  283. * WindowsVersionClass::Meets_Minimum_Version_Requirements *
  284. * *
  285. * INPUT: *
  286. * none. *
  287. * *
  288. * OUTPUT: *
  289. * ptr to name *
  290. * *
  291. * WARNINGS: *
  292. * none. *
  293. * *
  294. * HISTORY: *
  295. * 10/30/1995 BRR : Created. *
  296. *==========================================================================*/
  297. bool WindowsVersionInfo::Meets_Minimum_Version_Requirements ( void )
  298. {
  299. // return(( !IsWin95 && ( Version() >= 400 ))? true : false );
  300. return(( Version() >= 400 )? true : false );
  301. }