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.

447 lines
14 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: Xforms.cpp
  7. //
  8. // Contents: modifications (transforms) property page
  9. //
  10. // Classes: CXforms
  11. //
  12. // History: 03-14-1998 stevebl Commented
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.hxx"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CXforms property page
  23. IMPLEMENT_DYNCREATE(CXforms, CPropertyPage)
  24. CXforms::CXforms() : CPropertyPage(CXforms::IDD)
  25. {
  26. //{{AFX_DATA_INIT(CXforms)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. m_fModified = FALSE;
  30. m_pIClassAdmin = NULL;
  31. m_fPreDeploy = FALSE;
  32. m_ppThis = NULL;
  33. }
  34. CXforms::~CXforms()
  35. {
  36. if (m_ppThis)
  37. {
  38. *m_ppThis = NULL;
  39. }
  40. if (m_pIClassAdmin)
  41. {
  42. m_pIClassAdmin->Release();
  43. }
  44. }
  45. void CXforms::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CPropertyPage::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CXforms)
  49. // NOTE: the ClassWizard will add DDX and DDV calls here
  50. //}}AFX_DATA_MAP
  51. }
  52. BEGIN_MESSAGE_MAP(CXforms, CPropertyPage)
  53. //{{AFX_MSG_MAP(CXforms)
  54. ON_BN_CLICKED(IDC_BUTTON3, OnMoveUp)
  55. ON_BN_CLICKED(IDC_BUTTON4, OnMoveDown)
  56. ON_BN_CLICKED(IDC_BUTTON1, OnAdd)
  57. ON_BN_CLICKED(IDC_BUTTON2, OnRemove)
  58. ON_WM_CONTEXTMENU()
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CXforms message handlers
  63. void CXforms::OnMoveUp()
  64. {
  65. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  66. int i = pList->GetCurSel();
  67. if (LB_ERR != i && i > 0)
  68. {
  69. CString sz;
  70. pList->GetText(i, sz);
  71. pList->DeleteString(i);
  72. pList->InsertString(i-1, sz);
  73. pList->SetCurSel(i-1);
  74. if (!m_fPreDeploy)
  75. SetModified();
  76. m_fModified = TRUE;
  77. }
  78. }
  79. void CXforms::OnMoveDown()
  80. {
  81. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  82. int i = pList->GetCurSel();
  83. if (i != LB_ERR && i < pList->GetCount() - 1)
  84. {
  85. CString sz;
  86. pList->GetText(i+1, sz);
  87. pList->DeleteString(i+1);
  88. pList->InsertString(i, sz);
  89. pList->SetCurSel(i+1);
  90. if (!m_fPreDeploy)
  91. SetModified();
  92. m_fModified = TRUE;
  93. }
  94. }
  95. void CXforms::OnAdd()
  96. {
  97. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  98. CString szExtension;
  99. CString szFilter;
  100. szExtension.LoadString(IDS_DEF_TRANSFORM_EXTENSION);
  101. szFilter.LoadString(IDS_TRANSFORM_EXTENSION_FILTER);
  102. OPENFILENAME ofn;
  103. memset(&ofn, 0, sizeof(ofn));
  104. ofn.lStructSize = sizeof(ofn);
  105. ofn.hwndOwner = m_hWnd;
  106. ofn.hInstance = ghInstance;
  107. TCHAR lpstrFilter[MAX_PATH];
  108. //
  109. // Note that since wcsncpy does not null terminate
  110. // if the string hits the specified character limit,
  111. // we need to prevent it from going all the way
  112. // to the end of the buffer by specifying that
  113. // it should use a length one less than the size
  114. // of the buffer
  115. //
  116. wcsncpy(lpstrFilter, szFilter, MAX_PATH - 1 );
  117. //
  118. // Since the string may not have been null terminated
  119. // as described above, we ensure that the very last
  120. // character is a terminator to handle the case
  121. // where the string was at least MAX_PATH - 1
  122. // chars long.
  123. //
  124. lpstrFilter[ MAX_PATH - 1 ] = L'\0';
  125. ofn.lpstrFilter = lpstrFilter;
  126. TCHAR szFileTitle[MAX_PATH];
  127. TCHAR szFile[MAX_PATH];
  128. szFile[0] = NULL;
  129. ofn.lpstrFile = szFile;
  130. ofn.nMaxFile = MAX_PATH;
  131. ofn.lpstrFileTitle = szFileTitle;
  132. ofn.nMaxFileTitle = MAX_PATH;
  133. ofn.lpstrInitialDir = m_pScopePane->m_ToolDefaults.szStartPath;
  134. ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST;
  135. ofn.lpstrDefExt = szExtension;
  136. int iBreak = 0;
  137. while (lpstrFilter[iBreak])
  138. {
  139. if (lpstrFilter[iBreak] == TEXT('|'))
  140. {
  141. lpstrFilter[iBreak] = 0;
  142. }
  143. iBreak++;
  144. }
  145. if (GetOpenFileName(&ofn))
  146. {
  147. // user selected an application
  148. ULONG cbSize = sizeof(UNIVERSAL_NAME_INFO);
  149. UNIVERSAL_NAME_INFO * pUni = (UNIVERSAL_NAME_INFO *) new BYTE [cbSize];
  150. DWORD dwError = WNetGetUniversalName(ofn.lpstrFile,
  151. UNIVERSAL_NAME_INFO_LEVEL,
  152. pUni,
  153. &cbSize);
  154. if (ERROR_MORE_DATA == dwError) // we expect this to be true
  155. {
  156. delete [] pUni;
  157. pUni = (UNIVERSAL_NAME_INFO *) new BYTE [cbSize];
  158. dwError = WNetGetUniversalName(ofn.lpstrFile,
  159. UNIVERSAL_NAME_INFO_LEVEL,
  160. pUni,
  161. &cbSize);
  162. }
  163. CString szTransformPath;
  164. if (ERROR_SUCCESS == dwError)
  165. {
  166. szTransformPath = pUni->lpUniversalName;
  167. }
  168. else
  169. {
  170. szTransformPath = ofn.lpstrFile;
  171. }
  172. delete[] pUni;
  173. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  174. pList->AddString(szTransformPath);
  175. CDC * pDC = pList->GetDC();
  176. CSize size = pDC->GetTextExtent(szTransformPath);
  177. pDC->LPtoDP(&size);
  178. pList->ReleaseDC(pDC);
  179. if (pList->GetHorizontalExtent() < size.cx)
  180. {
  181. pList->SetHorizontalExtent(size.cx);
  182. }
  183. pList->SetCurSel(pList->GetCount() - 1);
  184. if (!m_fPreDeploy)
  185. SetModified();
  186. m_fModified = TRUE;
  187. int n = pList->GetCount();
  188. GetDlgItem(IDC_BUTTON2)->EnableWindow(n > 0);
  189. GetDlgItem(IDC_BUTTON3)->EnableWindow(n > 1);
  190. GetDlgItem(IDC_BUTTON4)->EnableWindow(n > 1);
  191. if (NULL == GetFocus())
  192. {
  193. GetParent()->GetDlgItem(IDOK)->SetFocus();
  194. }
  195. }
  196. }
  197. void CXforms::OnRemove()
  198. {
  199. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  200. int i = pList->GetCurSel();
  201. if (LB_ERR != i)
  202. {
  203. pList->DeleteString(i);
  204. pList->SetCurSel(0);
  205. if (!m_fPreDeploy)
  206. SetModified();
  207. m_fModified = TRUE;
  208. int n = pList->GetCount();
  209. GetDlgItem(IDC_BUTTON2)->EnableWindow(n > 0);
  210. GetDlgItem(IDC_BUTTON3)->EnableWindow(n > 1);
  211. GetDlgItem(IDC_BUTTON4)->EnableWindow(n > 1);
  212. if (NULL == GetFocus())
  213. {
  214. GetParent()->GetDlgItem(IDOK)->SetFocus();
  215. }
  216. }
  217. }
  218. BOOL CXforms::OnInitDialog()
  219. {
  220. if (m_pScopePane->m_fRSOP || !m_fPreDeploy)
  221. {
  222. GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
  223. SetDlgItemText(IDC_STATICNOHELP1, TEXT(""));
  224. }
  225. GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
  226. GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
  227. GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
  228. // Remember what the package name was at first so we can tell if the
  229. // user's changed it.
  230. m_szInitialPackageName = m_pData->m_pDetails->pszPackageName;
  231. RefreshData();
  232. CPropertyPage::OnInitDialog();
  233. return TRUE; // return TRUE unless you set the focus to a control
  234. // EXCEPTION: OCX Property Pages should return FALSE
  235. }
  236. BOOL CXforms::OnApply()
  237. {
  238. // NOTE
  239. //
  240. // If the transform list changes we really have no choice but to
  241. // re-deploy the app because it can cause virtually every field in the
  242. // package details structure to change (a change in the transform list
  243. // causes a rebuild of the script file which could potentially affect
  244. // almost everything).
  245. //
  246. // For this reason, this property sheet MUST NOT BE ACTIVE once an app
  247. // is deployed.
  248. //
  249. BOOL fBuildSucceeded = FALSE;
  250. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  251. if (m_fModified)
  252. {
  253. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  254. PACKAGEDETAIL * ppd;
  255. if (FAILED(CopyPackageDetail(ppd, m_pData->m_pDetails)))
  256. {
  257. return FALSE;
  258. }
  259. CString sz;
  260. int i;
  261. for (i = ppd->cSources; i--;)
  262. {
  263. OLESAFE_DELETE(ppd->pszSourceList[i]);
  264. }
  265. OLESAFE_DELETE(ppd->pszSourceList);
  266. int n = pList->GetCount();
  267. ppd->pszSourceList = (LPOLESTR *) OLEALLOC(sizeof(LPOLESTR) * (n + 1));
  268. if (ppd->pszSourceList)
  269. {
  270. OLESAFE_COPYSTRING(ppd->pszSourceList[0], m_pData->m_pDetails->pszSourceList[0]);
  271. for (i = 0; i < n; i++)
  272. {
  273. pList->GetText(i, sz);
  274. OLESAFE_COPYSTRING(ppd->pszSourceList[i+1], sz);
  275. }
  276. ppd->cSources = n + 1;
  277. }
  278. else
  279. {
  280. ppd->cSources = 0;
  281. return FALSE;
  282. }
  283. // Create a name for the new script file.
  284. // set the script path
  285. GUID guid;
  286. HRESULT hr = CoCreateGuid(&guid);
  287. if (FAILED(hr))
  288. {
  289. // undone
  290. }
  291. OLECHAR szGuid [256];
  292. StringFromGUID2(guid, szGuid, 256);
  293. CString szScriptFile = m_pScopePane->m_szGPT_Path;
  294. szScriptFile += L"\\";
  295. szScriptFile += szGuid;
  296. szScriptFile += L".aas";
  297. OLESAFE_DELETE(ppd->pInstallInfo->pszScriptPath);
  298. OLESAFE_COPYSTRING(ppd->pInstallInfo->pszScriptPath, szScriptFile);
  299. CString szOldName = ppd->pszPackageName;
  300. hr = BuildScriptAndGetActInfo(*ppd, ! m_pData->m_pDetails->pActInfo->bHasClasses);
  301. if (SUCCEEDED(hr))
  302. {
  303. if (0 != wcscmp(m_szInitialPackageName, szOldName))
  304. {
  305. // The User changed the name so we have to preserve his choice.
  306. // If the user hasn't changed the package name then it's ok to
  307. // set the packagename to whatever is in the script file.
  308. OLESAFE_DELETE(ppd->pszPackageName);
  309. OLESAFE_COPYSTRING(ppd->pszPackageName, szOldName);
  310. }
  311. fBuildSucceeded = TRUE;
  312. hr = m_pScopePane->PrepareExtensions(*ppd);
  313. if (SUCCEEDED(hr))
  314. {
  315. CString szUniqueName;
  316. int nHint;
  317. nHint = 1;
  318. m_pScopePane->GetUniquePackageName(ppd->pszPackageName, szUniqueName, nHint);
  319. OLESAFE_DELETE(ppd->pszPackageName);
  320. OLESAFE_COPYSTRING(ppd->pszPackageName, szUniqueName);
  321. hr = m_pIClassAdmin->RedeployPackage(
  322. &m_pData->m_pDetails->pInstallInfo->PackageGuid,
  323. ppd);
  324. if (SUCCEEDED(hr))
  325. {
  326. // delete the old script
  327. DeleteFile(m_pData->m_pDetails->pInstallInfo->pszScriptPath);
  328. // update indexes and property sheets
  329. m_pScopePane->RemoveExtensionEntry(m_cookie, *m_pData);
  330. m_pScopePane->RemoveUpgradeEntry(m_cookie, *m_pData);
  331. FreePackageDetail(m_pData->m_pDetails);
  332. m_pData->m_pDetails = ppd;
  333. m_pScopePane->InsertExtensionEntry(m_cookie, *m_pData);
  334. m_pScopePane->InsertUpgradeEntry(m_cookie, *m_pData);
  335. if (m_pScopePane->m_pFileExt)
  336. {
  337. m_pScopePane->m_pFileExt->SendMessage(WM_USER_REFRESH, 0, 0);
  338. }
  339. m_fModified = FALSE;
  340. if (!m_fPreDeploy)
  341. {
  342. MMCPropertyChangeNotify(m_hConsoleHandle, m_cookie);
  343. }
  344. }
  345. }
  346. }
  347. if (FAILED(hr))
  348. {
  349. CString sz;
  350. sz.LoadString(fBuildSucceeded ? IDS_TRANSFORM_FAILED_IN_CS : IDS_TRANSFORM_FAILED);
  351. ReportGeneralPropertySheetError(m_hWnd, sz, hr);
  352. // delete new script file (assuming it was created)
  353. DeleteFile(szScriptFile);
  354. FreePackageDetail(ppd);
  355. return FALSE;
  356. }
  357. }
  358. return CPropertyPage::OnApply();
  359. }
  360. LRESULT CXforms::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  361. {
  362. switch (message)
  363. {
  364. case WM_HELP:
  365. StandardHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, IDD);
  366. return 0;
  367. case WM_USER_REFRESH:
  368. RefreshData();
  369. return 0;
  370. case WM_USER_CLOSE:
  371. return GetOwner()->SendMessage(WM_CLOSE);
  372. default:
  373. return CPropertyPage::WindowProc(message, wParam, lParam);
  374. }
  375. }
  376. void CXforms::RefreshData(void)
  377. {
  378. CListBox * pList = (CListBox *)GetDlgItem(IDC_LIST1);
  379. pList->ResetContent();
  380. pList->SetHorizontalExtent(0);
  381. UINT i;
  382. // Item at 0 is the package. Items > 0 are transforms.
  383. for (i = 1; i < m_pData->m_pDetails->cSources; i++)
  384. {
  385. pList->AddString(m_pData->m_pDetails->pszSourceList[i]);
  386. CDC * pDC = pList->GetDC();
  387. CSize size = pDC->GetTextExtent(m_pData->m_pDetails->pszSourceList[i]);
  388. pDC->LPtoDP(&size);
  389. pList->ReleaseDC(pDC);
  390. if (pList->GetHorizontalExtent() < size.cx)
  391. {
  392. pList->SetHorizontalExtent(size.cx);
  393. }
  394. }
  395. pList->SetCurSel(0);
  396. SetModified(FALSE);
  397. m_fModified = FALSE;
  398. }
  399. void CXforms::OnContextMenu(CWnd* pWnd, CPoint point)
  400. {
  401. StandardContextMenu(pWnd->m_hWnd, IDD_MODIFICATIONS);
  402. }