WOLProduct.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. ** Command & Conquer Renegade(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. *
  20. * FILE
  21. * $Archive: /Commando/Code/WWOnline/WOLProduct.cpp $
  22. *
  23. * DESCRIPTION
  24. * This class specifies product-specific information, such as SKU.
  25. *
  26. * Client code should create a Product::Initializer object. This will create
  27. * a Product object and set it as the current product. Creating additional
  28. * Initializer objects will replace the current product information. This
  29. * will change the application's "identity" on the fly; this may cause
  30. * problems if Westwood Online activity is in progress. I don't expect there
  31. * to be any need to do this, except perhaps during early product development.
  32. *
  33. * PROGRAMMER
  34. * $Author: Denzil_l $
  35. *
  36. * VERSION INFO
  37. * $Revision: 4 $
  38. * $Modtime: 1/25/02 6:45p $
  39. *
  40. ******************************************************************************/
  41. #include "WOLProduct.h"
  42. #include <WWLib\win.h>
  43. namespace WWOnline {
  44. /******************************************************************************
  45. *
  46. * NAME
  47. * CurrentProduct
  48. *
  49. * DESCRIPTION
  50. * Current WWOnline product.
  51. *
  52. * INPUTS
  53. * NONE
  54. *
  55. * RESULT
  56. * Product -
  57. *
  58. ******************************************************************************/
  59. static RefPtr<Product>& CurrentProduct(void)
  60. {
  61. static RefPtr<Product> _current;
  62. return _current;
  63. }
  64. /******************************************************************************
  65. *
  66. * NAME
  67. * Product::Current
  68. *
  69. * DESCRIPTION
  70. * Get the current WWOnline product
  71. *
  72. * INPUTS
  73. * NONE
  74. *
  75. * RESULT
  76. *
  77. ******************************************************************************/
  78. RefPtr<Product> Product::Current(void)
  79. {
  80. return CurrentProduct().ReferencedObject();
  81. }
  82. /******************************************************************************
  83. *
  84. * NAME
  85. * Product::Create
  86. *
  87. * DESCRIPTION
  88. *
  89. * INPUTS
  90. *
  91. * RESULT
  92. *
  93. ******************************************************************************/
  94. RefPtr<Product> Product::Create(const char* registryPath, int gameCode,
  95. const wchar_t* chanPass, unsigned long ladderSKU)
  96. {
  97. return new Product(registryPath, gameCode, chanPass, ladderSKU);
  98. }
  99. /******************************************************************************
  100. *
  101. * NAME
  102. * Product::Product
  103. *
  104. * DESCRIPTION
  105. *
  106. * INPUTS
  107. *
  108. * RESULT
  109. *
  110. ******************************************************************************/
  111. Product::Product(const char* registryPath, int gameCode, const wchar_t* chanPass, unsigned long ladderSKU) :
  112. mRegistryPath(registryPath),
  113. mProductSKU(0),
  114. mLadderSKU(0),
  115. mProductVersion(0),
  116. mLanguageCode(0),
  117. mGameCode(gameCode),
  118. mChannelPassword(chanPass)
  119. {
  120. WWASSERT(registryPath && "Invalid parameter");
  121. HKEY rKey;
  122. LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryPath, 0, KEY_READ, &rKey);
  123. if (result == ERROR_SUCCESS)
  124. {
  125. // Get SKU
  126. DWORD type;
  127. DWORD sku = 0;
  128. DWORD sizeOfBuffer = sizeof(sku);
  129. result = RegQueryValueEx(rKey, "SKU", NULL, &type, (unsigned char*)&sku, &sizeOfBuffer);
  130. mProductSKU = sku;
  131. mLanguageCode = (sku & 0xFF);
  132. mLadderSKU = ladderSKU;
  133. // Get version
  134. DWORD version = 0;
  135. sizeOfBuffer = sizeof(version);
  136. result = RegQueryValueEx(rKey, "Version", NULL, &type, (unsigned char*)&version, &sizeOfBuffer);
  137. mProductVersion = version;
  138. RegCloseKey(rKey);
  139. }
  140. }
  141. /******************************************************************************
  142. *
  143. * NAME
  144. * WOLProduct::Initializer
  145. *
  146. * DESCRIPTION
  147. *
  148. * INPUTS
  149. *
  150. * RESULT
  151. *
  152. ******************************************************************************/
  153. Product::Initializer::Initializer(const char* registryPath, int gameCode,
  154. const wchar_t* chanPass, unsigned long ladderSKU)
  155. {
  156. CurrentProduct() = Product::Create(registryPath, gameCode, chanPass, ladderSKU);
  157. }
  158. /******************************************************************************
  159. *
  160. * NAME
  161. * WOLProduct::Initializer
  162. *
  163. * DESCRIPTION
  164. *
  165. * INPUTS
  166. *
  167. * RESULT
  168. *
  169. ******************************************************************************/
  170. Product::Initializer::~Initializer()
  171. {
  172. }
  173. }