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.

291 lines
8.1 KiB

  1. //
  2. // Downlevel (NT4, win9X) Install/Unistall page
  3. //
  4. #include "priv.h"
  5. #include "appwizid.h"
  6. #include "dlinst.h"
  7. #include "sccls.h"
  8. //
  9. // DonwLevelManager: Ugly singleton class
  10. //
  11. // Mainly there to keep state info and for its destructor
  12. //
  13. class CDLManager* g_pDLManager = NULL;
  14. class CDLManager
  15. {
  16. public:
  17. // Rely on the fact that shell "new" zero out memory
  18. CDLManager() : _hrInit(E_FAIL)
  19. {
  20. _hrInit = CoInitialize(0);
  21. _szStatic[0] = 0;
  22. _szStatic2[0] = 0;
  23. _uiStatic = 0;
  24. }
  25. ~CDLManager()
  26. {
  27. if (_peia)
  28. _peia->Release();
  29. if (SUCCEEDED(_hrInit))
  30. CoUninitialize();
  31. }
  32. public:
  33. void InitButtonsHandle(HWND hwndPage)
  34. {
  35. // No check for success: check before using
  36. if (!_hwndModifyUninstall)
  37. {
  38. _hwndModifyUninstall = GetDlgItem(hwndPage, IDC_MODIFYUNINSTALL);
  39. _rghwndButtons[IDC_MODIFY-IDC_BASEBUTTONS] = GetDlgItem(hwndPage, IDC_MODIFY);
  40. _rghwndButtons[IDC_REPAIR-IDC_BASEBUTTONS] = GetDlgItem(hwndPage, IDC_REPAIR);
  41. _rghwndButtons[IDC_UNINSTALL-IDC_BASEBUTTONS] = GetDlgItem(hwndPage, IDC_UNINSTALL);
  42. }
  43. }
  44. void SetVisibleButtons(BOOL bShow3Buttons)
  45. {
  46. // bShow3Buttons == TRUE will show the three buttons
  47. if (_hwndModifyUninstall)
  48. ShowWindow(_hwndModifyUninstall, bShow3Buttons?SW_HIDE:SW_SHOW);
  49. for (int i=0;i<3;++i)
  50. {
  51. if (_rghwndButtons[i])
  52. ShowWindow(_rghwndButtons[i], bShow3Buttons?SW_SHOW:SW_HIDE);
  53. }
  54. }
  55. public:
  56. IEnumInstalledApps* _peia;
  57. HWND _hwndModifyUninstall;
  58. HWND _rghwndButtons[3];
  59. HRESULT _hrInit;
  60. TCHAR _szStatic[250];
  61. TCHAR _szStatic2[50];
  62. UINT _uiStatic;
  63. };
  64. //
  65. // pcApps has to be already initialized, we only increment it
  66. //
  67. STDAPI DL_FillAppListBox(HWND hwndListBox, DWORD* pdwApps)
  68. {
  69. ASSERT(IsWindow(hwndListBox));
  70. static CDLManager DLManager;
  71. g_pDLManager = &DLManager;
  72. ASSERT(g_pDLManager);
  73. HRESULT hres = E_FAIL;
  74. IShellAppManager * pam;
  75. if (SUCCEEDED(g_pDLManager->_hrInit))
  76. {
  77. hres = CoCreateInstance(CLSID_ShellAppManager, NULL, CLSCTX_INPROC_SERVER,
  78. IID_IShellAppManager, (LPVOID *)&pam);
  79. if (SUCCEEDED(hres))
  80. {
  81. // Initialize InstalledApp Enum if required
  82. if (!g_pDLManager->_peia)
  83. hres = pam->EnumInstalledApps(&g_pDLManager->_peia);
  84. if (SUCCEEDED(hres))
  85. {
  86. IInstalledApp* pia;
  87. while ((hres = g_pDLManager->_peia->Next(&pia)) == S_OK)
  88. {
  89. APPINFODATA ais = {0};
  90. ais.cbSize = sizeof(ais);
  91. ais.dwMask = AIM_DISPLAYNAME;
  92. pia->GetAppInfo(&ais);
  93. if (ais.dwMask & AIM_DISPLAYNAME)
  94. {
  95. int iIndex = LB_ERR;
  96. iIndex = ListBox_AddString(hwndListBox, ais.pszDisplayName);
  97. // Did the operation succeed?
  98. if (LB_ERR != iIndex)
  99. {
  100. // Is memory OK?
  101. if (LB_ERRSPACE != iIndex)
  102. {
  103. // Yes
  104. ListBox_SetItemData(hwndListBox, iIndex, pia);
  105. ++(*pdwApps);
  106. }
  107. else
  108. {
  109. // No, better get out
  110. pia->Release();
  111. break;
  112. }
  113. }
  114. }
  115. else
  116. pia->Release();
  117. }
  118. }
  119. pam->Release();
  120. }
  121. }
  122. return hres;
  123. }
  124. STDAPI_(BOOL) DL_ConfigureButtonsAndStatic(HWND hwndPage, HWND hwndListBox, int iSel)
  125. {
  126. ASSERT(IsWindow(hwndPage));
  127. ASSERT(IsWindow(hwndListBox));
  128. ASSERT(0 <= iSel);
  129. UINT uiStatic = IDS_UNINSTINSTR_LEGACY;
  130. BOOL fret = FALSE;
  131. if (LB_ERR != iSel)
  132. {
  133. LRESULT lres = ListBox_GetItemData(hwndListBox, iSel);
  134. if (LB_ERR != lres)
  135. {
  136. fret = TRUE;
  137. IInstalledApp* pia = (IInstalledApp*)lres;
  138. DWORD dwActions = 0;
  139. pia->GetPossibleActions(&dwActions);
  140. dwActions &= (APPACTION_MODIFY|APPACTION_REPAIR|APPACTION_UNINSTALL|APPACTION_MODIFYREMOVE);
  141. g_pDLManager->InitButtonsHandle(hwndPage);
  142. if (dwActions & APPACTION_MODIFYREMOVE)
  143. {
  144. // Manage to show the right buttons
  145. g_pDLManager->SetVisibleButtons(FALSE);
  146. EnableWindow(g_pDLManager->_hwndModifyUninstall, TRUE);
  147. }
  148. else
  149. {
  150. if (dwActions & (APPACTION_MODIFY|APPACTION_REPAIR|APPACTION_UNINSTALL))
  151. {
  152. // Manage to show the right buttons
  153. g_pDLManager->SetVisibleButtons(TRUE);
  154. // Enable the applicable buttons
  155. EnableWindow(g_pDLManager->_rghwndButtons[IDC_MODIFY-IDC_BASEBUTTONS],
  156. (dwActions&APPACTION_MODIFY)?TRUE:FALSE);
  157. EnableWindow(g_pDLManager->_rghwndButtons[IDC_REPAIR-IDC_BASEBUTTONS],
  158. (dwActions&APPACTION_REPAIR)?TRUE:FALSE);
  159. EnableWindow(g_pDLManager->_rghwndButtons[IDC_UNINSTALL-IDC_BASEBUTTONS],
  160. (dwActions&APPACTION_UNINSTALL)?TRUE:FALSE);
  161. uiStatic = IDS_UNINSTINSTR_NEW;
  162. }
  163. else
  164. {
  165. // Manage to show the right buttons
  166. g_pDLManager->SetVisibleButtons(FALSE);
  167. EnableWindow(g_pDLManager->_hwndModifyUninstall, FALSE);
  168. }
  169. }
  170. }
  171. }
  172. if (!(*g_pDLManager->_szStatic))
  173. {
  174. if(!LoadString(g_hinst, IDS_UNINSTINSTR, g_pDLManager->_szStatic, ARRAYSIZE(g_pDLManager->_szStatic)))
  175. *(g_pDLManager->_szStatic) = 0;
  176. }
  177. if (*g_pDLManager->_szStatic && (g_pDLManager->_uiStatic != uiStatic))
  178. {
  179. TCHAR szMergedStatic[250];
  180. LoadString(g_hinst, uiStatic, g_pDLManager->_szStatic2, ARRAYSIZE(g_pDLManager->_szStatic2));
  181. StringCchPrintf(szMergedStatic, ARRAYSIZE(szMergedStatic), g_pDLManager->_szStatic, g_pDLManager->_szStatic2);
  182. SetDlgItemText(hwndPage, IDC_UNINSTINSTR, szMergedStatic);
  183. g_pDLManager->_uiStatic = uiStatic;
  184. }
  185. return fret;
  186. }
  187. STDAPI_(BOOL) DL_InvokeAction(int iButtonID, HWND hwndPage, HWND hwndListBox, int iSel)
  188. {
  189. BOOL fret = FALSE;
  190. // Get app from listbox selection
  191. LRESULT lres = ListBox_GetItemData(hwndListBox, iSel);
  192. if (LB_ERR != lres)
  193. {
  194. fret = TRUE;
  195. IInstalledApp* pia = (IInstalledApp*)lres;
  196. // Invoke action from button ID
  197. if (pia)
  198. {
  199. HWND hwndPropSheet = GetParent(hwndPage);
  200. ::EnableWindow(hwndPropSheet, FALSE);
  201. switch(iButtonID)
  202. {
  203. case IDC_MODIFY:
  204. pia->Modify(hwndPropSheet);
  205. break;
  206. case IDC_REPAIR:
  207. // Pass FALSe, we don't want to reinstall, only repair
  208. pia->Repair(FALSE);
  209. break;
  210. case IDC_MODIFYUNINSTALL:
  211. case IDC_UNINSTALL:
  212. pia->Uninstall(hwndPropSheet);
  213. break;
  214. default:
  215. //???
  216. break;
  217. }
  218. ::EnableWindow(hwndPropSheet , TRUE);
  219. }
  220. }
  221. return fret;
  222. }