propgeneral.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /////////////////////////////////////////////////////////////////////////////
  2. // PropGeneral.cpp : implementation file
  3. //
  4. #include "stdafx.h"
  5. #include "cliconfig.h"
  6. #include "cdate.h"
  7. #include "PropGeneral.h"
  8. #include "ShowConfigDlg.h"
  9. #include "regkey.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CPropGeneral property page
  17. IMPLEMENT_DYNCREATE(CPropGeneral, CPropertyPage)
  18. CPropGeneral::CPropGeneral() : CPropertyPage(CPropGeneral::IDD)
  19. {
  20. CString strValue;
  21. HKEY hKey;
  22. if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectPlay\\Applications\\Allegiance", 0, KEY_READ, &hKey)
  23. && SUCCEEDED(LoadRegString(hKey, "CurrentDirectory", strValue)))
  24. strValue += "\\artwork";
  25. else
  26. {
  27. char szBuf[MAX_PATH];
  28. ::GetModuleFileName(NULL, szBuf, sizeof(szBuf));
  29. for (char* sz=szBuf+strlen(szBuf); (sz > szBuf) && (*sz != '\\'); sz--);
  30. *sz = '\0';
  31. strcat(szBuf, "\\artwork");
  32. strValue = szBuf;
  33. }
  34. //{{AFX_DATA_INIT(CPropGeneral)
  35. m_dateArt = CDate(99,01,01,00,00,00);
  36. m_strArtPath = strValue;
  37. m_bCaptureFrameData = FALSE;
  38. m_bCockpit = TRUE;
  39. m_bEnvironment = TRUE;
  40. m_strFrameFileName = _T("");
  41. m_bLogToFile = FALSE;
  42. m_bPosters = TRUE;
  43. m_bRoundRadar = FALSE;
  44. m_bSoftwareHUD = FALSE;
  45. m_bBiDiLighting = TRUE;
  46. m_bCenterHUD = TRUE;
  47. m_bChatHistoryHUD = TRUE;
  48. m_bDebris = TRUE;
  49. m_bLensFlare = TRUE;
  50. m_bLinearResponse = TRUE;
  51. m_bStars = TRUE;
  52. m_bStrobes = TRUE;
  53. m_bTargetHUD = TRUE;
  54. m_bTrails = TRUE;
  55. //}}AFX_DATA_INIT
  56. // m_strZoneLobby = _T("");
  57. }
  58. CPropGeneral::~CPropGeneral()
  59. {
  60. }
  61. void CPropGeneral::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CPropertyPage::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CPropGeneral)
  65. DDX_Control(pDX, IDC_CONFIG, m_comboConfig);
  66. DDX_CDate(pDX, IDC_ARTDATE, m_dateArt);
  67. DDX_Text(pDX, IDC_ARTPATH, m_strArtPath);
  68. DDX_Check(pDX, IDC_CAPTUREFRAMEDATA, m_bCaptureFrameData);
  69. DDX_Check(pDX, IDC_COCKPIT, m_bCockpit);
  70. DDX_Check(pDX, IDC_ENVIRONMENT, m_bEnvironment);
  71. DDX_Text(pDX, IDC_FRAMEFILENAME, m_strFrameFileName);
  72. DDX_Check(pDX, IDC_LOGTOFILE, m_bLogToFile);
  73. DDX_Check(pDX, IDC_POSTERS, m_bPosters);
  74. DDX_Check(pDX, IDC_ROUNDRADAR, m_bRoundRadar);
  75. DDX_Check(pDX, IDC_SOFTWAREHUD, m_bSoftwareHUD);
  76. DDX_Check(pDX, IDC_BIDILIGHTING, m_bBiDiLighting);
  77. DDX_Check(pDX, IDC_CENTERHUD, m_bCenterHUD);
  78. DDX_Check(pDX, IDC_CHATHISTORYHUD, m_bChatHistoryHUD);
  79. DDX_Check(pDX, IDC_DEBRIS, m_bDebris);
  80. DDX_Check(pDX, IDC_LENSFLARE, m_bLensFlare);
  81. DDX_Check(pDX, IDC_LINEARRESPONSE, m_bLinearResponse);
  82. DDX_Check(pDX, IDC_STARS, m_bStars);
  83. DDX_Check(pDX, IDC_STROBES, m_bStrobes);
  84. DDX_Check(pDX, IDC_TARGETHUD, m_bTargetHUD);
  85. DDX_Check(pDX, IDC_TRAILS, m_bTrails);
  86. //}}AFX_DATA_MAP
  87. // DDX_Text(pDX, IDC_ZONELOBBY, m_strZoneLobby);
  88. }
  89. BEGIN_MESSAGE_MAP(CPropGeneral, CPropertyPage)
  90. //{{AFX_MSG_MAP(CPropGeneral)
  91. ON_BN_CLICKED(IDC_VIEWBTN, OnViewbtn)
  92. //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94. static int AddIfNotThere(CComboBox& combo, LPCTSTR pszString)
  95. {
  96. int nIndex = combo.FindStringExact(-1, pszString);
  97. if (CB_ERR == nIndex)
  98. nIndex = combo.AddString(pszString);
  99. return nIndex;
  100. }
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CPropGeneral message handlers
  103. BOOL CPropGeneral::OnInitDialog()
  104. {
  105. CPropertyPage::OnInitDialog();
  106. // initialize the server MRU list
  107. for (int i=0;i<16;i++)
  108. {
  109. CString strLook, strFind;
  110. strLook.Format("MRUConfig%02d", i);
  111. strFind = AfxGetApp()->GetProfileString("MRUConfig", strLook, "");
  112. if (strFind!="")
  113. m_comboConfig.AddString(strFind);
  114. }
  115. // fill the server list with some server names if it doesn't have any yet
  116. AddIfNotThere(m_comboConfig, "http://allegiance/internal.cfg");
  117. AddIfNotThere(m_comboConfig, "http://allegiance/public.cfg");
  118. AddIfNotThere(m_comboConfig, "http://207.46.173.22/allegiance.cfg");
  119. // in case the registry keys aren't present, set the values of the fields
  120. // with default values that can't be set during construction
  121. FILETIME ft;
  122. ft.dwLowDateTime = 0;
  123. ft.dwHighDateTime = 0;
  124. // get the stuff from the registry
  125. HKEY hKey;
  126. DWORD dwType;
  127. DWORD dwValue;
  128. DWORD cbValue;
  129. if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, KEY_READ, &hKey))
  130. {
  131. CString strValue;
  132. if (SUCCEEDED(LoadRegString(hKey, "CfgFile", strValue)))
  133. {
  134. if (m_comboConfig.FindStringExact(1, strValue) == CB_ERR)
  135. m_comboConfig.AddString(strValue);
  136. m_comboConfig.SelectString(-1, strValue);
  137. }
  138. // if (SUCCEEDED(LoadRegString(hKey, "ZoneClubLobbyServer", strValue)))
  139. // m_strZoneLobby = strValue;
  140. if (SUCCEEDED(LoadRegString(hKey, "ArtPath", strValue)))
  141. m_strArtPath = strValue;
  142. cbValue = sizeof(dwValue);
  143. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "UpdateLow", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  144. ft.dwLowDateTime = dwValue;
  145. cbValue = sizeof(dwValue);
  146. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "UpdateHigh", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  147. ft.dwHighDateTime = dwValue;
  148. m_dateArt = CDate(ft);
  149. cbValue = sizeof(dwValue);
  150. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "LogFrameData", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  151. m_bCaptureFrameData = (dwValue==1) ? 1 : 0;
  152. if (SUCCEEDED(LoadRegString(hKey, "LogFrameDataPath", strValue)))
  153. m_strFrameFileName = strValue;
  154. cbValue = sizeof(dwValue);
  155. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "Cockpit", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  156. m_bCockpit = (dwValue==1) ? 1 : 0;
  157. cbValue = sizeof(dwValue);
  158. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "Environment", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  159. m_bEnvironment = (dwValue==1) ? 1 : 0;
  160. cbValue = sizeof(dwValue);
  161. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "Posters", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  162. m_bPosters = (dwValue==1) ? 1 : 0;
  163. cbValue = sizeof(dwValue);
  164. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "RoundRadar", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  165. m_bRoundRadar = (dwValue==1) ? 1 : 0;
  166. cbValue = sizeof(dwValue);
  167. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "StyleHUD", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  168. m_bSoftwareHUD = (dwValue==1) ? 1 : 0;
  169. cbValue = sizeof(dwValue);
  170. if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, "LogToFile", NULL, &dwType, (unsigned char*)&dwValue, &cbValue))
  171. m_bLogToFile = (dwValue==1) ? 1 : 0;
  172. RegCloseKey(hKey);
  173. }
  174. UpdateData(false);
  175. return TRUE; // return TRUE unless you set the focus to a control
  176. // EXCEPTION: OCX Property Pages should return FALSE
  177. }
  178. void CPropGeneral::OnOK()
  179. {
  180. UpdateData(true);
  181. HKEY hKey;
  182. DWORD dw;
  183. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dw))
  184. {
  185. DWORD dwValueOne = 1;
  186. DWORD dwValueZero = 0;
  187. // save the server setting
  188. CString strConfig;
  189. m_comboConfig.GetWindowText(strConfig);
  190. ::RegSetValueEx(hKey, "CfgFile", NULL, REG_SZ, (const unsigned char*)(const char*)strConfig, strConfig.GetLength());
  191. // save the configs in the MRU list--just don't want to add one twice
  192. if (m_comboConfig.FindStringExact(1, strConfig)==-1)
  193. m_comboConfig.AddString(strConfig);
  194. for (int i=0;i<16 && i<m_comboConfig.GetCount();i++)
  195. {
  196. CString strEntry;
  197. strEntry.Format("MRUConfig%02d", i);
  198. m_comboConfig.GetLBText(i, strConfig);
  199. ::RegSetValueEx(hKey, strEntry, NULL, REG_SZ, (const unsigned char*)(const char*)strConfig, strConfig.GetLength());
  200. }
  201. // ::RegSetValueEx(hKey, "ZoneClubLobbyServer", NULL, REG_SZ, (const unsigned char*)(const char*)m_strZoneLobby, m_strZoneLobby.GetLength());
  202. ::RegSetValueEx(hKey, "ArtPath", NULL, REG_SZ, (const unsigned char*)(const char*)m_strArtPath, m_strArtPath.GetLength());
  203. FILETIME ft;
  204. m_dateArt.GetFiletime(&ft);
  205. ::RegSetValueEx(hKey, "UpdateLow", NULL, REG_DWORD, (const unsigned char*)&ft.dwLowDateTime, sizeof(ft.dwLowDateTime));
  206. ::RegSetValueEx(hKey, "UpdateHigh", NULL, REG_DWORD, (const unsigned char*)&ft.dwHighDateTime, sizeof(ft.dwHighDateTime));
  207. ::RegSetValueEx(hKey, "LogFrameData", NULL, REG_DWORD,
  208. (const unsigned char*)(m_bCaptureFrameData ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  209. ::RegSetValueEx(hKey, "LogFrameDataPath", NULL, REG_SZ, (const unsigned char*)(const char*)m_strFrameFileName, m_strFrameFileName.GetLength());
  210. ::RegSetValueEx(hKey, "Cockpit", NULL, REG_DWORD,
  211. (const unsigned char*)(m_bCockpit ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  212. ::RegSetValueEx(hKey, "Environment", NULL, REG_DWORD,
  213. (const unsigned char*)(m_bEnvironment ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  214. ::RegSetValueEx(hKey, "Posters", NULL, REG_DWORD,
  215. (const unsigned char*)(m_bPosters ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  216. ::RegSetValueEx(hKey, "RoundRadar", NULL, REG_DWORD,
  217. (const unsigned char*)(m_bRoundRadar ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  218. ::RegSetValueEx(hKey, "StyleHUD", NULL, REG_DWORD,
  219. (const unsigned char*)(m_bSoftwareHUD ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  220. ::RegSetValueEx(hKey, "LogToFile", NULL, REG_DWORD,
  221. (const unsigned char*)(m_bLogToFile ? &dwValueOne : &dwValueZero), sizeof(DWORD));
  222. ::RegCloseKey(hKey);
  223. }
  224. CPropertyPage::OnOK();
  225. }
  226. void CPropGeneral::OnViewbtn()
  227. {
  228. CString strURL;
  229. GetDlgItemText(IDC_CONFIG, strURL);
  230. // Ensure that we have an absolute URL
  231. USES_CONVERSION;
  232. if (S_FALSE == IsValidURL(NULL, T2CW(strURL), 0))
  233. {
  234. MessageBox("The value specified is not a valid URL.", "Unable to Display", MB_OK);
  235. return;
  236. }
  237. // Open the specified script file
  238. IStream* spstm;
  239. HRESULT hr = URLOpenBlockingStream(NULL, strURL, &spstm, 0, NULL);
  240. if (FAILED(hr))
  241. {
  242. MessageBox("Unable to open the specified config file, or it doesn't exist.", "Unable to Display", MB_OK);
  243. return;
  244. }
  245. // Get the size of the stream
  246. const LARGE_INTEGER nPosZero = {0, 0};
  247. ULARGE_INTEGER cbFileLarge;
  248. spstm->Seek(nPosZero, STREAM_SEEK_END, &cbFileLarge);
  249. //Assert(0 == cbFileLarge.HighPart);
  250. DWORD cbFile = cbFileLarge.LowPart;
  251. spstm->Seek(nPosZero, STREAM_SEEK_SET, NULL);
  252. CShowConfigDlg dlg;
  253. LPTSTR szBuffer = dlg.m_strContents.GetBufferSetLength(cbFile);
  254. hr = spstm->Read(szBuffer, cbFile, NULL);
  255. dlg.DoModal();
  256. }