Source code of Windows XP (NT5)
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.

443 lines
14 KiB

  1. // genpage.cpp : implementation file
  2. //
  3. #include "precomp.hxx"
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CGeneralPage property page
  11. IMPLEMENT_DYNCREATE(CGeneralPage, CPropertyPage)
  12. CGeneralPage::CGeneralPage() : CPropertyPage(CGeneralPage::IDD)
  13. {
  14. //{{AFX_DATA_INIT(CGeneralPage)
  15. m_szName = _T("");
  16. m_szDeploy = _T("");
  17. m_szDescription = _T("");
  18. m_szLocale = _T("");
  19. m_szPath = _T("");
  20. m_szVer = _T("");
  21. m_fShow = TRUE;
  22. //}}AFX_DATA_INIT
  23. m_hConsoleHandle = NULL;
  24. m_bUpdate = FALSE;
  25. }
  26. CGeneralPage::~CGeneralPage()
  27. {
  28. }
  29. void CGeneralPage::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CPropertyPage::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CGeneralPage)
  33. DDX_Control(pDX, IDC_DEPLOY, m_cbDeploy);
  34. DDX_CBString(pDX, IDC_DEPLOY, m_szDeploy);
  35. DDX_Text(pDX, IDC_NAME, m_szName);
  36. DDX_Text(pDX, IDC_DESCRIPTION, m_szDescription);
  37. DDX_Text(pDX, IDC_LOCALE, m_szLocale);
  38. DDX_Text(pDX, IDC_PATH, m_szPath);
  39. DDX_Text(pDX, IDC_VERSION, m_szVer);
  40. DDX_Control(pDX, IDC_CPU, m_cbCPU);
  41. DDX_Control(pDX, IDC_OS, m_cbOS);
  42. DDX_Check(pDX, IDC_CHECK1, m_fShow);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CGeneralPage, CPropertyPage)
  46. //{{AFX_MSG_MAP(CGeneralPage)
  47. ON_WM_DESTROY()
  48. ON_EN_CHANGE(IDC_NAME, OnChangeName)
  49. ON_EN_CHANGE(IDC_PATH, OnChangePath)
  50. ON_EN_CHANGE(IDC_DESCRIPTION, OnChangeDescription)
  51. ON_BN_CLICKED(IDC_CHECK1, OnChangeShow)
  52. ON_CBN_SELCHANGE(IDC_DEPLOY, OnSelchangeDeploy)
  53. ON_CBN_SELCHANGE(IDC_OS, OnChangeOS)
  54. ON_CBN_SELCHANGE(IDC_CPU, OnChangeCPU)
  55. ON_EN_CHANGE(IDC_VERSION, OnChangeVersion)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. BOOL CGeneralPage::OnApply()
  59. {
  60. #if 0
  61. if (m_pIAppManagerActions == NULL || m_pIClassAdmin == NULL)
  62. {
  63. return FALSE;
  64. }
  65. // put up an hourglass (this could take a while)
  66. CHourglass hourglass;
  67. CString szNewScriptPath;
  68. CString szOldScriptPath;
  69. HRESULT hr;
  70. if (m_bUpdate == TRUE)
  71. {
  72. PACKAGEDETAIL NewDetails;
  73. hr = m_pIClassAdmin->GetPackageDetails(m_pData->szName,
  74. &NewDetails.InstallInfo,
  75. &NewDetails.PlatformInfo);
  76. memcpy(&NewDetails, m_pData->pDetails, sizeof(PACKAGEDETAIL));
  77. // UNDONE - validate the data
  78. NewDetails.pszPackageName = (LPOLESTR) ((LPCTSTR)m_szName);
  79. swscanf((LPOLESTR)((LPCTSTR)m_szVer), _T("%u.%u"),&(NewDetails.Platform.dwVersionHi),&(NewDetails.Platform.dwVersionLo));
  80. NewDetails.Platform.dwPlatformId = m_cbOS.GetCurSel();
  81. NewDetails.Platform.dwProcessorArch = m_cbCPU.GetCurSel() == 1 ? PROCESSOR_ARCHITECTURE_ALPHA : PROCESSOR_ARCHITECTURE_INTEL;
  82. NewDetails.dwActFlags = (m_pData->pDetails->dwActFlags & (! (ACTFLG_Published | ACTFLG_Assigned | ACTFLG_UserInstall)));
  83. BOOL fAssign = FALSE;
  84. if (m_szDeploy == m_szPublished)
  85. {
  86. NewDetails.dwActFlags |= ACTFLG_Published;
  87. }
  88. else
  89. {
  90. NewDetails.dwActFlags |= ACTFLG_Assigned;
  91. fAssign = TRUE;
  92. }
  93. NewDetails.dwActFlags |= ((!m_fShow) ? 0 : ACTFLG_UserInstall);
  94. BOOL fMoveScript = (NewDetails.dwActFlags & (ACTFLG_Assigned | ACTFLG_Published))
  95. != (m_pData->pDetails->dwActFlags & (ACTFLG_Assigned | ACTFLG_Published))
  96. || (NewDetails.Platform.dwProcessorArch != m_pData->pDetails->Platform.dwProcessorArch);
  97. if (fMoveScript)
  98. {
  99. // Find out if script file can in fact be moved
  100. BOOL fCanMoveScript = FALSE;
  101. szOldScriptPath = m_pData->szPath;
  102. CString szTemp = szOldScriptPath;
  103. szTemp.MakeLower();
  104. int i = szTemp.Find(_T("\\published\\"));
  105. if (i < 0)
  106. {
  107. i = szTemp.Find(_T("\\assigned\\")); // cover all the bases
  108. }
  109. if (i >= 0)
  110. {
  111. // finally make sure it's got an .aas extension
  112. if (szTemp.Right(4) == _T(".aas"))
  113. {
  114. DWORD dwAttributes = GetFileAttributes(m_pData->szPath);
  115. if ((dwAttributes != 0xffffffff) && ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0))
  116. {
  117. fCanMoveScript = TRUE;
  118. }
  119. }
  120. }
  121. if (fCanMoveScript)
  122. {
  123. // Build new path
  124. szNewScriptPath = szOldScriptPath;
  125. // Strip off everything up to "\\published" or "\\assigned"
  126. szNewScriptPath = szNewScriptPath.Left(i);
  127. szNewScriptPath +=
  128. (NewDetails.dwActFlags & ACTFLG_Assigned) != 0
  129. ? _T("\\Assigned") : _T("\\Published");
  130. szNewScriptPath +=
  131. NewDetails.Platform.dwProcessorArch == PROCESSOR_ARCHITECTURE_ALPHA
  132. ? _T("\\Alpha\\") : _T("\\x86\\");
  133. {
  134. TCHAR Name [_MAX_FNAME];
  135. TCHAR Ext [_MAX_EXT];
  136. TCHAR ScriptNameAndPath[_MAX_PATH ];
  137. _tsplitpath( szOldScriptPath, NULL, NULL, Name, Ext );
  138. szNewScriptPath += Name;
  139. szNewScriptPath += Ext;
  140. }
  141. // Try and move it
  142. if (!MoveFileEx(szOldScriptPath,
  143. szNewScriptPath,
  144. MOVEFILE_COPY_ALLOWED|MOVEFILE_WRITE_THROUGH))
  145. {
  146. // wasn't moved
  147. fMoveScript = FALSE;
  148. // UNDONE - put up a message that the scrip file wasn't moved?
  149. }
  150. else
  151. {
  152. m_pData->szPath = szNewScriptPath;
  153. NewDetails.pszScriptPath = (LPOLESTR)(LPCOLESTR)m_pData->szPath;
  154. }
  155. }
  156. else
  157. {
  158. // wasn't moved so make sure we don't try and move it back later
  159. fMoveScript = FALSE;
  160. }
  161. }
  162. NewDetails.pszProductName = (LPOLESTR) ((LPCTSTR)m_szDescription);
  163. BOOL fPathChanged = m_szPath != m_pData->szPath;
  164. if (fPathChanged)
  165. {
  166. // user changed the path
  167. NewDetails.pszScriptPath = (LPOLESTR)((LPCTSTR)m_szPath);
  168. }
  169. hr = m_pIClassAdmin->DeletePackage(m_pData->pDetails->pszPackageName);
  170. if (SUCCEEDED(hr))
  171. {
  172. hr = m_pIClassAdmin->AddPackage(m_szName, &NewDetails);
  173. }
  174. if (FAILED(hr))
  175. {
  176. if (fMoveScript)
  177. {
  178. // changed location for deployment back to what it was
  179. // before we failed to change the info in the class store
  180. // (Note that we're assuming that if we could change it one way
  181. // we can change it back.)
  182. if (MoveFileEx(szNewScriptPath,
  183. szOldScriptPath,
  184. MOVEFILE_COPY_ALLOWED|MOVEFILE_WRITE_THROUGH))
  185. {
  186. m_pData->szPath = szOldScriptPath;
  187. m_pData->pDetails->pszScriptPath = (LPOLESTR)(LPCOLESTR)m_pData->szPath;
  188. }
  189. }
  190. hr = m_pIClassAdmin->AddPackage(m_szName, m_pData->pDetails);
  191. // need to move this message
  192. ::MessageBox(NULL,
  193. L"Couldn't apply changes. Verify that the class store's server is active.",
  194. L"ERROR",
  195. MB_OK);
  196. return FALSE;
  197. }
  198. else
  199. {
  200. if (fMoveScript)
  201. {
  202. // Notify clients of change
  203. if (m_pIAppManagerActions)
  204. {
  205. m_pIAppManagerActions->NotifyClients(FALSE);
  206. }
  207. }
  208. }
  209. memcpy(m_pData->pDetails, &NewDetails, sizeof(PACKAGEDETAIL));
  210. if (m_pData->pDetails->dwActFlags & ACTFLG_Assigned)
  211. {
  212. m_pData->type = DT_ASSIGNED;
  213. }
  214. else
  215. {
  216. m_pData->type = DT_PUBLISHED;
  217. }
  218. m_pData->szType = m_szDeploy;
  219. // Up above, we set NewDetails.pszPackageName to m_szName.
  220. // We can't leave it set to that because m_szName is a member
  221. // variable of this property sheet class object and will be released
  222. // when the property sheet goes away. We need to copy it to
  223. // m_pData->szName (which is a CString and therefore has it's own
  224. // memory store) and then set the details back to it so it doesn't
  225. // get freed from under us.
  226. m_pData->szName = m_szName;
  227. m_pData->pDetails->pszPackageName = (LPOLESTR)((LPCTSTR)m_pData->szName);
  228. // same problem with szDesc
  229. m_pData->szDesc = m_szDescription;
  230. m_pData->pDetails->pszProductName = (LPOLESTR)((LPCTSTR)m_pData->szDesc);
  231. if (fPathChanged)
  232. {
  233. m_pData->szPath = m_szPath;
  234. m_pData->pDetails->pszScriptPath = (LPOLESTR)((LPCTSTR)m_pData->szPath);
  235. }
  236. if (m_szPath != m_pData->szPath)
  237. {
  238. // user changed the path
  239. m_pData->szPath = m_szPath;
  240. m_pData->pDetails->pszScriptPath = (LPOLESTR)((LPCTSTR)m_pData->szPath);
  241. }
  242. SetStringData(m_pData);
  243. MMCPropertyChangeNotify(m_hConsoleHandle, (long) m_cookie);
  244. m_bUpdate = FALSE;
  245. }
  246. #endif
  247. return CPropertyPage::OnApply();
  248. }
  249. BOOL CGeneralPage::OnInitDialog()
  250. {
  251. TCHAR szBuffer[256];
  252. m_szName = m_pData->pDetails->pszPackageName;
  253. m_szDescription = _T("");
  254. m_szLocale = _T("");
  255. m_szPath = m_pData->pDetails->pInstallInfo->pszScriptPath;
  256. m_szDeploy = _T("");
  257. // wsprintf(szBuffer, _T("%u.%u"), m_pData->pDetails->Platform.dwVersionHi, m_pData->pDetails->Platform.dwVersionLo);
  258. m_szVer = szBuffer;
  259. m_fShow = m_pData->pDetails->pInstallInfo->dwActFlags & ACTFLG_UserInstall ? 1 : 0;
  260. CPropertyPage::OnInitDialog();
  261. // unmarshal the IAppManagerActions interface
  262. HRESULT hr = CoGetInterfaceAndReleaseStream(m_pIStreamAM, IID_IAppManagerActions, (void **) &m_pIAppManagerActions);
  263. if (!SUCCEEDED(hr))
  264. {
  265. #if DBG == 1
  266. ::MessageBox(NULL,
  267. L"Couldn't marshal IAppManagerActions",
  268. L"DEBUG ERROR",
  269. MB_OK);
  270. #endif
  271. m_pIAppManagerActions = NULL;
  272. return FALSE;
  273. // BUGBUG - what should I do here? Disallow changes?
  274. }
  275. // unmarshal the IClassAdmin interface
  276. hr = CoGetInterfaceAndReleaseStream(m_pIStream, IID_IClassAdmin, (void **) &m_pIClassAdmin);
  277. if (!SUCCEEDED(hr))
  278. {
  279. #if DBG == 1
  280. ::MessageBox(NULL,
  281. L"Couldn't marshal IClassAdmin",
  282. L"DEBUG ERROR",
  283. MB_OK);
  284. #endif
  285. m_pIClassAdmin = NULL;
  286. // BUGBUG - what should I do here? Disallow changes?
  287. }
  288. ::LoadString(ghInstance, IDS_ASSIGNED, szBuffer, 256);
  289. m_szAssigned = szBuffer;
  290. // Test to be sure it can be assigned.
  291. // If it's not a Darwin package then it can't be assigned and
  292. // the option won't even be presented to the user.
  293. if (m_pIAppManagerActions)
  294. {
  295. hr = m_pIAppManagerActions->CanPackageBeAssigned(m_cookie);
  296. }
  297. if (hr == ERROR_SUCCESS)
  298. {
  299. m_cbDeploy.AddString(szBuffer);
  300. }
  301. ::LoadString(ghInstance, IDS_PUBLISHED, szBuffer, 256);
  302. m_szPublished = szBuffer;
  303. m_cbDeploy.AddString(szBuffer);
  304. m_cbDeploy.SelectString(0, m_szDeploy);
  305. #if 0
  306. int i;
  307. for (i = 0; i < (sizeof(m_rgszOS) / sizeof(m_rgszOS[0])); i++)
  308. {
  309. ::LoadString(ghInstance, IDS_OS + i + 1, szBuffer, 256);
  310. m_rgszOS[i] = szBuffer;
  311. m_cbOS.AddString(szBuffer);
  312. }
  313. m_cbOS.SetCurSel(m_pData->pDetails->Platform.dwPlatformId);
  314. for (i = 0; i < (sizeof(m_rgszCPU) / sizeof(m_rgszCPU[0])); i++)
  315. {
  316. ::LoadString(ghInstance, IDS_HW + (i == 0 ? PROCESSOR_ARCHITECTURE_INTEL : PROCESSOR_ARCHITECTURE_ALPHA), szBuffer, 256);
  317. m_rgszCPU[i] = szBuffer;
  318. m_cbCPU.AddString(szBuffer);
  319. }
  320. m_cbCPU.SetCurSel(m_pData->pDetails->Platform.dwProcessorArch == PROCESSOR_ARCHITECTURE_ALPHA ? 1 : 0);
  321. #endif
  322. return TRUE; // return TRUE unless you set the focus to a control
  323. // EXCEPTION: OCX Property Pages should return FALSE
  324. }
  325. void CGeneralPage::OnChangeShow()
  326. {
  327. // TODO: If this is a RICHEDIT control, the control will not
  328. // send this notification unless you override the CPropertyPage::OnInitDialog()
  329. // function to send the EM_SETEVENTMASK message to the control
  330. // with the ENM_CHANGE flag ORed into the lParam mask.
  331. // TODO: Add your control notification handler code here
  332. SetModified();
  333. m_bUpdate = TRUE;
  334. }
  335. void CGeneralPage::OnChangePath()
  336. {
  337. SetModified();
  338. m_bUpdate = TRUE;
  339. }
  340. void CGeneralPage::OnChangeCPU()
  341. {
  342. SetModified();
  343. m_bUpdate = TRUE;
  344. }
  345. void CGeneralPage::OnChangeOS()
  346. {
  347. TCHAR * rgszVer[] =
  348. {
  349. _T("3.1"),
  350. _T("4.1"),
  351. _T("5.0")
  352. };
  353. int i = m_cbOS.GetCurSel();
  354. m_szVer = rgszVer[i];
  355. GetDlgItem(IDC_VERSION)->SetWindowText(m_szVer);
  356. SetModified();
  357. m_bUpdate = TRUE;
  358. }
  359. void CGeneralPage::OnChangeVersion()
  360. {
  361. SetModified();
  362. m_bUpdate = TRUE;
  363. }
  364. void CGeneralPage::OnChangeName()
  365. {
  366. // TODO: If this is a RICHEDIT control, the control will not
  367. // send this notification unless you override the CPropertyPage::OnInitDialog()
  368. // function to send the EM_SETEVENTMASK message to the control
  369. // with the ENM_CHANGE flag ORed into the lParam mask.
  370. // TODO: Add your control notification handler code here
  371. SetModified();
  372. m_bUpdate = TRUE;
  373. }
  374. void CGeneralPage::OnChangeDescription()
  375. {
  376. // TODO: If this is a RICHEDIT control, the control will not
  377. // send this notification unless you override the CPropertyPage::OnInitDialog()
  378. // function to send the EM_SETEVENTMASK message to the control
  379. // with the ENM_CHANGE flag ORed into the lParam mask.
  380. // TODO: Add your control notification handler code here
  381. SetModified();
  382. m_bUpdate = TRUE;
  383. }
  384. void CGeneralPage::OnSelchangeDeploy()
  385. {
  386. // TODO: Add your control notification handler code here
  387. SetModified();
  388. m_bUpdate = TRUE;
  389. }