Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1552 lines
44 KiB

  1. // Connect.cpp : Implementation of CConnect
  2. #include "precomp.h"
  3. #include "AddIn.h"
  4. #include "Connect.h"
  5. #include "addin_i.c"
  6. #include "testsettingsctrl.h"
  7. #include "avrfutil.h"
  8. #include <assert.h>
  9. using namespace ShimLib;
  10. // Globals needed by AppVerifier
  11. wstring g_strAppName;
  12. BOOL gp_bConsoleMode;
  13. BOOL gp_bWin2KMode;
  14. BOOL g_bBreakOnLog;
  15. BOOL g_bFullPageHeap;
  16. BOOL g_bPropagateTests;
  17. extern BOOL CheckWindowsVersion(void);
  18. //
  19. // Holds the name of the active EXE.
  20. //
  21. wstring g_wstrExeName;
  22. //
  23. // Indicates if it's okay to run.
  24. //
  25. BOOL g_bCorrectOSVersion = FALSE;
  26. #define AV_OPTION_BREAK_ON_LOG L"BreakOnLog"
  27. #define AV_OPTION_FULL_PAGEHEAP L"FullPageHeap"
  28. #define AV_OPTION_AV_DEBUGGER L"UseAVDebugger"
  29. #define AV_OPTION_DEBUGGER L"Debugger"
  30. #define AV_OPTION_PROPAGATE L"PropagateTests"
  31. void
  32. pReadOptions(
  33. void
  34. )
  35. {
  36. for (CAVAppInfo *pApp = g_aAppInfo.begin(); pApp != g_aAppInfo.end(); ++pApp) {
  37. LPCWSTR szExe = pApp->wstrExeName.c_str();
  38. static const DWORD MAX_DEBUGGER_LEN = 1024;
  39. WCHAR szDebugger[MAX_DEBUGGER_LEN];
  40. g_bBreakOnLog = pApp->bBreakOnLog = GetShimSettingDWORD(L"General", szExe, AV_OPTION_BREAK_ON_LOG, FALSE);
  41. g_bFullPageHeap = pApp->bFullPageHeap = GetShimSettingDWORD(L"General", szExe, AV_OPTION_FULL_PAGEHEAP, FALSE);
  42. pApp->bUseAVDebugger = TRUE;
  43. g_bPropagateTests = pApp->bPropagateTests = GetShimSettingDWORD(L"General", szExe, AV_OPTION_PROPAGATE, FALSE);
  44. pApp->wstrDebugger = L"";
  45. }
  46. }
  47. HPALETTE CreateDIBPalette(
  48. LPBITMAPINFO lpbmi,
  49. LPINT lpiNumColors
  50. )
  51. {
  52. LPBITMAPINFOHEADER lpbi;
  53. LPLOGPALETTE lpPal;
  54. HANDLE hLogPal;
  55. HPALETTE hPal = NULL;
  56. int i;
  57. lpbi = (LPBITMAPINFOHEADER)lpbmi;
  58. if (lpbi->biBitCount <= 8)
  59. *lpiNumColors = (1 << lpbi->biBitCount);
  60. else
  61. *lpiNumColors = 0; // No palette needed for 24 BPP DIB
  62. if (lpbi->biClrUsed > 0)
  63. *lpiNumColors = lpbi->biClrUsed; // Use biClrUsed
  64. if (*lpiNumColors)
  65. {
  66. hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) + sizeof (PALETTEENTRY) * (*lpiNumColors));
  67. lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);
  68. lpPal->palVersion = 0x300;
  69. lpPal->palNumEntries = (WORD)*lpiNumColors;
  70. for (i = 0; i < *lpiNumColors; i++)
  71. {
  72. lpPal->palPalEntry[i].peRed = lpbmi->bmiColors[i].rgbRed;
  73. lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
  74. lpPal->palPalEntry[i].peBlue = lpbmi->bmiColors[i].rgbBlue;
  75. lpPal->palPalEntry[i].peFlags = 0;
  76. }
  77. hPal = CreatePalette (lpPal);
  78. GlobalUnlock (hLogPal);
  79. GlobalFree (hLogPal);
  80. }
  81. return hPal;
  82. }
  83. HBITMAP LoadResourceBitmap(
  84. HINSTANCE hInstance,
  85. TCHAR* pszString,
  86. HPALETTE FAR* lphPalette
  87. )
  88. {
  89. HGLOBAL hGlobal;
  90. HBITMAP hBitmapFinal = NULL;
  91. LPBITMAPINFOHEADER lpbi;
  92. HDC hdc;
  93. int iNumColors;
  94. HRSRC hRsrc = FindResource(hInstance, pszString, RT_BITMAP);
  95. if (hRsrc)
  96. {
  97. hGlobal = LoadResource(hInstance, hRsrc);
  98. lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);
  99. hdc = GetDC(NULL);
  100. *lphPalette = CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
  101. if (*lphPalette)
  102. {
  103. SelectPalette(hdc,*lphPalette,FALSE);
  104. RealizePalette(hdc);
  105. }
  106. hBitmapFinal = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi, (LONG)CBM_INIT, (LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD), (LPBITMAPINFO)lpbi, DIB_RGB_COLORS );
  107. ReleaseDC(NULL,hdc);
  108. UnlockResource(hGlobal);
  109. FreeResource(hGlobal);
  110. }
  111. return (hBitmapFinal);
  112. }
  113. CComPtr<IPictureDisp>GetPicture(PTSTR szResource)
  114. {
  115. CComPtr<IPictureDisp> picture;
  116. PICTDESC pictDesc;
  117. pictDesc.cbSizeofstruct=sizeof(PICTDESC);
  118. pictDesc.picType=PICTYPE_BITMAP;
  119. pictDesc.bmp.hbitmap = LoadResourceBitmap(_Module.GetResourceInstance(), szResource, &pictDesc.bmp.hpal);
  120. OleCreatePictureIndirect(&pictDesc, IID_IPictureDisp, TRUE, (void**)(static_cast<IPictureDisp**>(&picture)));
  121. return picture;
  122. }
  123. // Called when the add-in is loaded into the environment.
  124. STDMETHODIMP
  125. CConnect::OnConnection(
  126. IDispatch *pApplication,
  127. AddInDesignerObjects::ext_ConnectMode ConnectMode,
  128. IDispatch *pAddInInst,
  129. SAFEARRAY ** custom
  130. )
  131. {
  132. HRESULT hr;
  133. INITCOMMONCONTROLSEX icc;
  134. // Initialize AppVerifier settings
  135. g_strAppName = L"";
  136. gp_bConsoleMode = FALSE;
  137. gp_bWin2KMode = FALSE;
  138. g_bBreakOnLog = FALSE;
  139. g_bFullPageHeap = FALSE;
  140. g_bPropagateTests = FALSE;
  141. try {
  142. if (CheckWindowsVersion()) {
  143. g_bCorrectOSVersion = TRUE;
  144. //
  145. // Add our tests to the listview.
  146. //
  147. InitTestInfo();
  148. //
  149. // Load the common control library and set up the link
  150. // window class.
  151. //
  152. icc.dwSize = sizeof(icc);
  153. icc.dwICC = ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES;
  154. InitCommonControlsEx(&icc);
  155. LinkWindow_RegisterClass();
  156. //
  157. // Get the development environment instance and our add-in instance.
  158. //
  159. hr = pApplication->QueryInterface(__uuidof(EnvDTE::_DTE),
  160. (LPVOID*)&m_pDTE);
  161. if (FAILED(hr)) {
  162. return hr;
  163. }
  164. hr = pAddInInst->QueryInterface(__uuidof(EnvDTE::AddIn),
  165. (LPVOID*)&m_pAddInInstance);
  166. if (FAILED(hr)) {
  167. return hr;
  168. }
  169. //
  170. // OnStartupComplete contains actual connection code.
  171. //
  172. if (ConnectMode != AddInDesignerObjects::ext_cm_Startup) {
  173. return OnStartupComplete(custom);
  174. }
  175. }
  176. } // try
  177. catch(HRESULT err) {
  178. hr = err;
  179. }
  180. return hr;
  181. }
  182. //
  183. // Called when the add-in is unloaded from the environment.
  184. //
  185. STDMETHODIMP
  186. CConnect::OnDisconnection(
  187. AddInDesignerObjects::ext_DisconnectMode /*RemoveMode*/,
  188. SAFEARRAY ** /*custom*/ )
  189. {
  190. m_pDTE.Release();
  191. m_pAddInInstance.Release();
  192. m_pEnableControl.Release();
  193. m_pTestsControl.Release();
  194. m_pOptionControl.Release();
  195. m_pLogViewControl.Release();
  196. return S_OK;
  197. }
  198. //
  199. // Called when there is a change to the add-in's loaded into the environment.
  200. //
  201. STDMETHODIMP
  202. CConnect::OnAddInsUpdate(
  203. SAFEARRAY ** /*custom*/ )
  204. {
  205. //
  206. // We don't care about these changes.
  207. //
  208. return S_OK;
  209. }
  210. STDMETHODIMP
  211. CConnect::OnStartupComplete(
  212. SAFEARRAY ** /*custom*/
  213. )
  214. /*++
  215. Return: S_OK on success, or an HRESULT on failure.
  216. Desc: This is called when the environment has finished
  217. loading or by OnConnection() in other instances.
  218. This is where we add our buttons to the Debug
  219. toolbar and such.
  220. --*/
  221. {
  222. HRESULT hr = E_FAIL;
  223. CComPtr<EnvDTE::Commands> pCommands;
  224. CComPtr<Office::_CommandBars> pCommandBars;
  225. CComPtr<Office::CommandBar> pDebugBar;
  226. CComPtr<EnvDTE::Command> pOptionsCmd;
  227. CComPtr<EnvDTE::Command> pTestsCmd;
  228. CComPtr<EnvDTE::Command> pEnableCmd;
  229. CComPtr<EnvDTE::Command> pLogViewCmd;
  230. CComPtr<EnvDTE::Events> pEventSet;
  231. CComPtr<EnvDTE::_DTEEvents> pDTEEvents;
  232. CComPtr<EnvDTE::_SolutionEvents> pSolutionEvents;
  233. WCHAR wszCommandId[64];
  234. WCHAR wszCommandText[64];
  235. WCHAR wszCommandTooltip[64];
  236. m_solutionEventsSink.m_pParent = this;
  237. m_dteEventsSink.m_pParent = this;
  238. //
  239. // Read settings in from SDB and registry.
  240. //
  241. if (g_bCorrectOSVersion) {
  242. GetCurrentAppSettings();
  243. pReadOptions();
  244. }
  245. try {
  246. //
  247. // Get the main menu bars.
  248. //
  249. hr = m_pDTE->get_CommandBars(&pCommandBars);
  250. if (FAILED(hr)) {
  251. throw hr;
  252. }
  253. hr = m_pDTE->get_Commands(&pCommands);
  254. if (FAILED(hr)) {
  255. throw hr;
  256. }
  257. //
  258. // Delete existing named commands and menus.
  259. //
  260. hr = pCommands->Item(CComVariant(L"AppVerifier.Connect.Enable"),
  261. 0,
  262. &pEnableCmd);
  263. if (SUCCEEDED(hr)) {
  264. pEnableCmd->Delete();
  265. pEnableCmd.Release();
  266. }
  267. hr = pCommands->Item(CComVariant(L"AppVerifier.Connect.Tests"),
  268. 0,
  269. &pTestsCmd);
  270. if (SUCCEEDED(hr)) {
  271. pTestsCmd->Delete();
  272. pTestsCmd.Release();
  273. }
  274. hr = pCommands->Item(CComVariant(L"AppVerifier.Connect.Options"),
  275. 0,
  276. &pOptionsCmd);
  277. if (SUCCEEDED(hr)) {
  278. pOptionsCmd->Delete();
  279. pOptionsCmd.Release();
  280. }
  281. hr = pCommands->Item(CComVariant(L"AppVerifier.Connect.ViewLog"),
  282. 0,
  283. &pLogViewCmd);
  284. if (SUCCEEDED(hr)) {
  285. pLogViewCmd->Delete();
  286. pLogViewCmd.Release();
  287. }
  288. //
  289. // Get the 'Debug' toolbar.
  290. //
  291. hr = pCommandBars->get_Item(CComVariant(L"Debug"), &pDebugBar);
  292. if (FAILED(hr)) {
  293. throw hr;
  294. }
  295. //
  296. // Create the commands. These will show as buttons on the 'Debug'
  297. // toolbar.
  298. //
  299. LoadString(g_hInstance,
  300. IDS_TB_VERIFICATION_CMD_ID,
  301. wszCommandId,
  302. ARRAYSIZE(wszCommandId));
  303. LoadString(g_hInstance,
  304. IDS_TB_VERIFICATION_CMD_TEXT,
  305. wszCommandText,
  306. ARRAYSIZE(wszCommandText));
  307. LoadString(g_hInstance,
  308. IDS_TB_VERIFICATION_CMD_TOOLTIP,
  309. wszCommandTooltip,
  310. ARRAYSIZE(wszCommandTooltip));
  311. //
  312. // First one is 'Verification Off'.
  313. //
  314. hr = pCommands->AddNamedCommand(
  315. m_pAddInInstance,
  316. CComBSTR(wszCommandId),
  317. CComBSTR(wszCommandText),
  318. CComBSTR(wszCommandTooltip),
  319. VARIANT_TRUE,
  320. 0,
  321. NULL,
  322. EnvDTE::vsCommandStatusSupported|EnvDTE::vsCommandStatusEnabled,
  323. &pEnableCmd);
  324. //
  325. // Add the bitmap for this button including the mask associated
  326. // with it.
  327. //
  328. if (SUCCEEDED(hr)) {
  329. hr = pEnableCmd->AddControl(pDebugBar, 1, &m_pEnableControl);
  330. if (FAILED(hr)) {
  331. throw hr;
  332. }
  333. CComQIPtr<Office::_CommandBarButton,
  334. &_uuidof(Office::_CommandBarButton)>pButton(m_pEnableControl);
  335. CComPtr<IPictureDisp>picture = GetPicture(MAKEINTRESOURCE(IDB_ENABLED));
  336. if (pButton && picture) {
  337. pButton->put_Picture(picture);
  338. CComPtr<IPictureDisp>pictureMask = GetPicture(MAKEINTRESOURCE(IDB_ENABLED_MASK));
  339. if (pictureMask) {
  340. pButton->put_Mask(pictureMask);
  341. }
  342. }
  343. }
  344. //
  345. // Second one is 'Tests'.
  346. //
  347. LoadString(g_hInstance,
  348. IDS_TB_TESTS_CMD_ID,
  349. wszCommandId,
  350. ARRAYSIZE(wszCommandId));
  351. LoadString(g_hInstance,
  352. IDS_TB_TESTS_CMD_TEXT,
  353. wszCommandText,
  354. ARRAYSIZE(wszCommandText));
  355. LoadString(g_hInstance,
  356. IDS_TB_TESTS_CMD_TOOLTIP,
  357. wszCommandTooltip,
  358. ARRAYSIZE(wszCommandTooltip));
  359. hr = pCommands->AddNamedCommand(
  360. m_pAddInInstance,
  361. CComBSTR(wszCommandId),
  362. CComBSTR(wszCommandText),
  363. CComBSTR(wszCommandTooltip),
  364. VARIANT_FALSE,
  365. IDB_TESTSETTINGS_BTN,
  366. NULL,
  367. EnvDTE::vsCommandStatusSupported|EnvDTE::vsCommandStatusEnabled,
  368. &pTestsCmd);
  369. if (SUCCEEDED(hr)) {
  370. //
  371. // Add a button to the app verifier menu.
  372. //
  373. hr = pTestsCmd->AddControl(pDebugBar, 2, &m_pTestsControl);
  374. if (FAILED(hr)) {
  375. throw hr;
  376. }
  377. }
  378. //
  379. // Third one is 'Options'.
  380. //
  381. LoadString(g_hInstance,
  382. IDS_TB_OPTIONS_CMD_ID,
  383. wszCommandId,
  384. ARRAYSIZE(wszCommandId));
  385. LoadString(g_hInstance,
  386. IDS_TB_OPTIONS_CMD_TEXT,
  387. wszCommandText,
  388. ARRAYSIZE(wszCommandText));
  389. LoadString(g_hInstance,
  390. IDS_TB_OPTIONS_CMD_TOOLTIP,
  391. wszCommandTooltip,
  392. ARRAYSIZE(wszCommandTooltip));
  393. hr = pCommands->AddNamedCommand(
  394. m_pAddInInstance,
  395. CComBSTR(wszCommandId),
  396. CComBSTR(wszCommandText),
  397. CComBSTR(wszCommandTooltip),
  398. VARIANT_FALSE,
  399. IDB_OPTIONS_BTN,
  400. NULL,
  401. EnvDTE::vsCommandStatusSupported|EnvDTE::vsCommandStatusEnabled,
  402. &pOptionsCmd);
  403. if (SUCCEEDED(hr)) {
  404. //
  405. // Add a button to the app verifier menu.
  406. //
  407. hr = pOptionsCmd->AddControl(pDebugBar, 3, &m_pOptionControl);
  408. if (FAILED(hr)) {
  409. throw hr;
  410. }
  411. }
  412. //
  413. // Fourth one is 'View Log.'
  414. //
  415. LoadString(g_hInstance,
  416. IDS_TB_VIEWLOG_CMD_ID,
  417. wszCommandId,
  418. ARRAYSIZE(wszCommandId));
  419. LoadString(g_hInstance,
  420. IDS_TB_VIEWLOG_CMD_TEXT,
  421. wszCommandText,
  422. ARRAYSIZE(wszCommandText));
  423. LoadString(g_hInstance,
  424. IDS_TB_VIEWLOG_CMD_TOOLTIP,
  425. wszCommandTooltip,
  426. ARRAYSIZE(wszCommandTooltip));
  427. hr = pCommands->AddNamedCommand(
  428. m_pAddInInstance,
  429. CComBSTR(wszCommandId),
  430. CComBSTR(wszCommandText),
  431. CComBSTR(wszCommandTooltip),
  432. VARIANT_FALSE,
  433. IDB_VIEWLOG_BTN,
  434. NULL,
  435. EnvDTE::vsCommandStatusSupported|EnvDTE::vsCommandStatusEnabled,
  436. &pLogViewCmd);
  437. if (SUCCEEDED(hr)) {
  438. //
  439. // Add a button to the app verifier menu.
  440. //
  441. hr = pLogViewCmd->AddControl(pDebugBar, 4, &m_pLogViewControl);
  442. if (FAILED(hr)) {
  443. throw hr;
  444. }
  445. }
  446. //
  447. // Hookup to environment events.
  448. //
  449. hr = m_pDTE->get_Events(&pEventSet);
  450. if (FAILED(hr)) {
  451. throw hr;
  452. }
  453. hr = pEventSet->get_DTEEvents(&pDTEEvents);
  454. if (FAILED(hr)) {
  455. throw hr;
  456. }
  457. hr = m_dteEventsSink.DispEventAdvise((IUnknown*)pDTEEvents.p);
  458. if (FAILED(hr)) {
  459. throw hr;
  460. }
  461. hr = pEventSet->get_SolutionEvents(&pSolutionEvents);
  462. if (FAILED(hr)) {
  463. throw hr;
  464. }
  465. hr = m_solutionEventsSink.DispEventAdvise((IUnknown*)pSolutionEvents.p);
  466. if (FAILED(hr)) {
  467. throw hr;
  468. }
  469. //
  470. // Setup for current solution.
  471. //
  472. m_solutionEventsSink.Opened();
  473. } // try
  474. catch(HRESULT err) {
  475. hr = err;
  476. }
  477. catch(...) {
  478. hr = E_FAIL;
  479. }
  480. return hr;
  481. }
  482. //
  483. // Called when the environment starts to shutdown.
  484. //
  485. STDMETHODIMP
  486. CConnect::OnBeginShutdown(
  487. SAFEARRAY ** /*custom*/ )
  488. {
  489. return S_OK;
  490. }
  491. //
  492. // Called when the status of a command is queried.
  493. //
  494. STDMETHODIMP
  495. CConnect::QueryStatus(
  496. BSTR bstrCmdName,
  497. EnvDTE::vsCommandStatusTextWanted NeededText,
  498. EnvDTE::vsCommandStatus *pStatusOption,
  499. VARIANT * /*pvarCommandText*/)
  500. {
  501. if (NeededText == EnvDTE::vsCommandStatusTextWantedNone) {
  502. if ((_wcsicmp(bstrCmdName, L"AppVerifier.Connect.Tests")==0) ||
  503. (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.Options")==0)) {
  504. if (m_bEnabled) {
  505. *pStatusOption = (EnvDTE::vsCommandStatus)
  506. (EnvDTE::vsCommandStatusEnabled | EnvDTE::vsCommandStatusSupported);
  507. } else {
  508. *pStatusOption = (EnvDTE::vsCommandStatus)
  509. (EnvDTE::vsCommandStatusEnabled | EnvDTE::vsCommandStatusSupported);
  510. }
  511. }
  512. else if (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.ViewLog")==0) {
  513. *pStatusOption = (EnvDTE::vsCommandStatus)
  514. (EnvDTE::vsCommandStatusEnabled | EnvDTE::vsCommandStatusSupported);
  515. }
  516. else if (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.Enable")==0) {
  517. *pStatusOption = (EnvDTE::vsCommandStatus)
  518. (EnvDTE::vsCommandStatusEnabled | EnvDTE::vsCommandStatusSupported);
  519. }
  520. }
  521. return S_OK;
  522. }
  523. BOOL
  524. CALLBACK
  525. CConnect::DlgViewOptions(
  526. HWND hDlg,
  527. UINT message,
  528. WPARAM wParam,
  529. LPARAM lParam
  530. )
  531. {
  532. switch (message) {
  533. case WM_INITDIALOG:
  534. if (g_bBreakOnLog) {
  535. CheckDlgButton(hDlg, IDC_BREAK_ON_LOG, BST_CHECKED);
  536. }
  537. if (g_bFullPageHeap) {
  538. CheckDlgButton(hDlg, IDC_FULL_PAGEHEAP, BST_CHECKED);
  539. }
  540. if (g_bPropagateTests) {
  541. CheckDlgButton(hDlg, IDC_PROPAGATE_TESTS_TO_CHILDREN, BST_CHECKED);
  542. }
  543. return TRUE;
  544. case WM_NOTIFY:
  545. switch (((NMHDR FAR *)lParam)->code) {
  546. case PSN_APPLY:
  547. g_bBreakOnLog = FALSE;
  548. g_bFullPageHeap = FALSE;
  549. g_bPropagateTests = FALSE;
  550. //
  551. // Determine which options the user has enabled.
  552. //
  553. if (IsDlgButtonChecked(hDlg, IDC_BREAK_ON_LOG) == BST_CHECKED) {
  554. g_bBreakOnLog = TRUE;
  555. }
  556. if (IsDlgButtonChecked(hDlg, IDC_FULL_PAGEHEAP) == BST_CHECKED) {
  557. g_bFullPageHeap = TRUE;
  558. }
  559. if (IsDlgButtonChecked(hDlg, IDC_PROPAGATE_TESTS_TO_CHILDREN) == BST_CHECKED) {
  560. g_bPropagateTests = TRUE;
  561. }
  562. ::SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  563. break;
  564. case PSN_QUERYCANCEL:
  565. return FALSE;
  566. }
  567. }
  568. return FALSE;
  569. }
  570. void
  571. CConnect::CreatePropertySheet(
  572. HWND hWndParent
  573. )
  574. {
  575. CTestInfo* pTest;
  576. DWORD dwPages = 1;
  577. DWORD dwPage = 0;
  578. WCHAR wszTitle[MAX_PATH];
  579. LPCWSTR szExe = g_wstrExeName.c_str();
  580. //
  581. // count the number of pages
  582. //
  583. for (pTest = g_aTestInfo.begin(); pTest != g_aTestInfo.end(); pTest++) {
  584. if (pTest->PropSheetPage.pfnDlgProc) {
  585. dwPages++;
  586. }
  587. }
  588. m_phPages = new HPROPSHEETPAGE[dwPages];
  589. if (!m_phPages) {
  590. return;
  591. }
  592. //
  593. // init the global page
  594. //
  595. m_PageGlobal.dwSize = sizeof(PROPSHEETPAGE);
  596. m_PageGlobal.dwFlags = PSP_USETITLE;
  597. m_PageGlobal.hInstance = g_hInstance;
  598. m_PageGlobal.pszTemplate = MAKEINTRESOURCE(IDD_AV_OPTIONS);
  599. m_PageGlobal.pfnDlgProc = DlgViewOptions;
  600. m_PageGlobal.pszTitle = MAKEINTRESOURCE(IDS_GLOBAL_OPTIONS);
  601. m_PageGlobal.lParam = 0;
  602. m_PageGlobal.pfnCallback = NULL;
  603. m_phPages[0] = CreatePropertySheetPage(&m_PageGlobal);
  604. if (!m_phPages[0]) {
  605. //
  606. // we need the global page minimum
  607. //
  608. return;
  609. }
  610. //
  611. // add the pages for the various tests
  612. //
  613. dwPage = 1;
  614. for (pTest = g_aTestInfo.begin(); pTest != g_aTestInfo.end(); pTest++) {
  615. if (pTest->PropSheetPage.pfnDlgProc) {
  616. //
  617. // we use the lParam to identify the exe involved
  618. //
  619. pTest->PropSheetPage.lParam = (LPARAM)szExe;
  620. m_phPages[dwPage] = CreatePropertySheetPage(&(pTest->PropSheetPage));
  621. if (!m_phPages[dwPage]) {
  622. dwPages--;
  623. } else {
  624. dwPage++;
  625. }
  626. }
  627. }
  628. LoadString(g_hInstance,
  629. IDS_OPTIONS_TITLE,
  630. wszTitle,
  631. ARRAYSIZE(wszTitle));
  632. wstring wstrOptions = wszTitle;
  633. wstrOptions += L" - ";
  634. wstrOptions += szExe;
  635. m_psh.dwSize = sizeof(PROPSHEETHEADER);
  636. m_psh.dwFlags = PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP;
  637. m_psh.hwndParent = hWndParent;
  638. m_psh.hInstance = g_hInstance;
  639. m_psh.pszCaption = wstrOptions.c_str();
  640. m_psh.nPages = dwPages;
  641. m_psh.nStartPage = 0;
  642. m_psh.phpage = m_phPages;
  643. m_psh.pfnCallback = NULL;
  644. PropertySheet(&m_psh);
  645. }
  646. //
  647. // Called to execute a command.
  648. //
  649. STDMETHODIMP
  650. CConnect::Exec(
  651. BSTR bstrCmdName,
  652. EnvDTE::vsCommandExecOption ExecuteOption,
  653. VARIANT * /*pvarVariantIn*/,
  654. VARIANT * /*pvarVariantOut*/,
  655. VARIANT_BOOL *pvbHandled
  656. )
  657. {
  658. HRESULT hr;
  659. CComPtr<IDispatch> pObject;
  660. *pvbHandled = VARIANT_FALSE;
  661. if (ExecuteOption == EnvDTE::vsCommandExecOptionDoDefault) {
  662. *pvbHandled = VARIANT_TRUE;
  663. if (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.Tests")==0) {
  664. CreateToolWindow(CLSID_TestSettingsCtrl);
  665. }
  666. else if (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.Options")==0) {
  667. //CreateToolWindow(CLSID_AVOptions);
  668. CreatePropertySheet(NULL);
  669. }
  670. else if (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.ViewLog")==0) {
  671. CreateToolWindow(CLSID_LogViewer);
  672. }
  673. else if (_wcsicmp(bstrCmdName, L"AppVerifier.Connect.Enable")==0) {
  674. m_bEnabled = !m_bEnabled;
  675. CComQIPtr<Office::_CommandBarButton,
  676. &_uuidof(Office::_CommandBarButton)>pButton(m_pEnableControl);
  677. if (m_bEnabled) {
  678. SetEnabledUI();
  679. } else {
  680. SetDisabledUI();
  681. }
  682. GetCurrentAppSettings();
  683. CConnect::SetCurrentAppSettings();
  684. } else {
  685. *pvbHandled = VARIANT_FALSE;
  686. }
  687. }
  688. return S_OK;
  689. }
  690. CComPtr<EnvDTE::Window>CConnect::GetToolWindow(
  691. CLSID clsid
  692. )
  693. {
  694. HRESULT hr;
  695. CComPtr<EnvDTE::Windows>pWindows;
  696. CComPtr<EnvDTE::Window>pToolWindow;
  697. CComBSTR guidPosition;
  698. hr = m_pDTE->get_Windows(&pWindows);
  699. if (FAILED(hr)) {
  700. return NULL;
  701. }
  702. if(clsid == CLSID_LogViewer) {
  703. guidPosition = L"{D39B1B7A-EFF3-42ae-8F2B-8EEE78154187}";
  704. }
  705. else if (clsid == CLSID_TestSettingsCtrl) {
  706. guidPosition = L"{71CD7261-A72E-4a93-AB5F-3EBCFDEAE842}";
  707. }
  708. else if (clsid == CLSID_AVOptions) {
  709. guidPosition = L"{dc878f00-ac86-4813-8ca9-384fa07cefbf}";
  710. } else {
  711. return NULL;
  712. }
  713. hr = pWindows->Item(CComVariant(guidPosition), &pToolWindow);
  714. if (SUCCEEDED(hr)) {
  715. return pToolWindow;
  716. } else {
  717. return NULL;
  718. }
  719. }
  720. void
  721. CConnect::CreateToolWindow(
  722. const CLSID& clsid
  723. )
  724. {
  725. HRESULT hr;
  726. CComBSTR progID;
  727. CComBSTR caption;
  728. CComBSTR guidPosition;
  729. long lMinWidth, lMinHeight;
  730. long lWidth, lHeight;
  731. BOOL bCreated = FALSE;
  732. CComPtr<IDispatch>pObject;
  733. CComPtr<EnvDTE::Windows>pWindows;
  734. CComPtr<EnvDTE::Window>pToolWindow;
  735. //
  736. // Bail if verifier is enabled, except for logviewer.
  737. //
  738. if (m_bEnabled && clsid != CLSID_LogViewer) {
  739. return;
  740. }
  741. //
  742. // Check if window has been already created.
  743. //
  744. pToolWindow = GetToolWindow(clsid);
  745. if (pToolWindow == NULL) {
  746. bCreated = TRUE;
  747. CComPtr<IPictureDisp> picture;
  748. if(clsid == CLSID_LogViewer) {
  749. progID = L"AppVerifier.LogViewer.1";
  750. caption = L"AppVerifier Log";
  751. guidPosition = L"{D39B1B7A-EFF3-42ae-8F2B-8EEE78154187}";
  752. lMinWidth = 600;
  753. lMinHeight = 400;
  754. picture = GetPicture(MAKEINTRESOURCE(IDB_VIEWLOG));
  755. }
  756. else if (clsid == CLSID_TestSettingsCtrl) {
  757. progID = L"AppVerifier.TestSettingsCtrl.1";
  758. caption = L"AppVerifier Test Settings";
  759. guidPosition = L"{71CD7261-A72E-4a93-AB5F-3EBCFDEAE842}";
  760. lMinWidth = 600;
  761. lMinHeight = 400;
  762. picture = GetPicture(MAKEINTRESOURCE(IDB_TESTSETTINGS));
  763. }
  764. else if (clsid == CLSID_AVOptions) {
  765. progID = L"AppVerifier.AVOptions.1";
  766. caption = L"AppVerifier Options";
  767. guidPosition = L"{dc878f00-ac86-4813-8ca9-384fa07cefbf}";
  768. lMinWidth = 300;
  769. lMinHeight = 100;
  770. picture = GetPicture(MAKEINTRESOURCE(IDB_OPTIONS));
  771. } else {
  772. return;
  773. }
  774. hr = m_pDTE->get_Windows(&pWindows);
  775. if (FAILED(hr)) {
  776. return;
  777. }
  778. hr = pWindows->CreateToolWindow(
  779. m_pAddInInstance,
  780. progID,
  781. caption,
  782. guidPosition,
  783. &pObject,
  784. &pToolWindow);
  785. if (FAILED(hr)) {
  786. return;
  787. }
  788. CComQIPtr<IUnknown, &IID_IUnknown>pictUnk(picture);
  789. if (pictUnk) {
  790. pToolWindow->SetTabPicture(CComVariant(pictUnk));
  791. }
  792. }
  793. //
  794. // Make the window visible and activate it.
  795. //
  796. hr = pToolWindow->put_Visible(VARIANT_TRUE);
  797. if (FAILED(hr)) {
  798. return;
  799. }
  800. hr = pToolWindow->Activate();
  801. if (FAILED(hr)) {
  802. return;
  803. }
  804. if (bCreated) {
  805. hr = pToolWindow->get_Width(&lWidth);
  806. if (SUCCEEDED(hr) && (lWidth < lMinWidth)) {
  807. pToolWindow->put_Width(lMinWidth);
  808. }
  809. hr = pToolWindow->get_Height(&lHeight);
  810. if (SUCCEEDED(hr) && (lHeight < lMinHeight)) {
  811. pToolWindow->put_Height(lMinHeight);
  812. }
  813. }
  814. }
  815. void
  816. CConnect::GetNativeVCExecutableNames(
  817. EnvDTE::Project* pProject
  818. )
  819. {
  820. HRESULT hr;
  821. assert(pProject);
  822. // Get the DTE object associated with this project.
  823. CComPtr<IDispatch> vcProjectObject;
  824. hr = pProject->get_Object(&vcProjectObject);
  825. if (SUCCEEDED(hr))
  826. {
  827. // Cast that object to a VCProject object.
  828. CComQIPtr<VCProjectEngineLibrary::VCProject,
  829. &__uuidof(VCProjectEngineLibrary::VCProject)> vcProject(vcProjectObject);
  830. if (vcProject)
  831. {
  832. // Get the configuration set associated with this project.
  833. CComPtr<IDispatch> vcConfigSetObject;
  834. hr = vcProject->get_Configurations(&vcConfigSetObject);
  835. if (SUCCEEDED(hr))
  836. {
  837. // Cast to IVCCollection
  838. CComQIPtr<VCProjectEngineLibrary::IVCCollection,
  839. &__uuidof(VCProjectEngineLibrary::IVCCollection)>
  840. vcConfigurationSet(vcConfigSetObject);
  841. if (vcConfigurationSet)
  842. {
  843. long lVCConfigCount;
  844. hr = vcConfigurationSet->get_Count(&lVCConfigCount);
  845. if (SUCCEEDED(hr))
  846. {
  847. // Loop through all configurations for this project.
  848. for(long j = 1; j <= lVCConfigCount; j++)
  849. {
  850. CComVariant vtConfigSetIdx(j);
  851. CComPtr<IDispatch> vcConfigObject;
  852. hr = vcConfigurationSet->Item(
  853. vtConfigSetIdx, &vcConfigObject);
  854. if (SUCCEEDED(hr))
  855. {
  856. CComQIPtr<
  857. VCProjectEngineLibrary::
  858. VCConfiguration,
  859. &__uuidof(VCProjectEngineLibrary::
  860. VCConfiguration)>
  861. vcConfig(vcConfigObject);
  862. if (vcConfig)
  863. {
  864. // First, verify that this is
  865. // a native executable.
  866. VARIANT_BOOL bIsManaged;
  867. VCProjectEngineLibrary::ConfigurationTypes
  868. configType;
  869. hr = vcConfig->get_ManagedExtensions(&bIsManaged);
  870. if (FAILED(hr)) {
  871. continue;
  872. }
  873. hr = vcConfig->get_ConfigurationType(&configType);
  874. if (FAILED(hr)) {
  875. continue;
  876. }
  877. if (configType !=
  878. VCProjectEngineLibrary::typeApplication &&
  879. bIsManaged != VARIANT_FALSE) {
  880. continue;
  881. }
  882. CComBSTR bstrOutput;
  883. hr = vcConfig->get_PrimaryOutput(&bstrOutput);
  884. if (SUCCEEDED(hr)) {
  885. std::wstring wsFullPath = bstrOutput;
  886. int nPos = wsFullPath.rfind(L'\\');
  887. std::wstring wsShortName = wsFullPath.substr(nPos + 1);
  888. g_wstrExeName = wsShortName;
  889. m_sExeList.insert(wsShortName);
  890. }
  891. }
  892. }
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. BOOL
  901. CConnect::GetAppExeNames(
  902. void
  903. )
  904. {
  905. HRESULT hr;
  906. CComPtr<EnvDTE::_Solution>pSolution;
  907. CComPtr<EnvDTE::SolutionBuild>pSolBuild;
  908. CComPtr<EnvDTE::Projects>projectSet;
  909. CComVariant varStartupProjects;
  910. m_sExeList.clear();
  911. //
  912. // Get the current solution, there is at most one of these.
  913. //
  914. hr = m_pDTE->get_Solution(&pSolution);
  915. if (FAILED(hr)) {
  916. return FALSE;
  917. }
  918. //
  919. // Get the set of all projects in the solution.
  920. //
  921. hr = pSolution->get_Projects(&projectSet);
  922. if (FAILED(hr)) {
  923. return FALSE;
  924. }
  925. hr = pSolution->get_SolutionBuild(&pSolBuild);
  926. if (FAILED(hr)) {
  927. return FALSE;
  928. }
  929. //
  930. // Get the safe array containing all projects that will be
  931. // launched when the solution is run.
  932. // This may return nothing, if the current solution is empty.
  933. //
  934. hr = pSolBuild->get_StartupProjects(&varStartupProjects);
  935. if (FAILED(hr)){
  936. return FALSE;
  937. }
  938. if((varStartupProjects.vt & VT_ARRAY) && (varStartupProjects.vt & VT_VARIANT)) {
  939. UINT cDim = SafeArrayGetDim(varStartupProjects.parray);
  940. if (cDim == 1) {
  941. long lowerBound, upperBound;
  942. SafeArrayGetLBound(varStartupProjects.parray, 1, &lowerBound);
  943. SafeArrayGetUBound(varStartupProjects.parray, 1, &upperBound);
  944. // Loop through the safe array, getting each startup project.
  945. for (long i = lowerBound; i <= upperBound; i++) {
  946. CComVariant vtStartupProjectName;
  947. hr = SafeArrayGetElement(varStartupProjects.parray, &i,
  948. (VARIANT*)&vtStartupProjectName);
  949. if (SUCCEEDED(hr)) {
  950. CComPtr<EnvDTE::Project> project;
  951. hr = projectSet->Item(vtStartupProjectName,&project);
  952. if (SUCCEEDED(hr)) {
  953. GetNativeVCExecutableNames(project);
  954. }
  955. }
  956. }
  957. }
  958. }
  959. return TRUE;
  960. }
  961. BOOL
  962. CConnect::GetAppInfo(
  963. void
  964. )
  965. {
  966. g_psTests->clear();
  967. m_bEnabled = FALSE;
  968. if (GetAppExeNames()) {
  969. if (m_sExeList.empty()) {
  970. return FALSE;
  971. }
  972. std::set<std::wstring>::iterator iter;
  973. iter = m_sExeList.begin();
  974. for(; iter != m_sExeList.end(); iter++) {
  975. //
  976. // Locate this exe in the list of apps.
  977. //
  978. for (int i = 0; i < g_aAppInfo.size(); i++) {
  979. if ((*iter) == g_aAppInfo[i].wstrExeName) {
  980. m_bEnabled = TRUE;
  981. //
  982. // Add this app's tests to the set of tests to run.
  983. //
  984. CTestInfoArray::iterator test;
  985. test = g_aTestInfo.begin();
  986. for (; test != g_aTestInfo.end(); test++) {
  987. if (g_aAppInfo[i].IsTestActive(*test)) {
  988. g_psTests->insert(test);
  989. }
  990. }
  991. break;
  992. }
  993. }
  994. }
  995. return TRUE;
  996. }
  997. SetCurrentAppSettings();
  998. return FALSE;
  999. }
  1000. void
  1001. CConnect::SetEnabledUI(
  1002. void
  1003. )
  1004. {
  1005. WCHAR wszCommandText[64];
  1006. WCHAR wszTooltip[64];
  1007. LoadString(g_hInstance,
  1008. IDS_TB_VERIFY_ENABLED_TEXT,
  1009. wszCommandText,
  1010. ARRAYSIZE(wszCommandText));
  1011. LoadString(g_hInstance,
  1012. IDS_TB_VERIFY_ENABLED_TOOLTIP,
  1013. wszTooltip,
  1014. ARRAYSIZE(wszTooltip));
  1015. //
  1016. // Change the text on the button.
  1017. //
  1018. CComQIPtr<Office::_CommandBarButton,
  1019. &_uuidof(Office::_CommandBarButton)>pButton(m_pEnableControl);
  1020. m_pEnableControl->put_Caption(CComBSTR(wszCommandText));
  1021. //
  1022. // Set the picture so we show the button as enabled.
  1023. //
  1024. CComPtr<IPictureDisp>picture = GetPicture(MAKEINTRESOURCE(IDB_DISABLED));
  1025. pButton->put_Picture(picture);
  1026. CComPtr<IPictureDisp>pictureMask = GetPicture(MAKEINTRESOURCE(IDB_ENABLED_MASK));
  1027. pButton->put_Mask(pictureMask);
  1028. //
  1029. // Change the tooltip so that it corresponds to the change
  1030. // in the button text.
  1031. //
  1032. m_pEnableControl->put_TooltipText(CComBSTR(wszTooltip));
  1033. m_pEnableControl->put_Enabled(VARIANT_TRUE);
  1034. m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1035. m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1036. //
  1037. // Hide all of our settings windows.
  1038. //
  1039. CComPtr<EnvDTE::Window>pWindow;
  1040. pWindow = GetToolWindow(CLSID_TestSettingsCtrl);
  1041. if (pWindow) {
  1042. pWindow->put_Visible(VARIANT_FALSE);
  1043. }
  1044. pWindow = GetToolWindow(CLSID_AVOptions);
  1045. if (pWindow) {
  1046. pWindow->put_Visible(VARIANT_FALSE);
  1047. }
  1048. }
  1049. void
  1050. CConnect::DisableVerificationBtn(
  1051. void
  1052. )
  1053. {
  1054. CComQIPtr<Office::_CommandBarButton,
  1055. &_uuidof(Office::_CommandBarButton)>pButton(m_pEnableControl);
  1056. m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1057. }
  1058. void
  1059. CConnect::EnableVerificationBtn(
  1060. void
  1061. )
  1062. {
  1063. CComQIPtr<Office::_CommandBarButton,
  1064. &_uuidof(Office::_CommandBarButton)>pButton(m_pEnableControl);
  1065. m_pEnableControl->put_Enabled(VARIANT_TRUE);
  1066. }
  1067. void
  1068. CConnect::SetDisabledUI(
  1069. void
  1070. )
  1071. {
  1072. WCHAR wszCommandText[64];
  1073. WCHAR wszTooltip[64];
  1074. LoadString(g_hInstance,
  1075. IDS_TB_VERIFICATION_CMD_TEXT,
  1076. wszCommandText,
  1077. ARRAYSIZE(wszCommandText));
  1078. LoadString(g_hInstance,
  1079. IDS_TB_VERIFICATION_CMD_TOOLTIP,
  1080. wszTooltip,
  1081. ARRAYSIZE(wszTooltip));
  1082. //
  1083. // Change the text on the button.
  1084. //
  1085. CComQIPtr<Office::_CommandBarButton,
  1086. &_uuidof(Office::_CommandBarButton)>pButton(m_pEnableControl);
  1087. m_pEnableControl->put_Caption(CComBSTR(wszCommandText));
  1088. //
  1089. // Set the picture so we show the button as disabled.
  1090. //
  1091. CComPtr<IPictureDisp> picture = GetPicture(MAKEINTRESOURCE(IDB_ENABLED));
  1092. pButton->put_Picture(picture);
  1093. CComPtr<IPictureDisp> pictureMask = GetPicture(MAKEINTRESOURCE(IDB_ENABLED_MASK));
  1094. pButton->put_Mask(pictureMask);
  1095. //
  1096. // Change the tooltip so that it corresponds to the change
  1097. // in the button text.
  1098. //
  1099. m_pEnableControl->put_TooltipText(CComBSTR(wszTooltip));
  1100. m_pEnableControl->put_Enabled(VARIANT_TRUE);
  1101. m_pTestsControl->put_Enabled(VARIANT_TRUE);
  1102. m_pOptionControl->put_Enabled(VARIANT_TRUE);
  1103. }
  1104. void
  1105. CConnect::SetCurrentAppSettings(
  1106. void
  1107. )
  1108. {
  1109. if (m_bEnabled) {
  1110. //
  1111. // Insert exes into app array.
  1112. //
  1113. std::set<std::wstring>::iterator exe;
  1114. exe = m_sExeList.begin();
  1115. for (; exe != m_sExeList.end(); exe++) {
  1116. CAVAppInfo* pApp = NULL;
  1117. for (int i = 0; i < g_aAppInfo.size(); i++) {
  1118. if (g_aAppInfo[i].wstrExeName==*exe) {
  1119. pApp = &g_aAppInfo[i];
  1120. break;
  1121. }
  1122. }
  1123. if (pApp == NULL) {
  1124. CAVAppInfo app;
  1125. app.wstrExeName = *exe;
  1126. g_aAppInfo.push_back(app);
  1127. pApp = &g_aAppInfo.back();
  1128. }
  1129. std::set<CTestInfo*, CompareTests>::iterator iter;
  1130. iter = g_psTests->begin();
  1131. for(; iter != g_psTests->end(); iter++) {
  1132. pApp->AddTest(**iter);
  1133. }
  1134. //
  1135. // Add flags.
  1136. //
  1137. pApp->bBreakOnLog = g_bBreakOnLog;
  1138. pApp->bFullPageHeap = g_bFullPageHeap;
  1139. pApp->bUseAVDebugger = FALSE;
  1140. pApp->bPropagateTests = g_bPropagateTests;
  1141. pApp->wstrDebugger = L"";
  1142. }
  1143. } else {
  1144. std::set<std::wstring>::iterator exe;
  1145. exe = m_sExeList.begin();
  1146. for (; exe != m_sExeList.end(); exe++) {
  1147. CAVAppInfoArray::iterator app;
  1148. app = g_aAppInfo.begin();
  1149. for (; app != g_aAppInfo.end(); app++) {
  1150. if (app->wstrExeName==*exe) {
  1151. //
  1152. // Before we erase this app, remove all kernel tests
  1153. // and write app data.
  1154. //
  1155. app->dwRegFlags = 0;
  1156. ::SetCurrentAppSettings();
  1157. g_aAppInfo.erase(app);
  1158. break;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. if (!g_aAppInfo.empty()) {
  1164. //
  1165. // Persist Options.
  1166. //
  1167. for (CAVAppInfo *pApp = g_aAppInfo.begin(); pApp != g_aAppInfo.end(); ++pApp) {
  1168. LPCWSTR szExe = pApp->wstrExeName.c_str();
  1169. SaveShimSettingDWORD(L"General", szExe, AV_OPTION_BREAK_ON_LOG, (DWORD)pApp->bBreakOnLog);
  1170. SaveShimSettingDWORD(L"General", szExe, AV_OPTION_FULL_PAGEHEAP, (DWORD)pApp->bFullPageHeap);
  1171. SaveShimSettingDWORD(L"General", szExe, AV_OPTION_AV_DEBUGGER, (DWORD)pApp->bUseAVDebugger);
  1172. SaveShimSettingDWORD(L"General", szExe, AV_OPTION_PROPAGATE, (DWORD)pApp->bPropagateTests);
  1173. SaveShimSettingString(L"General", szExe, AV_OPTION_DEBUGGER, pApp->wstrDebugger.c_str());
  1174. }
  1175. ::SetCurrentAppSettings();
  1176. }
  1177. }
  1178. HRESULT
  1179. CConnect::CSolutionEventsSink::AfterClosing(
  1180. void
  1181. )
  1182. {
  1183. // We're done, cleanup.
  1184. // Disable our controls
  1185. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1186. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1187. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1188. return S_OK;
  1189. }
  1190. HRESULT
  1191. CConnect::CSolutionEventsSink::BeforeClosing(
  1192. void
  1193. )
  1194. {
  1195. return S_OK;
  1196. }
  1197. HRESULT
  1198. CConnect::CSolutionEventsSink::Opened(
  1199. void
  1200. )
  1201. {
  1202. CComPtr<EnvDTE::_Solution>pSolution;
  1203. CComPtr<EnvDTE::Globals>pGlobals;
  1204. if (!g_bCorrectOSVersion) {
  1205. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1206. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1207. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1208. m_pParent->m_pLogViewControl->put_Enabled(VARIANT_FALSE);
  1209. return S_OK;
  1210. }
  1211. //
  1212. // Change in config.
  1213. //
  1214. if (m_pParent->GetAppInfo()) {
  1215. if (m_pParent->m_bEnabled) {
  1216. m_pParent->SetEnabledUI();
  1217. } else {
  1218. m_pParent->SetDisabledUI();
  1219. }
  1220. } else {
  1221. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1222. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1223. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1224. }
  1225. return S_OK;
  1226. }
  1227. HRESULT
  1228. CConnect::CSolutionEventsSink::ProjectAdded(
  1229. EnvDTE::Project* /*proj*/
  1230. )
  1231. {
  1232. if (!g_bCorrectOSVersion) {
  1233. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1234. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1235. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1236. m_pParent->m_pLogViewControl->put_Enabled(VARIANT_FALSE);
  1237. return S_OK;
  1238. }
  1239. //
  1240. // Change in config.
  1241. //
  1242. if (m_pParent->GetAppInfo()) {
  1243. if (m_pParent->m_bEnabled) {
  1244. m_pParent->SetEnabledUI();
  1245. } else {
  1246. m_pParent->SetDisabledUI();
  1247. }
  1248. } else {
  1249. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1250. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1251. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1252. }
  1253. return S_OK;
  1254. }
  1255. HRESULT
  1256. CConnect::CSolutionEventsSink::ProjectRemoved(
  1257. EnvDTE::Project* /*proj*/
  1258. )
  1259. {
  1260. if (!g_bCorrectOSVersion) {
  1261. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1262. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1263. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1264. m_pParent->m_pLogViewControl->put_Enabled(VARIANT_FALSE);
  1265. return S_OK;
  1266. }
  1267. // Change in config.
  1268. if (m_pParent->GetAppInfo()) {
  1269. if (m_pParent->m_bEnabled) {
  1270. m_pParent->SetEnabledUI();
  1271. } else {
  1272. m_pParent->SetDisabledUI();
  1273. }
  1274. } else {
  1275. m_pParent->m_pOptionControl->put_Enabled(VARIANT_FALSE);
  1276. m_pParent->m_pTestsControl->put_Enabled(VARIANT_FALSE);
  1277. m_pParent->m_pEnableControl->put_Enabled(VARIANT_FALSE);
  1278. }
  1279. return S_OK;
  1280. }
  1281. HRESULT
  1282. CConnect::CSolutionEventsSink::ProjectRenamed(
  1283. EnvDTE::Project* /*proj*/,
  1284. BSTR /*bstrOldName*/
  1285. )
  1286. {
  1287. return S_OK;
  1288. }
  1289. HRESULT
  1290. CConnect::CSolutionEventsSink::QueryCloseSolution(
  1291. VARIANT_BOOL* fCancel
  1292. )
  1293. {
  1294. *fCancel = VARIANT_FALSE;
  1295. return S_OK;
  1296. }
  1297. HRESULT
  1298. CConnect::CSolutionEventsSink::Renamed(
  1299. BSTR /*bstrOldName*/
  1300. )
  1301. {
  1302. return S_OK;
  1303. }