IGR.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // IGR.cpp - A class used to access the IGR registry settings.
  20. //
  21. // JeffB 7/5/00
  22. //
  23. #include <assert.h>
  24. #include <windows.h>
  25. #include <winreg.h>
  26. //#include "always.h"
  27. #include "IGR.h"
  28. IGROptionsClass *OnlineOptions = NULL;
  29. /*********************************************************************************************
  30. * IGROptions::Init -- Class initializer. Reads from the registry *
  31. * *
  32. * INPUT: None *
  33. * *
  34. * OUTPUT: bool; Did we read everything OK? *
  35. * *
  36. * WARNINGS: none *
  37. * *
  38. * HISTORY: *
  39. * 07/05/00 JeffB: Initial coding *
  40. *===========================================================================================*/
  41. bool IGROptionsClass::Init( void )
  42. {
  43. int size;
  44. int returnValue;
  45. HKEY handle;
  46. char key[128];
  47. unsigned long type;
  48. valid = false;
  49. // Load the options from the registry
  50. size = sizeof( int );
  51. // Setup the key
  52. strcpy( key, WOLAPI_REG_KEY_BOTTOM );
  53. // Get a handle to the WOLAPI entry
  54. if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS, &handle ) == ERROR_SUCCESS ) {
  55. // If successful, get the options
  56. IGROptionsType ReadOptions = 0;
  57. returnValue = RegQueryValueEx(handle, WOLAPI_REG_KEY_OPTIONS, NULL,
  58. (unsigned long *) &type, (unsigned char *) &ReadOptions, (unsigned long *)&size);
  59. if (returnValue == ERROR_SUCCESS) {
  60. // If successful, and we got a DWORD, store options and set the valid flage
  61. if (type == REG_DWORD) {
  62. options = ReadOptions;
  63. valid = true;
  64. }
  65. }
  66. // Clean up
  67. RegCloseKey( handle );
  68. }
  69. return ( valid );
  70. }
  71. /***********************************************************************************************
  72. * IGROptions::Is_Auto_Login_Allowed -- Set the passed options in the registry *
  73. * *
  74. * INPUT: None *
  75. * *
  76. * OUTPUT: bool; Is the option set *
  77. * *
  78. * WARNINGS: none *
  79. * *
  80. * HISTORY: *
  81. * 07/05/00 JeffB: Initial coding *
  82. *=============================================================================================*/
  83. bool IGROptionsClass::Is_Auto_Login_Allowed( void )
  84. {
  85. return(( options & IGR_NO_AUTO_LOGIN ) == 0 );
  86. }
  87. /***********************************************************************************************
  88. * IGROptions::Is_Storing_Nicks_Allowed -- Set the passed options in the registry *
  89. * *
  90. * INPUT: None *
  91. * *
  92. * OUTPUT: bool; Is the option set *
  93. * *
  94. * WARNINGS: none *
  95. * *
  96. * HISTORY: *
  97. * 07/05/00 JeffB: Initial coding *
  98. *=============================================================================================*/
  99. bool IGROptionsClass::Is_Storing_Nicks_Allowed( void )
  100. {
  101. return(( options & IGR_NEVER_STORE_NICKS ) == 0 );
  102. }
  103. /***********************************************************************************************
  104. * IGROptions::Is_Running_Reg_App_Allowed -- Set the passed options in the registry *
  105. * *
  106. * INPUT: None *
  107. * *
  108. * OUTPUT: bool; Is the option set *
  109. * *
  110. * WARNINGS: none *
  111. * *
  112. * HISTORY: *
  113. * 07/05/00 JeffB: Initial coding *
  114. *=============================================================================================*/
  115. bool IGROptionsClass::Is_Running_Reg_App_Allowed( void )
  116. {
  117. return(( options & IGR_NEVER_RUN_REG_APP ) == 0 );
  118. }
  119. /*********************************************************************************************
  120. * IGROptions::Set_Options -- Set the passed options in the registry *
  121. * *
  122. * INPUT: Options to set *
  123. * *
  124. * OUTPUT: bool; Did we set the options successfully *
  125. * *
  126. * WARNINGS: none *
  127. * *
  128. * HISTORY: *
  129. * 07/05/00 JeffB: Initial coding *
  130. *===========================================================================================*/
  131. bool IGROptionsClass::Set_Options( IGROptionsType options )
  132. {
  133. bool ReturnValue = false;
  134. HKEY handle;
  135. int disp;
  136. char key[ 128 ];
  137. // We don't care if it's valid, we'll MAKE it valid.
  138. strcpy( key, WOLAPI_REG_KEY_BOTTOM );
  139. // Do they have the WOLAPI key?
  140. if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_ALL_ACCESS, &handle ) != ERROR_SUCCESS ) {
  141. // If not, make the WOLAPI key
  142. if( RegCreateKeyEx( HKEY_LOCAL_MACHINE, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
  143. NULL, &handle, (unsigned long *)&disp ) != ERROR_SUCCESS )
  144. return false;
  145. }
  146. if( RegSetValueEx( handle, WOLAPI_REG_KEY_OPTIONS, 0, REG_DWORD, (unsigned char *)&options, sizeof(int))
  147. == ERROR_SUCCESS ) {
  148. ReturnValue = true;
  149. }
  150. RegCloseKey( handle );
  151. // Reinit the class to make sure we have these settings for later queries.
  152. Init();
  153. assert( valid == TRUE );
  154. return ReturnValue;
  155. }