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.

438 lines
16 KiB

  1. #include "precomp.h"
  2. #include <admparse.h>
  3. #define NUM_ICONS 3
  4. extern TCHAR g_szCustIns[MAX_PATH];
  5. extern TCHAR g_szBuildRoot[MAX_PATH];
  6. extern TCHAR g_szWizRoot[MAX_PATH];
  7. extern TCHAR g_szLoadedIns[MAX_PATH];
  8. extern TCHAR g_szTempSign[MAX_PATH];
  9. extern TCHAR g_szTitle[MAX_PATH];
  10. extern TCHAR g_szLanguage[16];
  11. extern BOOL g_fBranded, g_fIntranet;
  12. extern PROPSHEETPAGE g_psp[NUM_PAGES];
  13. extern int g_iCurPage;
  14. static int s_ADMOpen, s_ADMClose, s_ADMCategory;
  15. DWORD g_dwADMPlatformId = PLATFORM_WIN32;
  16. // Creates image list, adds 3 bitmaps to it, and associates the image
  17. // list with the treeview control.
  18. LRESULT InitImageList(HWND hTreeView)
  19. {
  20. HIMAGELIST hWndImageList;
  21. HICON hIcon;
  22. hWndImageList = ImageList_Create(GetSystemMetrics (SM_CXSMICON),
  23. GetSystemMetrics (SM_CYSMICON),
  24. TRUE,
  25. NUM_ICONS,
  26. 3);
  27. if(!hWndImageList)
  28. {
  29. return FALSE;
  30. }
  31. hIcon = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_ICON2));
  32. s_ADMOpen = ImageList_AddIcon(hWndImageList, hIcon);
  33. DestroyIcon(hIcon);
  34. hIcon = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_ICON3));
  35. s_ADMClose = ImageList_AddIcon(hWndImageList, hIcon);
  36. DestroyIcon(hIcon);
  37. hIcon = LoadIcon(g_rvInfo.hInst, MAKEINTRESOURCE(IDI_ICON4));
  38. s_ADMCategory = ImageList_AddIcon(hWndImageList, hIcon);
  39. DestroyIcon(hIcon);
  40. // Fail if not all images were added.
  41. if (ImageList_GetImageCount(hWndImageList) < NUM_ICONS)
  42. {
  43. // ERROR: Unable to add all images to image list.
  44. return FALSE;
  45. }
  46. // Associate image list with treeView control.
  47. TreeView_SetImageList(hTreeView, hWndImageList, TVSIL_NORMAL);
  48. return TRUE;
  49. }
  50. void DeleteOldAdmFiles(LPCTSTR pcszImportIns, LPCTSTR pcszBrandDir)
  51. {
  52. TCHAR szBuf[8];
  53. TCHAR szFile[MAX_PATH];
  54. LPTSTR pszDot;
  55. HANDLE hFind;
  56. WIN32_FIND_DATA fd;
  57. GetPrivateProfileString(BRANDING, LANG_LOCALE, TEXT("EN"), szBuf, countof(szBuf), pcszImportIns);
  58. PathCombine(szFile, g_szWizRoot, TEXT("policies"));
  59. PathAppend(szFile, szBuf); // language
  60. PathAppend(szFile, TEXT("*.adm"));
  61. if ((hFind = FindFirstFile(szFile, &fd)) != INVALID_HANDLE_VALUE)
  62. {
  63. do
  64. {
  65. StrCpy(szFile, fd.cFileName);
  66. if ((pszDot = StrRChr(szFile, NULL, TEXT('.'))) != NULL)
  67. {
  68. *pszDot = TEXT('\0');
  69. WritePrivateProfileString(IS_EXTREGINF, szFile, NULL, g_szCustIns);
  70. StrCpy(pszDot, TEXT(".inf"));
  71. DeleteFileInDir(szFile, pcszBrandDir);
  72. }
  73. } while (FindNextFile(hFind, &fd));
  74. }
  75. }
  76. // FUNCTION: ADMParse(HWND, UINT, UINT, LONG)
  77. //
  78. // PURPOSE: Processes messages for ADM page
  79. //
  80. // MESSAGES:
  81. //
  82. // WM_INITDIALOG - intializes the page
  83. // WM_NOTIFY - processes the notifications sent to the page
  84. // WM_COMMAND - saves the id of the choice selected
  85. INT_PTR CALLBACK ADMParse(
  86. HWND hDlg,
  87. UINT message,
  88. WPARAM wParam,
  89. LPARAM lParam)
  90. {
  91. HWND hTreeView = GetDlgItem(hDlg, IDC_ADMTREE);
  92. LPNM_TREEVIEW lpNMTreeView = (LPNM_TREEVIEW) lParam;
  93. TV_ITEM tvitem, tvitem1;
  94. HTREEITEM hItem;
  95. HTREEITEM hParentItem;
  96. TCHAR szMessage[512];
  97. TCHAR szTemp[MAX_PATH];
  98. RECT rect;
  99. RECT rectDlg;
  100. RECT rectDscr;
  101. static TCHAR szWorkDir[MAX_PATH];
  102. switch (message)
  103. {
  104. case WM_INITDIALOG:
  105. InitSysFont( hDlg, IDC_ADMTREE);
  106. g_hWizard = hDlg;
  107. InitImageList(hTreeView);
  108. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), FALSE);
  109. #ifdef UNICODE
  110. TreeView_SetUnicodeFormat(hTreeView, TRUE);
  111. #else
  112. TreeView_SetUnicodeFormat(hTreeView, FALSE);
  113. #endif
  114. break;
  115. case IDM_BATCHADVANCE:
  116. DoBatchAdvance(hDlg);
  117. break;
  118. case WM_HELP:
  119. IeakPageHelp(hDlg, g_psp[g_iCurPage].pszTemplate);
  120. break;
  121. case WM_COMMAND:
  122. switch (HIWORD(wParam))
  123. {
  124. case BN_CLICKED:
  125. switch (LOWORD(wParam))
  126. {
  127. case IDC_ADMIMPORT:
  128. wnsprintf(szTemp, countof(szTemp), TEXT("%sPolicies%s"), g_szWizRoot, g_szLanguage);
  129. ImportADMFile(hDlg, hTreeView, szTemp, szWorkDir, GetRole(g_fBranded, g_fIntranet), g_szCustIns);
  130. if((hItem = TreeView_GetSelection(hTreeView)) == NULL ||
  131. TreeView_GetParent(hTreeView, hItem) != NULL ||
  132. !CanDeleteADM(hTreeView, hItem)) {
  133. EnsureDialogFocus(hDlg, IDC_ADMDELETE, IDC_ADMIMPORT);
  134. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), FALSE);
  135. }
  136. else
  137. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), TRUE);
  138. break;
  139. case IDC_ADMDELETE:
  140. LoadString(g_rvInfo.hInst, IDS_ADMDELWARN, szMessage, countof(szMessage));
  141. if(MessageBox(hDlg, szMessage, g_szTitle, MB_ICONQUESTION|MB_YESNO) == IDYES)
  142. {
  143. hItem = TreeView_GetSelection(hTreeView);
  144. DeleteADMItem(hTreeView, hItem, szWorkDir, g_szCustIns, TRUE, TRUE);
  145. if ((hItem = TreeView_GetSelection(hTreeView)) == NULL ||
  146. TreeView_GetParent(hTreeView, hItem) != NULL ||
  147. !CanDeleteADM(hTreeView, hItem)) {
  148. EnsureDialogFocus(hDlg, IDC_ADMDELETE, IDC_ADMIMPORT);
  149. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), FALSE);
  150. }
  151. else
  152. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), TRUE);
  153. }
  154. break;
  155. }
  156. break;
  157. }
  158. break;
  159. case WM_NOTIFY:
  160. switch (((NMHDR FAR *) lParam)->code)
  161. {
  162. case PSN_HELP:
  163. IeakPageHelp(hDlg, g_psp[g_iCurPage].pszTemplate);
  164. break;
  165. case PSN_SETACTIVE:
  166. SetBannerText(hDlg);
  167. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  168. GetWindowRect(hDlg, &rectDlg);
  169. GetWindowRect(GetDlgItem(hDlg, IDC_ADMINSTR), &rect);
  170. rectDscr.left = rect.left - rectDlg.left + 1;
  171. rectDscr.top = rect.top - rectDlg.top + 1;
  172. rectDscr.right = rectDscr.left + (rect.right - rect.left) - 2;
  173. rectDscr.bottom = rectDscr.top + (rect.bottom - rect.top) - 2;
  174. CreateADMWindow(hTreeView, GetDlgItem(hDlg, IDC_ADMDELETE), rectDscr.left,
  175. rectDscr.top, rectDscr.right - rectDscr.left,
  176. rectDscr.bottom - rectDscr.top);
  177. wnsprintf(szTemp, countof(szTemp), TEXT("%sPolicies%s"), g_szWizRoot, g_szLanguage);
  178. PathCombine(szWorkDir, g_szBuildRoot, TEXT("INS"));
  179. PathAppend(szWorkDir, GetOutputPlatformDir());
  180. PathAppend(szWorkDir, g_szLanguage);
  181. PathRemoveBackslash(szWorkDir);
  182. {
  183. CNewCursor cur(IDC_WAIT);
  184. int nRole = GetRole(g_fBranded, g_fIntranet);
  185. if(!LoadADMFiles(hTreeView, NULL, szTemp, szWorkDir, g_dwADMPlatformId, nRole,
  186. s_ADMClose, s_ADMCategory))
  187. {
  188. EnableWindow(GetDlgItem(hDlg, IDC_ADMIMPORT), FALSE);
  189. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), FALSE);
  190. }
  191. else
  192. {
  193. EnableWindow(GetDlgItem(hDlg, IDC_ADMIMPORT), TRUE);
  194. if(TreeView_GetSelection(hTreeView) == NULL)
  195. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), FALSE);
  196. else
  197. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), TRUE);
  198. }
  199. // delete old adm files from an imported ins file
  200. if (GetPrivateProfileInt(IS_BRANDING, TEXT("DeleteAdms"), 0, g_szCustIns))
  201. {
  202. TCHAR szImportInsFile[MAX_PATH];
  203. if (ISNULL(g_szLoadedIns))
  204. {
  205. GetPrivateProfileString(IS_BRANDING, TEXT("ImportIns"), TEXT(""),
  206. szImportInsFile, countof(szImportInsFile), g_szCustIns);
  207. }
  208. else
  209. StrCpy(szImportInsFile, g_szLoadedIns);
  210. // only do process if we got the path of the ins file and extreginf section
  211. // is not empty
  212. if (ISNONNULL(szImportInsFile) &&
  213. !InsIsSectionEmpty(IS_EXTREGINF, szImportInsFile))
  214. DeleteOldAdmFiles(szImportInsFile, g_szTempSign);
  215. }
  216. }
  217. CheckBatchAdvance(hDlg);
  218. break;
  219. case PSN_WIZBACK:
  220. case PSN_WIZNEXT:
  221. DeleteADMItems(hTreeView, szWorkDir, g_szCustIns, TRUE);
  222. TreeView_DeleteAllItems(hTreeView);
  223. DestroyADMWindow(hTreeView);
  224. g_iCurPage = PPAGE_ADM;
  225. EnablePages();
  226. if (((NMHDR FAR *) lParam)->code == PSN_WIZNEXT)
  227. PageNext(hDlg);
  228. else
  229. PagePrev(hDlg);
  230. break;
  231. case PSN_QUERYCANCEL:
  232. if(QueryCancel(hDlg) == TRUE)
  233. {
  234. DeleteADMItems(hTreeView, szWorkDir, g_szCustIns, FALSE);
  235. DestroyADMWindow(hTreeView);
  236. }
  237. break;
  238. case TVN_SELCHANGED:
  239. hParentItem = TreeView_GetParent(hTreeView, lpNMTreeView->itemNew.hItem);
  240. SelectADMItem(hDlg, hTreeView, &lpNMTreeView->itemOld, FALSE, FALSE);
  241. // display the information for the newly selected item
  242. DisplayADMItem(hDlg, hTreeView, &lpNMTreeView->itemNew, FALSE);
  243. if (hParentItem != NULL ||
  244. (lpNMTreeView->itemNew.hItem != NULL && !CanDeleteADM(hTreeView, lpNMTreeView->itemNew.hItem))) {
  245. EnsureDialogFocus(hDlg, IDC_ADMDELETE, IDC_ADMIMPORT);
  246. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), FALSE);
  247. }
  248. else
  249. EnableWindow(GetDlgItem(hDlg, IDC_ADMDELETE), TRUE);
  250. break;
  251. case TVN_ITEMEXPANDED:
  252. tvitem.mask = TVIF_IMAGE;
  253. tvitem.hItem = lpNMTreeView->itemNew.hItem;
  254. TreeView_GetItem(hTreeView, &tvitem);
  255. // If tree item is EXPANDING (opening up) and
  256. // current icon == CloseFolder, change icon to OpenFolder
  257. if((lpNMTreeView->action == TVE_EXPAND) &&
  258. (tvitem.iImage == s_ADMClose))
  259. {
  260. tvitem1.hItem = lpNMTreeView->itemNew.hItem;
  261. tvitem1.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  262. tvitem1.iImage = s_ADMOpen;
  263. tvitem1.iSelectedImage = s_ADMOpen;
  264. TreeView_SetItem(hTreeView, &tvitem1);
  265. }
  266. // If tree item is COLLAPSING (closing up) and
  267. // current icon == OpenFolder, change icon to CloseFolder
  268. else if((lpNMTreeView->action == TVE_COLLAPSE) &&
  269. (tvitem.iImage == s_ADMOpen))
  270. {
  271. tvitem1.hItem = lpNMTreeView->itemNew.hItem;
  272. tvitem1.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  273. tvitem1.iImage = s_ADMClose;
  274. tvitem1.iSelectedImage = s_ADMClose;
  275. TreeView_SetItem(hTreeView, &tvitem1);
  276. }
  277. break;
  278. default:
  279. return FALSE;
  280. }
  281. break;
  282. default:
  283. return FALSE;
  284. }
  285. return TRUE;
  286. }
  287. // Indicates whether to display/hide the adm page in the wizard
  288. // If the correct Roles are set or no Roles set at all in the adm file,
  289. // the page is displayed
  290. BOOL ADMEnablePage()
  291. {
  292. TCHAR szFileName[MAX_PATH];
  293. TCHAR szFilePath[MAX_PATH];
  294. WIN32_FIND_DATA FindFileData;
  295. wnsprintf(szFilePath, countof(szFilePath), TEXT("%sPolicies%s*.adm"), g_szWizRoot, g_szLanguage);
  296. HANDLE hFind = FindFirstFile(szFilePath, &FindFileData);
  297. if(hFind != INVALID_HANDLE_VALUE)
  298. {
  299. do
  300. {
  301. wnsprintf(szFileName, countof(szFileName), TEXT("%sPolicies%s%s"), g_szWizRoot, g_szLanguage, FindFileData.cFileName);
  302. if(IsADMFileVisible(szFileName, GetRole(g_fBranded, g_fIntranet), g_dwADMPlatformId))
  303. {
  304. FindClose(hFind);
  305. return TRUE;
  306. }
  307. }while(FindNextFile(hFind, &FindFileData));
  308. FindClose(hFind);
  309. }
  310. return FALSE;
  311. }
  312. INT_PTR CALLBACK ADMDesc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  313. {
  314. UNREFERENCED_PARAMETER(wParam);
  315. switch (message)
  316. {
  317. case IDM_BATCHADVANCE:
  318. DoBatchAdvance(hDlg);
  319. break;
  320. case WM_HELP:
  321. IeakPageHelp(hDlg, g_psp[g_iCurPage].pszTemplate);
  322. break;
  323. case WM_INITDIALOG:
  324. return(FALSE);
  325. case WM_COMMAND:
  326. switch (LOWORD(wParam))
  327. {
  328. case IDC_ADMWIN32:
  329. g_dwADMPlatformId = PLATFORM_WIN32;
  330. break;
  331. case IDC_ADMWIN2K:
  332. g_dwADMPlatformId = PLATFORM_W2K;
  333. break;
  334. }
  335. break;
  336. case WM_NOTIFY:
  337. switch (((NMHDR FAR *) lParam)->code)
  338. {
  339. case PSN_HELP:
  340. IeakPageHelp(hDlg, g_psp[g_iCurPage].pszTemplate);
  341. break;
  342. case PSN_SETACTIVE:
  343. SetBannerText(hDlg);
  344. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_BACK | PSWIZB_NEXT);
  345. if (InsGetBool(IS_ADM, IK_ADMIN, 1, g_szCustIns))
  346. {
  347. CheckRadioButton(hDlg, IDC_ADMWIN32, IDC_ADMWIN2K, IDC_ADMWIN32);
  348. g_dwADMPlatformId = PLATFORM_WIN32;
  349. }
  350. else
  351. {
  352. CheckRadioButton(hDlg, IDC_ADMWIN32, IDC_ADMWIN2K, IDC_ADMWIN2K);
  353. g_dwADMPlatformId = PLATFORM_W2K;
  354. }
  355. CheckBatchAdvance(hDlg);
  356. break;
  357. case PSN_WIZBACK:
  358. case PSN_WIZNEXT:
  359. InsWriteBoolEx(IS_ADM, IK_ADMIN, (g_dwADMPlatformId == PLATFORM_WIN32) ? 1 : 0, g_szCustIns);
  360. InsFlushChanges(g_szCustIns);
  361. g_iCurPage = PPAGE_ADMDESC;
  362. EnablePages();
  363. if (((NMHDR FAR *) lParam)->code == PSN_WIZNEXT)
  364. PageNext(hDlg);
  365. else
  366. PagePrev(hDlg);
  367. break;
  368. case PSN_QUERYCANCEL:
  369. QueryCancel(hDlg);
  370. break;
  371. }
  372. break;
  373. default:
  374. return FALSE;
  375. }
  376. return TRUE;
  377. }