DlgChatPreferences.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /////////////////////////////////////////////////////////////////////////////
  2. // DlgChatPreferences.cpp : implementation file
  3. //
  4. #include "stdafx.h"
  5. #include "AllSrvUI.h"
  6. #include "PageChat.h"
  7. #include "DlgChatPreferences.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDlgChatPreferences dialog
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Message Map
  17. BEGIN_MESSAGE_MAP(CDlgChatPreferences, CDialog)
  18. //{{AFX_MSG_MAP(CDlgChatPreferences)
  19. ON_BN_CLICKED(IDC_ENABLE_CHAT_LIST, OnEnableChatList)
  20. ON_BN_CLICKED(IDC_UNLIMITED_CHAT_HISTORY, OnUnlimitedChatHistory)
  21. ON_BN_CLICKED(IDC_LIMIT_CHAT_HISTORY, OnLimitChatHistory)
  22. ON_BN_CLICKED(IDC_ADMIN_RUN, OnAdminRun)
  23. ON_BN_CLICKED(IDC_ADMIN_RUN_PROPERTIES, OnAdminRunProperties)
  24. ON_BN_CLICKED(IDC_ADMIN_RUN_TEST, OnAdminRunTest)
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Construction
  29. CDlgChatPreferences::CDlgChatPreferences(CPageChat* pPage)
  30. : CDialog(CDlgChatPreferences::IDD, pPage),
  31. m_pPage(pPage)
  32. {
  33. //{{AFX_DATA_INIT(CDlgChatPreferences)
  34. m_bAdminChatList = FALSE;
  35. m_bAdminMessageBox = FALSE;
  36. m_bAdminRun = FALSE;
  37. m_bEnableChatList = FALSE;
  38. m_eChatListLimit = -1;
  39. m_dwChatListLimit = 0;
  40. //}}AFX_DATA_INIT
  41. // Get the module filepath
  42. TCHAR szModule[_MAX_PATH];
  43. GetModuleFileName(NULL, szModule, sizeofArray(szModule));
  44. TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR];
  45. _tsplitpath(szModule, szDrive, szDir, NULL, NULL);
  46. _tmakepath(szModule, szDrive, szDir, TEXT("AdminAlert"), TEXT(".lnk"));
  47. m_strShortcutPath = szModule;
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // Overrides
  51. void CDlgChatPreferences::DoDataExchange(CDataExchange* pDX)
  52. {
  53. // Perform default processing
  54. CDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CDlgChatPreferences)
  56. DDX_Control(pDX, IDC_ADMIN_RUN_PROPERTIES, m_btnAdminRunProperties);
  57. DDX_Control(pDX, IDC_UNLIMITED_CHAT_HISTORY, m_btnUnlimitedChat);
  58. DDX_Control(pDX, IDC_LIMIT_CHAT_HISTORY, m_btnLimitChat);
  59. DDX_Control(pDX, IDC_CHAT_HISTORY_LIMIT, m_editChatListLimit);
  60. DDX_Control(pDX, IDC_LIMIT_POST_CAPTION, m_staticChatListLimit);
  61. DDX_Check(pDX, IDC_ADMIN_CHAT_LIST, m_bAdminChatList);
  62. DDX_Check(pDX, IDC_ADMIN_MSGBOX, m_bAdminMessageBox);
  63. DDX_Check(pDX, IDC_ADMIN_RUN, m_bAdminRun);
  64. DDX_Check(pDX, IDC_ENABLE_CHAT_LIST, m_bEnableChatList);
  65. DDX_Radio(pDX, IDC_UNLIMITED_CHAT_HISTORY, m_eChatListLimit);
  66. DDX_Text(pDX, IDC_CHAT_HISTORY_LIMIT, m_dwChatListLimit);
  67. //}}AFX_DATA_MAP
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Implementation
  71. void CDlgChatPreferences::LoadFromRegistry()
  72. {
  73. // Open/create the registry key
  74. CRegKey key;
  75. key.Create(HKEY_LOCAL_MACHINE, HKLM_AllSrvUI);
  76. // AdminAlertChatList
  77. DWORD dwBool = true;
  78. key.QueryValue(dwBool, TEXT("AdminAlertChatList"));
  79. m_bAdminChatList = !!dwBool;
  80. // AdminAlertMessageBox
  81. dwBool = true;
  82. key.QueryValue(dwBool, TEXT("AdminAlertMessageBox"));
  83. m_bAdminMessageBox = !!dwBool;
  84. // AdminAlertRun
  85. dwBool = false;
  86. if (ShortcutExists())
  87. key.QueryValue(dwBool, TEXT("AdminAlertRun"));
  88. m_bAdminRun = !!dwBool;
  89. // ChatList
  90. dwBool = true;
  91. key.QueryValue(dwBool, TEXT("ChatList"));
  92. m_bEnableChatList = !!dwBool;
  93. // ChatListLimit
  94. key.QueryValue(m_dwChatListLimit, TEXT("ChatListLimit"));
  95. }
  96. void CDlgChatPreferences::SaveToRegistry()
  97. {
  98. // Open/create the registry key
  99. CRegKey key;
  100. key.Create(HKEY_LOCAL_MACHINE, HKLM_AllSrvUI);
  101. // AdminAlertChatList
  102. key.SetValue(m_bAdminChatList, TEXT("AdminAlertChatList"));
  103. // AdminAlertMessageBox
  104. key.SetValue(m_bAdminMessageBox, TEXT("AdminAlertMessageBox"));
  105. // AdminAlertRun
  106. key.SetValue(m_bAdminRun, TEXT("AdminAlertRun"));
  107. // ChatList
  108. key.SetValue(m_bEnableChatList, TEXT("ChatList"));
  109. // ChatListLimit
  110. key.SetValue(m_dwChatListLimit, TEXT("ChatListLimit"));
  111. }
  112. bool CDlgChatPreferences::ShortcutExists()
  113. {
  114. // Open the file for read-only access
  115. UINT uModeOld = ::SetErrorMode(SEM_NOOPENFILEERRORBOX);
  116. TCHandle shFile = ::CreateFile(m_strShortcutPath, GENERIC_READ,
  117. FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  118. ::SetErrorMode(uModeOld);
  119. return (INVALID_HANDLE_VALUE == shFile) ? (shFile.Detach(), false) : true;
  120. }
  121. void CDlgChatPreferences::UpdateUI()
  122. {
  123. m_btnUnlimitedChat.EnableWindow(m_bEnableChatList);
  124. m_btnLimitChat.EnableWindow(m_bEnableChatList);
  125. m_editChatListLimit.EnableWindow(m_bEnableChatList && m_eChatListLimit);
  126. m_staticChatListLimit.EnableWindow(m_bEnableChatList && m_eChatListLimit);
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. // Message Handlers
  130. BOOL CDlgChatPreferences::OnInitDialog()
  131. {
  132. // Perform default processing
  133. CDialog::OnInitDialog();
  134. // Select the ChatListLimit radio button
  135. m_eChatListLimit = (0 == m_dwChatListLimit) ? 0 : 1;
  136. // Update the UI
  137. UpdateUI();
  138. // Update fields from data members
  139. UpdateData(false);
  140. // Return true to set the focus to the first tabstop control
  141. return true;
  142. }
  143. void CDlgChatPreferences::OnOK()
  144. {
  145. // Perform default processing
  146. CDialog::OnOK();
  147. // Set m_dwChatListLimit appropriately
  148. if (0 == m_eChatListLimit)
  149. m_dwChatListLimit = 0;
  150. // Can't run a shortcut if it doesn't exist
  151. if (!ShortcutExists())
  152. m_bAdminRun = false;
  153. // Save values to the registry
  154. SaveToRegistry();
  155. }
  156. void CDlgChatPreferences::OnEnableChatList()
  157. {
  158. // Update data members from fields
  159. UpdateData();
  160. // Update the UI
  161. UpdateUI();
  162. }
  163. void CDlgChatPreferences::OnUnlimitedChatHistory()
  164. {
  165. // Update data members from fields
  166. UpdateData();
  167. // Update the UI
  168. UpdateUI();
  169. }
  170. void CDlgChatPreferences::OnLimitChatHistory()
  171. {
  172. // Update data members from fields
  173. UpdateData();
  174. // Update the UI
  175. UpdateUI();
  176. }
  177. void CDlgChatPreferences::OnAdminRun()
  178. {
  179. // Create the shortcut and set properties if it does not exist
  180. if (!ShortcutExists())
  181. OnAdminRunProperties();
  182. }
  183. void CDlgChatPreferences::OnAdminRunProperties()
  184. {
  185. // Create the shortcut if it does not exist
  186. if (!ShortcutExists())
  187. {
  188. IShellLinkPtr spShellLink;
  189. HRESULT hr = spShellLink.CreateInstance(CLSID_ShellLink);
  190. if (SUCCEEDED(hr))
  191. {
  192. USES_CONVERSION;
  193. IPersistFilePtr spPersistFile(spShellLink);
  194. if (NULL != spPersistFile)
  195. hr = spPersistFile->Save(T2COLE(m_strShortcutPath), true);
  196. }
  197. }
  198. // Display the shortcut properties
  199. SHELLEXECUTEINFO shei = {sizeof(shei)};
  200. shei.fMask = SEE_MASK_NOCLOSEPROCESS;
  201. shei.lpVerb = TEXT("properties");
  202. shei.lpFile = m_strShortcutPath;
  203. shei.nShow = SW_SHOWNORMAL;
  204. bool bExecuted = !!::ShellExecuteEx(&shei);
  205. }
  206. void CDlgChatPreferences::OnAdminRunTest()
  207. {
  208. IAGCEventCreatePtr spEventCreate;
  209. HRESULT hr = spEventCreate.CreateInstance(__uuidof(AGCEvent));
  210. if (SUCCEEDED(hr))
  211. {
  212. spEventCreate->Init();
  213. spEventCreate->put_SubjectName(CComBSTR(L"HelplessNewbie"));
  214. spEventCreate->put_ID(EventID_AdminPage);
  215. spEventCreate->AddProperty(CComBSTR(L"Message"),
  216. &CComVariant(L"Test message from Chat Preferences."));
  217. spEventCreate->AddProperty(CComBSTR(L"Target"),
  218. &CComVariant(L"ADMIN"));
  219. spEventCreate->AddProperty(CComBSTR(L"GameID"),
  220. &CComVariant(L"TEST"));
  221. // Save the current AdminAlert options
  222. bool bAdminChatList = !!m_bAdminChatList;
  223. bool bAdminMessageBox = !!m_bAdminMessageBox;
  224. bool bAdminRun = !!m_bAdminRun;
  225. // Update the current values to test
  226. UpdateData();
  227. // Fire the test event
  228. IAGCEventPtr spEvent(spEventCreate);
  229. m_pPage->OnEvent(spEvent);
  230. // Restore the previous AdminAlert options
  231. m_bAdminChatList = bAdminChatList;
  232. m_bAdminMessageBox = bAdminMessageBox;
  233. m_bAdminRun = bAdminRun;
  234. }
  235. }