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.

1565 lines
54 KiB

  1. // adm.cpp
  2. #include "precomp.h"
  3. #include "admparse.h"
  4. #include "adm.h"
  5. typedef struct Category
  6. {
  7. LPTSTR pszName;
  8. HWND hWnd;
  9. HKEY hKeyClass;
  10. LPVOID pData;
  11. BOOL fRSoPMode;
  12. } ADMCategory;
  13. typedef struct ADM
  14. {
  15. LPTSTR pszName;
  16. TCHAR szFileName[MAX_PATH];
  17. DWORD dwAdm;
  18. LPVOID pData;
  19. } ADMFile;
  20. #define ADM_DSCRLEN 32767
  21. #define ADM_DSCRLINELEN 100
  22. #define ADM_TITLELEN 100
  23. TCHAR g_szLogFileName[MAX_PATH];
  24. HTREEITEM g_hPolicyRootItem = NULL; // only used by profile manager
  25. int g_ADMClose, g_ADMCategory;
  26. #define GetFirstPolicyItem(hTreeView) ((g_hPolicyRootItem != NULL) ? TreeView_GetChild(hTreeView, g_hPolicyRootItem) : TreeView_GetRoot(hTreeView))
  27. #define PolicyRoot() ((g_hPolicyRootItem != NULL) ? g_hPolicyRootItem : NULL)
  28. #define IsWizard() ((g_hPolicyRootItem == NULL) ? TRUE : FALSE)
  29. // private helper functions
  30. static HFONT getBoldFont(HWND hWnd);
  31. static BOOL isADMFileVisibleHelper(LPCTSTR pcszFileName, int nRole, DWORD dwPlatformId);
  32. static BOOL loadADMFilesHelper(HWND hTreeView, HTREEITEM hPolicyRootItem,
  33. LPCTSTR pcszADMFilePath, LPCTSTR pcszWorkDir,
  34. DWORD dwPlatformId, int nRole,
  35. int nIconADMClose, int nIconADMCategory);
  36. static void deleteADMItemHelper(HWND hTreeView, HTREEITEM hParentItem, LPCTSTR pcszWorkDir,
  37. LPCTSTR pcszInsFile, BOOL bDeleteFile, BOOL bSave);
  38. static void deleteADMItemsHelper(HWND hTreeView, LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile,
  39. BOOL bSave);
  40. static void getADMDescriptionTitle(LPCTSTR pcszFileName, LPTSTR pszDscrTitle);
  41. static void getADMDescription(LPCTSTR pcszFileName, LPTSTR pszDscr);
  42. static void importADMFileHelper(HWND hMainWnd, HWND hTreeView, LPCTSTR pcszADMFilePath,
  43. LPCTSTR pcszWorkDir, int nRole, LPCTSTR pcszInsFile);
  44. static void resetAdmFilesHelper(HWND hTreeView, LPCTSTR pcszWorkDir, BOOL bReset);
  45. static void saveAdmFilesHelper(HWND hTreeView, LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile);
  46. static INT_PTR CALLBACK logDialogProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM);
  47. static BOOL getAdmFileListHelper(LPRESULTITEM* pResultItems, int* pnResultItems, int nRole);
  48. static HTREEITEM addADMItemHelper(HWND hTreeView, LPCTSTR pcszADMFilePath, LPCTSTR pcszFileName,
  49. LPCTSTR pcszWorkDir, int nRole, BSTR bstrRSoPNamespace);
  50. void WINAPI CreateADMWindow(HWND hOwner, HWND hWndInsertAfter, int nXPos, int nYPos,
  51. int nWidth, int nHeight)
  52. {
  53. CDscrWnd* pDscrWnd = new CDscrWnd;
  54. if (pDscrWnd != NULL)
  55. {
  56. SetWindowLongPtr(hOwner, GWLP_USERDATA, (LONG_PTR)pDscrWnd);
  57. pDscrWnd->Create(GetParent(hOwner), hWndInsertAfter, nXPos, nYPos, nWidth, nHeight);
  58. }
  59. }
  60. void WINAPI ShowADMWindow(HWND hOwner, BOOL fShow)
  61. {
  62. CDscrWnd* pDscrWnd = (CDscrWnd*)GetWindowLongPtr(hOwner, GWLP_USERDATA);
  63. if (pDscrWnd != NULL)
  64. pDscrWnd->ShowWindow(fShow);
  65. }
  66. void WINAPI MoveADMWindow(HWND hOwner, int nXPos, int nYPos, int nWidth, int nHeight)
  67. {
  68. CDscrWnd* pDscrWnd = (CDscrWnd*)GetWindowLongPtr(hOwner, GWLP_USERDATA);
  69. if (pDscrWnd != NULL)
  70. pDscrWnd->MoveWindow(nXPos, nYPos, nWidth, nHeight);
  71. }
  72. void WINAPI SetADMWindowTextA(HWND hOwner, LPCSTR pcszTitle, LPCSTR pcszText,
  73. BOOL fUpdateWindowState /* = TRUE */)
  74. {
  75. USES_CONVERSION;
  76. CDscrWnd* pDscrWnd = (CDscrWnd*)GetWindowLongPtr(hOwner, GWLP_USERDATA);
  77. if (pDscrWnd != NULL)
  78. pDscrWnd->SetText(A2CT(pcszTitle), A2CT(pcszText), fUpdateWindowState);
  79. }
  80. void WINAPI SetADMWindowTextW(HWND hOwner, LPCWSTR pcwszTitle, LPCWSTR pcwszText,
  81. BOOL fUpdateWindowState /* = TRUE */)
  82. {
  83. USES_CONVERSION;
  84. CDscrWnd* pDscrWnd = (CDscrWnd*)GetWindowLongPtr(hOwner, GWLP_USERDATA);
  85. if (pDscrWnd != NULL)
  86. pDscrWnd->SetText(W2CT(pcwszTitle), W2CT(pcwszText), fUpdateWindowState);
  87. }
  88. void WINAPI DestroyADMWindow(HWND hOwner)
  89. {
  90. CDscrWnd* pDscrWnd = (CDscrWnd*)GetWindowLongPtr(hOwner, GWLP_USERDATA);
  91. if (pDscrWnd != NULL)
  92. {
  93. delete pDscrWnd;
  94. SetWindowLongPtr(hOwner, GWLP_USERDATA, 0L);
  95. }
  96. }
  97. BOOL WINAPI IsADMFileVisibleA(LPCSTR pcszFileName, int nRole, DWORD dwPlatformId)
  98. {
  99. USES_CONVERSION;
  100. return isADMFileVisibleHelper(A2CT(pcszFileName), nRole, dwPlatformId);
  101. }
  102. BOOL WINAPI IsADMFileVisibleW(LPCWSTR pcwszFileName, int nRole, DWORD dwPlatformId)
  103. {
  104. USES_CONVERSION;
  105. return isADMFileVisibleHelper(W2CT(pcwszFileName), nRole, dwPlatformId);
  106. }
  107. BOOL WINAPI LoadADMFilesA(HWND hTreeView, HTREEITEM hPolicyRootItem, LPCSTR pcszADMFilePath,
  108. LPCSTR pcszWorkDir, DWORD dwPlatformId, int nRole,
  109. int nIconADMClose, int nIconADMCategory)
  110. {
  111. USES_CONVERSION;
  112. return loadADMFilesHelper(hTreeView, hPolicyRootItem, A2CT(pcszADMFilePath),
  113. A2CT(pcszWorkDir), dwPlatformId, nRole, nIconADMClose, nIconADMCategory);
  114. }
  115. BOOL WINAPI LoadADMFilesW(HWND hTreeView, HTREEITEM hPolicyRootItem, LPCWSTR pcwszADMFilePath,
  116. LPCWSTR pcwszWorkDir, DWORD dwPlatformId, int nRole,
  117. int nIconADMClose, int nIconADMCategory)
  118. {
  119. USES_CONVERSION;
  120. return loadADMFilesHelper(hTreeView, hPolicyRootItem, W2CT(pcwszADMFilePath),
  121. W2CT(pcwszWorkDir), dwPlatformId, nRole, nIconADMClose, nIconADMCategory);
  122. }
  123. void WINAPI DeleteADMItemA(HWND hTreeView, HTREEITEM hParentItem, LPCSTR pcszWorkDir,
  124. LPCSTR pcszInsFile, BOOL bDeleteFile, BOOL bSave)
  125. {
  126. USES_CONVERSION;
  127. deleteADMItemHelper(hTreeView, hParentItem, A2CT(pcszWorkDir), A2CT(pcszInsFile),
  128. bDeleteFile, bSave);
  129. }
  130. void WINAPI DeleteADMItemW(HWND hTreeView, HTREEITEM hParentItem, LPCWSTR pcwszWorkDir,
  131. LPCWSTR pcwszInsFile, BOOL bDeleteFile, BOOL bSave)
  132. {
  133. USES_CONVERSION;
  134. deleteADMItemHelper(hTreeView, hParentItem, W2CT(pcwszWorkDir), W2CT(pcwszInsFile),
  135. bDeleteFile, bSave);
  136. }
  137. void WINAPI DeleteADMItemsA(HWND hTreeView, LPCSTR pcszWorkDir, LPCSTR pcszInsFile,
  138. BOOL bSave)
  139. {
  140. USES_CONVERSION;
  141. deleteADMItemsHelper(hTreeView, A2CT(pcszWorkDir), A2CT(pcszInsFile), bSave);
  142. }
  143. void WINAPI DeleteADMItemsW(HWND hTreeView, LPCWSTR pcwszWorkDir, LPCWSTR pcwszInsFile,
  144. BOOL bSave)
  145. {
  146. USES_CONVERSION;
  147. deleteADMItemsHelper(hTreeView, W2CT(pcwszWorkDir), W2CT(pcwszInsFile), bSave);
  148. }
  149. // Displays the description of the adm file or displays the category window
  150. // depending on whether the selected item was an ADMFile Item or a category item.
  151. void WINAPI DisplayADMItem(HWND hWnd, HWND hTreeView, LPTVITEM lpSelectedItem,
  152. BOOL fShowDisabled)
  153. {
  154. TV_ITEM tvitem;
  155. HWND hAdmWnd = NULL;
  156. RECT rect;
  157. RECT wndRect;
  158. HTREEITEM hParentItem = TreeView_GetParent(hTreeView, lpSelectedItem->hItem);
  159. int nWidth, nHeight;
  160. TCHAR szDscrTitle[ADM_TITLELEN];
  161. TCHAR szDscr[ADM_DSCRLEN];
  162. ADMFile* pADMFile;
  163. if(hParentItem != PolicyRoot())
  164. { // item is a category
  165. ShowADMWindow(hTreeView, FALSE);
  166. if(lpSelectedItem->lParam != NULL)
  167. {
  168. ADMCategory* pADMCategory;
  169. tvitem.mask = TVIF_PARAM;
  170. tvitem.hItem = hParentItem;
  171. TreeView_GetItem(hTreeView, &tvitem);
  172. // get the cooridnates to display the window
  173. // the coordinates are the same as the static instruction window
  174. GetWindowRect(hWnd, &wndRect);
  175. if(!IsWizard())
  176. {
  177. wndRect.left += GetSystemMetrics(SM_CXFIXEDFRAME);
  178. wndRect.top += (GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU) +
  179. GetSystemMetrics(SM_CYFIXEDFRAME));
  180. }
  181. CDscrWnd* pDscrWnd = (CDscrWnd*)GetWindowLongPtr(hTreeView, GWLP_USERDATA);
  182. if (pDscrWnd != NULL)
  183. {
  184. pDscrWnd->GetRect(&rect);
  185. rect.right = (rect.left - wndRect.left) + (rect.right - rect.left);
  186. rect.bottom = (rect.top - wndRect.top) + (rect.bottom - rect.top);
  187. rect.left = rect.left - wndRect.left;
  188. rect.top = rect.top - wndRect.top;
  189. }
  190. else
  191. {
  192. RECT rectTreeView;
  193. GetWindowRect(hTreeView, &rectTreeView);
  194. rect.left = rectTreeView.right - wndRect.left + 7;
  195. rect.top = rectTreeView.top - wndRect.top + 2;
  196. rect.right = (wndRect.right - wndRect.left - 7 -
  197. ((!IsWizard()) ? GetSystemMetrics(SM_CXFIXEDFRAME) : 0));
  198. rect.bottom = rect.top + rectTreeView.bottom - rectTreeView.top - 4;
  199. }
  200. nWidth = rect.right - rect.left;
  201. nHeight = rect.bottom - rect.top;
  202. pADMFile = (ADMFile*)tvitem.lParam;
  203. pADMCategory = (ADMCategory*)lpSelectedItem->lParam;
  204. // Display the window associated with the item/category
  205. CreateAdmUi(pADMFile->dwAdm, hWnd, rect.left, rect.top, nWidth, nHeight,
  206. WS_TABSTOP, 0, pADMCategory->pszName, pADMCategory->hKeyClass, &hAdmWnd,
  207. pADMFile->pData, &pADMCategory->pData, pADMCategory->fRSoPMode);
  208. pADMCategory->hWnd = hAdmWnd;
  209. if(fShowDisabled)
  210. EnableWindow(hAdmWnd, FALSE);
  211. else
  212. EnableWindow(hAdmWnd, TRUE);
  213. }
  214. }
  215. else
  216. { // item is a adm file
  217. ShowADMWindow(hTreeView, TRUE);
  218. ZeroMemory(szDscrTitle, ADM_TITLELEN);
  219. ZeroMemory(szDscr, ADM_DSCRLEN);
  220. if(lpSelectedItem->lParam != NULL)
  221. {
  222. pADMFile = (ADMFile*)lpSelectedItem->lParam;
  223. getADMDescriptionTitle(pADMFile->szFileName, szDscrTitle);
  224. getADMDescription(pADMFile->szFileName, szDscr);
  225. }
  226. else
  227. {
  228. if(!IsWizard())
  229. {
  230. LoadString(g_hInst, IDS_POLICYBRANCHTITLE, szDscrTitle, ADM_TITLELEN);
  231. LoadString(g_hInst, IDS_POLICYBRANCHTEXT, szDscr, ADM_DSCRLEN);
  232. }
  233. }
  234. SetADMWindowText(hTreeView, szDscrTitle, szDscr);
  235. }
  236. }
  237. // Displays an ADM file description or category window depending
  238. // on the type of the selected item
  239. void WINAPI SelectADMItem(HWND hWnd, HWND hTreeView, LPTVITEM lpTVItem,
  240. BOOL bSelect, BOOL fShowDisabled)
  241. {
  242. HTREEITEM hParentItem;
  243. TCHAR szDscrTitle[ADM_TITLELEN];
  244. TCHAR szDscr[ADM_DSCRLEN];
  245. hParentItem = TreeView_GetParent(hTreeView, lpTVItem->hItem);
  246. if(bSelect == FALSE)
  247. {
  248. // if the previously selected item was a category item,
  249. // save the category information and destroy the window
  250. // associated with that category
  251. if(hParentItem != g_hPolicyRootItem)
  252. {
  253. if(lpTVItem->lParam != NULL)
  254. SaveADMItem(hTreeView, lpTVItem, ITEM_SAVE | ITEM_DESTROY);
  255. }
  256. else
  257. ShowADMWindow(hTreeView, FALSE);
  258. }
  259. else
  260. {
  261. if(hParentItem == NULL)
  262. {
  263. LoadString(g_hInst, IDS_POLICYBRANCHTITLE, szDscrTitle, ADM_TITLELEN);
  264. LoadString(g_hInst, IDS_POLICYBRANCHTEXT, szDscr, ADM_DSCRLEN);
  265. SetADMWindowText(hTreeView, szDscrTitle, szDscr);
  266. return;
  267. }
  268. // display the information for the newly selected item
  269. DisplayADMItem(hWnd, hTreeView, lpTVItem, fShowDisabled);
  270. }
  271. }
  272. void WINAPI ImportADMFileA(HWND hMainWnd, HWND hTreeView, LPCSTR pcszADMFilePath,
  273. LPCSTR pcszWorkDir, int nRole, LPCSTR pcszInsFile)
  274. {
  275. USES_CONVERSION;
  276. importADMFileHelper(hMainWnd, hTreeView, A2CT(pcszADMFilePath), A2CT(pcszWorkDir),
  277. nRole, A2CT(pcszInsFile));
  278. }
  279. void WINAPI ImportADMFileW(HWND hMainWnd, HWND hTreeView, LPCWSTR pcwszADMFilePath,
  280. LPCWSTR pcwszWorkDir, int nRole, LPCWSTR pcwszInsFile)
  281. {
  282. USES_CONVERSION;
  283. importADMFileHelper(hMainWnd, hTreeView, W2CT(pcwszADMFilePath), W2CT(pcwszWorkDir),
  284. nRole, W2CT(pcwszInsFile));
  285. }
  286. void WINAPI CheckForDupKeys(HWND hMainWnd, HWND hTreeView, HTREEITEM hItem,
  287. BOOL bDispSuccessMsg)
  288. {
  289. TV_ITEM tvitem;
  290. TV_ITEM tvitem1;
  291. HANDLE hFile;
  292. HRESULT hResult;
  293. TCHAR szMessage[MAX_PATH];
  294. BOOL bClearLog = TRUE;
  295. HTREEITEM hPolicyItem = GetFirstPolicyItem(hTreeView);
  296. TCHAR szRoot[MAX_PATH];
  297. TCHAR szTitle[MAX_PATH];
  298. tvitem.mask = TVIF_PARAM;
  299. tvitem.hItem = hItem;
  300. TreeView_GetItem(hTreeView, &tvitem);
  301. LoadString(g_hInst, IDS_TITLE, szTitle, ARRAYSIZE(szTitle));
  302. if(ISNULL(g_szLogFileName))
  303. {
  304. LPTSTR pLastSlash;
  305. DWORD dwSize = sizeof(szRoot);
  306. GetModuleFileName(GetModuleHandle(NULL), szRoot, MAX_PATH);
  307. if(ISNULL(szRoot))
  308. SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEAK6WIZ.EXE"), NULL, NULL, (LPVOID) szRoot, &dwSize);
  309. if(ISNONNULL(szRoot))
  310. {
  311. pLastSlash = StrRChr(szRoot, NULL, TEXT('\\'));
  312. if (pLastSlash)
  313. *(++pLastSlash) = 0;
  314. CharUpper(szRoot);
  315. }
  316. wnsprintf(g_szLogFileName, ARRAYSIZE(g_szLogFileName), TEXT("%sadmlog.txt"), szRoot);
  317. }
  318. do
  319. {
  320. tvitem1.mask = TVIF_PARAM;
  321. tvitem1.hItem = hPolicyItem;
  322. TreeView_GetItem(hTreeView, &tvitem1);
  323. hResult = CheckDuplicateKeys(((ADMFile*)tvitem.lParam)->dwAdm, ((ADMFile*)tvitem1.lParam)->dwAdm,
  324. g_szLogFileName, bClearLog);
  325. if(hResult != S_OK)
  326. {
  327. if(GetLastError() == STATUS_NO_MEMORY)
  328. {
  329. LoadString(g_hInst, IDS_MEMORY_ERROR, szMessage, ARRAYSIZE(szMessage));
  330. }
  331. else if(GetLastError() == ERROR_FILE_NOT_FOUND)
  332. {
  333. LoadString(g_hInst, IDS_FILE_ERROR, szMessage, ARRAYSIZE(szMessage));
  334. }
  335. MessageBox(hTreeView, szMessage, szTitle, MB_ICONINFORMATION|MB_OK);
  336. return;
  337. }
  338. bClearLog = FALSE;
  339. }while((hPolicyItem = TreeView_GetNextSibling(hTreeView, hPolicyItem)) != NULL); // get next item
  340. hFile = CreateFile( g_szLogFileName, GENERIC_READ, FILE_SHARE_READ,
  341. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  342. if( hFile == INVALID_HANDLE_VALUE )
  343. {
  344. LoadString(g_hInst, IDS_NO_DUPLICATEKEYS, szMessage, ARRAYSIZE(szMessage));
  345. MessageBox(hTreeView, szMessage, szTitle, MB_ICONINFORMATION|MB_OK);
  346. return;
  347. }
  348. if(GetFileSize( hFile, NULL ) == 0)
  349. {
  350. CloseHandle(hFile);
  351. if(bDispSuccessMsg)
  352. {
  353. LoadString(g_hInst, IDS_NO_DUPLICATEKEYS, szMessage, ARRAYSIZE(szMessage));
  354. MessageBox(hTreeView, szMessage, szTitle, MB_ICONINFORMATION|MB_OK);
  355. }
  356. }
  357. else
  358. {
  359. CloseHandle(hFile);
  360. DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ERRORLOG), hMainWnd, logDialogProc);
  361. }
  362. SetFocus(hMainWnd);
  363. }
  364. void WINAPI ResetAdmFilesA(HWND hTreeView, LPCSTR pcszWorkDir, BOOL bReset)
  365. {
  366. USES_CONVERSION;
  367. resetAdmFilesHelper(hTreeView, A2CT(pcszWorkDir), bReset);
  368. }
  369. void WINAPI ResetAdmFilesW(HWND hTreeView, LPCWSTR pcwszWorkDir, BOOL bReset)
  370. {
  371. USES_CONVERSION;
  372. resetAdmFilesHelper(hTreeView, W2CT(pcwszWorkDir), bReset);
  373. }
  374. void WINAPI SaveAdmFilesA(HWND hTreeView, LPCSTR pcszWorkDir, LPCSTR pcszInsFile)
  375. {
  376. USES_CONVERSION;
  377. saveAdmFilesHelper(hTreeView, A2CT(pcszWorkDir), A2CT(pcszInsFile));
  378. }
  379. void WINAPI SaveAdmFilesW(HWND hTreeView, LPCWSTR pcwszWorkDir, LPCWSTR pcwszInsFile)
  380. {
  381. USES_CONVERSION;
  382. saveAdmFilesHelper(hTreeView, W2CT(pcwszWorkDir), W2CT(pcwszInsFile));
  383. }
  384. BOOL WINAPI CanDeleteADM(HWND hTreeView, HTREEITEM hItem)
  385. {
  386. TV_ITEM tvitem;
  387. int nDeleteLock = 0;
  388. tvitem.mask = TVIF_PARAM;
  389. tvitem.hItem = hItem;
  390. TreeView_GetItem(hTreeView, &tvitem);
  391. if(tvitem.lParam != NULL)
  392. {
  393. nDeleteLock = GetPrivateProfileInt(TEXT("IEAK"), TEXT("Lock"), 0,
  394. ((ADMFile*)tvitem.lParam)->szFileName);
  395. }
  396. return (BOOL) !nDeleteLock;
  397. }
  398. HWND WINAPI GetAdmWindowHandle(HWND hTreeView, HTREEITEM hItem)
  399. {
  400. TV_ITEM tvitem;
  401. tvitem.mask = TVIF_PARAM;
  402. tvitem.hItem = hItem;
  403. if (TreeView_GetItem(hTreeView, &tvitem) == TRUE)
  404. return ((ADMCategory*)tvitem.lParam)->hWnd;
  405. else
  406. return NULL;
  407. }
  408. void WINAPI SaveADMItem(HWND hTreeView, LPTVITEM lpTVItem, DWORD dwFlags)
  409. {
  410. if (lpTVItem != NULL && lpTVItem->lParam != NULL)
  411. {
  412. TVITEM tvitem;
  413. tvitem.mask = TVIF_PARAM;
  414. tvitem.hItem = TreeView_GetParent(hTreeView, lpTVItem->hItem);
  415. TreeView_GetItem(hTreeView, &tvitem);
  416. if (dwFlags)
  417. {
  418. DWORD dwAdmFlags = 0;
  419. ADMFile* pADMFile = (ADMFile*)tvitem.lParam;
  420. ADMCategory* pADMCategory = (ADMCategory*)lpTVItem->lParam;
  421. if (pADMCategory != NULL)
  422. {
  423. if (HasFlag(dwFlags, ITEM_SAVE))
  424. dwAdmFlags |= ADM_SAVE;
  425. if (HasFlag(dwFlags, ITEM_DESTROY))
  426. dwAdmFlags |= ADM_DESTROY;
  427. AdmSaveData(pADMFile->dwAdm, pADMFile->pData, pADMCategory->pData, dwAdmFlags);
  428. if (HasFlag(dwFlags, ITEM_DESTROY))
  429. {
  430. DestroyWindow(pADMCategory->hWnd);
  431. pADMCategory->hWnd = NULL;
  432. pADMCategory->pData = NULL;
  433. }
  434. }
  435. }
  436. }
  437. }
  438. BOOL WINAPI GetAdmFileListA(LPRESULTITEMA* pResultItemsArrayA, int* pnResultItems, int nRole)
  439. {
  440. LPRESULTITEM pResultItemArray = NULL;
  441. BOOL fRet;
  442. fRet = getAdmFileListHelper(&pResultItemArray, pnResultItems, nRole);
  443. if (pResultItemArray != NULL)
  444. {
  445. int i;
  446. if ((i = *pnResultItems) != 0)
  447. {
  448. if ((*pResultItemsArrayA = (LPRESULTITEMA)CoTaskMemAlloc(i * sizeof(RESULTITEMA))) != NULL)
  449. {
  450. for (i--; i >= 0; i--)
  451. {
  452. // must used StrLen manually here to figure out how many bytes to allocate!
  453. if (pResultItemArray[i].pszName != NULL)
  454. (*pResultItemsArrayA)[i].pszName =
  455. (LPSTR)CoTaskMemAlloc((StrLen(pResultItemArray[i].pszName)+1)*2);
  456. if (pResultItemArray[i].pszDesc != NULL)
  457. (*pResultItemsArrayA)[i].pszDesc =
  458. (LPSTR)CoTaskMemAlloc((StrLen(pResultItemArray[i].pszDesc)+1)*2);
  459. ResultItemT2A(&pResultItemArray[i], &(*pResultItemsArrayA)[i]);
  460. if (pResultItemArray[i].pszName != NULL)
  461. CoTaskMemFree(pResultItemArray[i].pszName);
  462. if (pResultItemArray[i].pszDesc != NULL)
  463. CoTaskMemFree(pResultItemArray[i].pszDesc);
  464. }
  465. }
  466. }
  467. CoTaskMemFree(pResultItemArray);
  468. }
  469. return fRet;
  470. }
  471. BOOL WINAPI GetAdmFileListW(LPRESULTITEMW* pResultItemsArrayW, int* pnResultItems, int nRole)
  472. {
  473. LPRESULTITEM pResultItemArray = NULL;
  474. BOOL fRet;
  475. fRet = getAdmFileListHelper(&pResultItemArray, pnResultItems, nRole);
  476. if (pResultItemArray != NULL)
  477. {
  478. int i;
  479. if ((i = *pnResultItems) != 0)
  480. {
  481. if ((*pResultItemsArrayW = (LPRESULTITEMW)CoTaskMemAlloc(i * sizeof(RESULTITEMW))) != NULL)
  482. {
  483. for (i--; i >= 0; i--)
  484. {
  485. // must used StrLen manually here to figure out how many bytes to allocate!
  486. if (pResultItemArray[i].pszName != NULL)
  487. (*pResultItemsArrayW)[i].pszName =
  488. (LPWSTR)CoTaskMemAlloc((StrLen(pResultItemArray[i].pszName)+1) * sizeof(WCHAR));
  489. if (pResultItemArray[i].pszDesc != NULL)
  490. (*pResultItemsArrayW)[i].pszDesc =
  491. (LPWSTR)CoTaskMemAlloc((StrLen(pResultItemArray[i].pszDesc)+1) * sizeof(WCHAR));
  492. ResultItemT2W(&pResultItemArray[i], &(*pResultItemsArrayW)[i]);
  493. if (pResultItemArray[i].pszName != NULL)
  494. CoTaskMemFree(pResultItemArray[i].pszName);
  495. if (pResultItemArray[i].pszDesc != NULL)
  496. CoTaskMemFree(pResultItemArray[i].pszDesc);
  497. }
  498. }
  499. }
  500. CoTaskMemFree(pResultItemArray);
  501. }
  502. return fRet;
  503. }
  504. HTREEITEM WINAPI AddADMItemA(HWND hTreeView, LPCSTR pcszADMFilePath, LPCSTR pcszFileName,
  505. LPCSTR pcszWorkDir, int nRole, BSTR bstrRSOPNamespace)
  506. {
  507. USES_CONVERSION;
  508. return addADMItemHelper(hTreeView, A2CT(pcszADMFilePath), A2CT(pcszFileName),
  509. A2CT(pcszWorkDir), nRole, bstrRSOPNamespace);
  510. }
  511. HTREEITEM WINAPI AddADMItemW(HWND hTreeView, LPCWSTR pcwszADMFilePath, LPCWSTR pcwszFileName,
  512. LPCWSTR pcwszWorkDir, int nRole, BSTR bstrRSOPNamespace)
  513. {
  514. USES_CONVERSION;
  515. return addADMItemHelper(hTreeView, W2CT(pcwszADMFilePath), W2CT(pcwszFileName),
  516. W2CT(pcwszWorkDir), nRole, bstrRSOPNamespace);
  517. }
  518. // Converts the .adm filename to .inf filename and concatenates the
  519. // appropriate path for the .inf file
  520. static void getInfFileName(LPCTSTR pcszADMFileName, LPTSTR pszInfFileName, DWORD cchInfFile, LPCTSTR pcszWorkDir)
  521. {
  522. TCHAR szBaseFileName[MAX_PATH];
  523. ZeroMemory(pszInfFileName, cchInfFile*sizeof(TCHAR));
  524. StrCpy(szBaseFileName, PathFindFileName(pcszADMFileName));
  525. PathRemoveExtension(szBaseFileName);
  526. if(ISNONNULL(pcszWorkDir))
  527. wnsprintf(pszInfFileName, cchInfFile, TEXT("%s\\%s.inf"), pcszWorkDir, szBaseFileName);
  528. }
  529. // Loads all the categories for a specified .adm file
  530. static void loadCategories(HWND hTreeView, HTREEITEM hParentItem, DWORD dwAdm,
  531. BOOL fRSoPMode)
  532. {
  533. int nSize = 0;
  534. int nCategorySize = 0;
  535. TV_INSERTSTRUCT tvis;
  536. TCHAR szCategories[2048];
  537. TCHAR szCategory[1024];
  538. HKEY hKeyCurrentClass = HKEY_CURRENT_USER;
  539. // Get the category list. The category strings are concatenated into a
  540. // single string with '\0' as the seperator and the last string is
  541. // terminated with "\0\0"
  542. GetAdmCategories(dwAdm, szCategories, ARRAYSIZE(szCategories), &nSize);
  543. for(int nIndex = 0; nIndex < (nSize - 2); nIndex++)
  544. {
  545. memset(szCategory, 0, sizeof(szCategory));
  546. nCategorySize = 0;
  547. while(szCategories[nIndex] != TEXT('\0'))
  548. {
  549. szCategory[nCategorySize++] = szCategories[nIndex++];
  550. }
  551. if(StrCmpI(szCategory, TEXT("HKLM")) == 0)
  552. {
  553. hKeyCurrentClass = HKEY_LOCAL_MACHINE;
  554. continue;
  555. }
  556. else if(StrCmpI(szCategory, TEXT("HKCU")) == 0)
  557. {
  558. hKeyCurrentClass = HKEY_CURRENT_USER;
  559. continue;
  560. }
  561. ADMCategory* pCategory = (ADMCategory*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ADMCategory));
  562. if(pCategory == NULL) // not enough memory available
  563. {
  564. return;
  565. }
  566. memset(pCategory, 0, sizeof(ADMCategory));
  567. pCategory->pszName = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
  568. (lstrlen(szCategory) + 1)*sizeof(TCHAR));
  569. if(pCategory->pszName == NULL) // not enough memory available
  570. {
  571. HeapFree(GetProcessHeap(), 0, pCategory);
  572. return;
  573. }
  574. StrCpy(pCategory->pszName, szCategory);
  575. pCategory->hKeyClass = hKeyCurrentClass;
  576. pCategory->fRSoPMode = fRSoPMode;
  577. tvis.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  578. tvis.item.pszText = pCategory->pszName;
  579. tvis.item.cchTextMax = lstrlen(pCategory->pszName);
  580. tvis.item.lParam = (LPARAM) pCategory;
  581. tvis.item.iImage = tvis.item.iSelectedImage = g_ADMCategory;
  582. tvis.hInsertAfter = (HTREEITEM) TVI_LAST;
  583. tvis.hParent = hParentItem;
  584. if(TreeView_InsertItem( hTreeView, &tvis) == NULL)
  585. { // insert failure
  586. HeapFree(GetProcessHeap(), 0, pCategory->pszName);
  587. HeapFree(GetProcessHeap(), 0, pCategory);
  588. }
  589. }
  590. }
  591. // Checks whether a particular .adm file is to be displayed in the tree view
  592. // depending on the PLATFORM key in the IEAK section
  593. static BOOL isADMFileVisibleHelper(LPCTSTR pcszFileName, int nRole, DWORD dwPlatformId)
  594. {
  595. TCHAR szRoles[5];
  596. TCHAR szPlatform[10];
  597. ZeroMemory(szRoles,sizeof(szRoles));
  598. ZeroMemory(szPlatform, sizeof(szPlatform));
  599. if(IsWizard())
  600. {
  601. // if the Roles are not specified or are not of the proper format,
  602. // the adm file is assumed to be visible
  603. if(GetPrivateProfileString(TEXT("IEAK"), TEXT("Roles"), TEXT(""), szRoles, ARRAYSIZE(szRoles), pcszFileName) == 3)
  604. {
  605. if(!((szRoles[0] == TEXT('0') || szRoles[0] == TEXT('1')) &&
  606. (szRoles[1] == TEXT('0') || szRoles[1] == TEXT('1')) &&
  607. (szRoles[2] == TEXT('0') || szRoles[2] == TEXT('1')) &&
  608. ((szRoles[0] == TEXT('1') && nRole == ROLE_ICP) || // ICP
  609. (szRoles[1] == TEXT('1') && nRole == ROLE_ISP) || // ISP
  610. (szRoles[2] == TEXT('1') && nRole == ROLE_CORP)))) // Corp. Admin
  611. {
  612. return FALSE;
  613. }
  614. }
  615. }
  616. GetPrivateProfileString(TEXT("IEAK"), TEXT("Platform"), TEXT(""), szPlatform, ARRAYSIZE(szPlatform), pcszFileName);
  617. if(!((szPlatform[1] == TEXT('1') && dwPlatformId == PLATFORM_WIN32) || // WIN32
  618. (szPlatform[3] == TEXT('1') && dwPlatformId == PLATFORM_W2K))) // W2K
  619. {
  620. return FALSE;
  621. }
  622. return TRUE;
  623. }
  624. // Adds an item (.adm file) to the tree view
  625. static HTREEITEM addADMItemHelper(HWND hTreeView, LPCTSTR pcszADMFilePath, LPCTSTR pcszFileName,
  626. LPCTSTR pcszWorkDir, int nRole, BSTR bstrRSOPNamespace)
  627. {
  628. TV_INSERTSTRUCT tvis;
  629. HTREEITEM hItem = NULL;
  630. DWORD dwAdm = 0;
  631. TCHAR szADMFileName[MAX_PATH];
  632. TCHAR szOutputFile[MAX_PATH];
  633. TCHAR szTitle[ADM_TITLELEN];
  634. PathCombine(szADMFileName, pcszADMFilePath, pcszFileName);
  635. // check for the visibility of the adm file
  636. if(!IsADMFileVisible(szADMFileName, nRole, g_dwPlatformId))
  637. return NULL;
  638. ADMFile* pADMFile = (ADMFile*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ADMFile));
  639. if(pADMFile == NULL) // not enough memory available
  640. {
  641. return NULL;
  642. }
  643. ZeroMemory(pADMFile, sizeof(ADMFile));
  644. StrCpy(pADMFile->szFileName, szADMFileName);
  645. ZeroMemory(szTitle, sizeof(szTitle));
  646. GetPrivateProfileString(TEXT("Strings"), TEXT("IEAK_Title"), pcszFileName, szTitle,
  647. ARRAYSIZE(szTitle), pADMFile->szFileName);
  648. pADMFile->pszName = (LPTSTR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
  649. (StrLen(szTitle) + 1)*sizeof(TCHAR));
  650. if(pADMFile->pszName == NULL) // not enough memory available
  651. {
  652. HeapFree(GetProcessHeap(), 0, pADMFile);
  653. return NULL;
  654. }
  655. StrCpy(pADMFile->pszName, szTitle);
  656. tvis.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  657. tvis.item.pszText = pADMFile->pszName;
  658. tvis.item.cchTextMax = StrLen(pADMFile->pszName);
  659. tvis.item.lParam = (LPARAM) pADMFile;
  660. if (IsWizard())
  661. {
  662. tvis.item.mask |= TVIF_STATE;
  663. tvis.item.stateMask = tvis.item.state = TVIS_BOLD;
  664. }
  665. tvis.item.iImage = tvis.item.iSelectedImage = g_ADMClose;
  666. tvis.hInsertAfter = (HTREEITEM) TVI_LAST;
  667. tvis.hParent = PolicyRoot();
  668. getInfFileName(pADMFile->szFileName, szOutputFile, ARRAYSIZE(szOutputFile), pcszWorkDir);
  669. if(AdmInit(pADMFile->szFileName, szOutputFile, bstrRSOPNamespace, &dwAdm, &pADMFile->pData) == S_OK)
  670. {
  671. pADMFile->dwAdm = dwAdm;
  672. if((hItem = TreeView_InsertItem( hTreeView, &tvis)) != NULL)
  673. { // insert success
  674. loadCategories(hTreeView, hItem, dwAdm, (NULL == bstrRSOPNamespace) ? FALSE : TRUE);
  675. }
  676. }
  677. if(hItem == NULL)
  678. {
  679. HeapFree(GetProcessHeap(), 0, pADMFile->pszName);
  680. HeapFree(GetProcessHeap(), 0, pADMFile);
  681. hItem = NULL;
  682. }
  683. return hItem;
  684. }
  685. static void addAdmItems(HWND hTreeView, LPCTSTR pcszFileType, LPCTSTR pcszADMFilePath,
  686. LPCTSTR pcszWorkDir, int nRole)
  687. {
  688. WIN32_FIND_DATA FindFileData;
  689. TCHAR szFileName[MAX_PATH];
  690. PathCombine(szFileName, pcszADMFilePath, pcszFileType);
  691. HANDLE hFind = FindFirstFile(szFileName, &FindFileData);
  692. if(hFind != INVALID_HANDLE_VALUE)
  693. {
  694. do
  695. {
  696. // addAdmItems is called from loadADMFiles which is never called in RSoP mode,
  697. // so just pass in FALSE always.
  698. addADMItemHelper(hTreeView, pcszADMFilePath, FindFileData.cFileName,
  699. pcszWorkDir, nRole, NULL);
  700. }while(FindNextFile(hFind, &FindFileData));
  701. FindClose(hFind);
  702. }
  703. }
  704. // Loads all the .adm files from a specific path
  705. static BOOL loadADMFilesHelper(HWND hTreeView, HTREEITEM hPolicyRootItem,
  706. LPCTSTR pcszADMFilePath, LPCTSTR pcszWorkDir,
  707. DWORD dwPlatformId, int nRole,
  708. int nIconADMClose, int nIconADMCategory)
  709. {
  710. g_hPolicyRootItem = hPolicyRootItem;
  711. g_dwPlatformId = dwPlatformId;
  712. g_ADMClose = nIconADMClose;
  713. g_ADMCategory = nIconADMCategory;
  714. ZeroMemory(g_szLogFileName, sizeof(g_szLogFileName));
  715. addAdmItems(hTreeView, TEXT("*.adm"), pcszADMFilePath, pcszWorkDir, nRole);
  716. // add also files with .opa extension, Office requirement - 06/08/98
  717. addAdmItems(hTreeView, TEXT("*.opa"), pcszADMFilePath, pcszWorkDir, nRole);
  718. return TRUE;
  719. }
  720. // Returns the item handle for the requested filename if any
  721. static HTREEITEM getADMItemHandle(HWND hTreeView, LPTSTR pszADMFileName)
  722. {
  723. HTREEITEM hItem = NULL;
  724. TV_ITEM tvitem;
  725. hItem = GetFirstPolicyItem(hTreeView);
  726. while(hItem != NULL) // if items in the tree view
  727. {
  728. tvitem.mask = TVIF_PARAM;
  729. tvitem.hItem = hItem;
  730. TreeView_GetItem(hTreeView, &tvitem);
  731. if(tvitem.lParam != NULL &&
  732. StrCmp(((ADMFile*) tvitem.lParam)->szFileName, pszADMFileName) == 0)
  733. {
  734. return hItem;
  735. }
  736. hItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  737. }
  738. return NULL;
  739. }
  740. // Deletes an item from the tree view and releases any memory
  741. // allocated with that item
  742. static void deleteADMItemHelper(HWND hTreeView, HTREEITEM hParentItem, LPCTSTR pcszWorkDir,
  743. LPCTSTR pcszInsFile, BOOL bDeleteFile, BOOL bSave)
  744. {
  745. ADMFile* pADMFile = NULL;
  746. ADMCategory* pADMCategory = NULL;
  747. HTREEITEM hItem = NULL;
  748. HTREEITEM hNextItem = NULL;
  749. TCHAR szRegistryData[MAX_PATH + 15];
  750. TCHAR szBaseFileName[_MAX_FNAME];
  751. TV_ITEM tvitem;
  752. TV_ITEM tvparentitem;
  753. TCHAR szOutputFile[MAX_PATH];
  754. tvparentitem.mask = TVIF_PARAM;
  755. tvparentitem.hItem = hParentItem;
  756. TreeView_GetItem(hTreeView, &tvparentitem);
  757. if(tvparentitem.lParam != NULL)
  758. {
  759. pADMFile = (ADMFile*) tvparentitem.lParam;
  760. hItem = TreeView_GetChild(hTreeView, hParentItem); // get child item
  761. while(hItem != NULL)
  762. {
  763. hNextItem = TreeView_GetNextSibling(hTreeView, hItem); // get next child item
  764. tvitem.mask = TVIF_PARAM;
  765. tvitem.hItem = hItem;
  766. TreeView_GetItem(hTreeView, &tvitem);
  767. if(tvitem.lParam != NULL)
  768. {
  769. pADMCategory = (ADMCategory*) tvitem.lParam;
  770. HeapFree(GetProcessHeap(), 0, pADMCategory->pszName);
  771. HeapFree(GetProcessHeap(), 0, pADMCategory);
  772. TreeView_DeleteItem(hTreeView, hItem);
  773. }
  774. hItem = hNextItem;
  775. }
  776. getInfFileName(pADMFile->szFileName, szOutputFile, ARRAYSIZE(szOutputFile),
  777. pcszWorkDir);
  778. StrCpy(szBaseFileName, PathFindFileName(szOutputFile));
  779. PathRemoveExtension(szBaseFileName);
  780. if(bDeleteFile == TRUE)
  781. {
  782. DeleteFile(pADMFile->szFileName);
  783. DeleteFile(szOutputFile);
  784. }
  785. else
  786. {
  787. if (bSave)
  788. {
  789. AdmFinished(pADMFile->dwAdm, szOutputFile, pADMFile->pData);
  790. if (PathFileExists(szOutputFile))
  791. {
  792. wnsprintf(szRegistryData, ARRAYSIZE(szRegistryData),
  793. TEXT("*,%s,DefaultInstall"), PathFindFileName(szOutputFile));
  794. InsWriteString(IS_EXTREGINF, szBaseFileName, szRegistryData, pcszInsFile);
  795. if (!InsIsSectionEmpty(TEXT("AddRegSection.HKLM"), szOutputFile))
  796. {
  797. wnsprintf(szRegistryData, ARRAYSIZE(szRegistryData),
  798. TEXT("%s,IEAKInstall.HKLM"), PathFindFileName(szOutputFile));
  799. InsWriteString(IS_EXTREGINF_HKLM, szBaseFileName, szRegistryData, pcszInsFile);
  800. }
  801. if (!InsIsSectionEmpty(TEXT("AddRegSection.HKCU"), szOutputFile))
  802. {
  803. wnsprintf(szRegistryData, ARRAYSIZE(szRegistryData),
  804. TEXT("%s,IEAKInstall.HKCU"), PathFindFileName(szOutputFile));
  805. InsWriteString(IS_EXTREGINF_HKCU, szBaseFileName, szRegistryData, pcszInsFile);
  806. }
  807. }
  808. }
  809. }
  810. AdmClose(pADMFile->dwAdm, &pADMFile->pData, bDeleteFile);
  811. HeapFree(GetProcessHeap(), 0, pADMFile->pszName);
  812. HeapFree(GetProcessHeap(), 0, pADMFile);
  813. TreeView_DeleteItem(hTreeView, hParentItem);
  814. if(TreeView_GetCount(hTreeView) == 0) // if no items in the tree view
  815. SetADMWindowText(hTreeView, TEXT(""), TEXT(""));
  816. }
  817. WritePrivateProfileString(NULL, NULL, NULL, pcszInsFile);
  818. }
  819. // Deletes all the items from the tree view
  820. static void deleteADMItemsHelper(HWND hTreeView, LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile,
  821. BOOL bSave)
  822. {
  823. HTREEITEM hItem = GetFirstPolicyItem(hTreeView); // get policy fisrt item
  824. HTREEITEM hNextItem = NULL;
  825. HTREEITEM hSelectedItem = TreeView_GetSelection(hTreeView); // get selected item
  826. if(hSelectedItem != NULL)
  827. {
  828. TreeView_Select(hTreeView, NULL, TVGN_CARET);
  829. }
  830. while(hItem != NULL) // if items in the tree view
  831. {
  832. hNextItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  833. deleteADMItemHelper(hTreeView, hItem, pcszWorkDir, pcszInsFile, FALSE, bSave);
  834. hItem = hNextItem;
  835. }
  836. }
  837. static void getADMDescriptionTitle(LPCTSTR pcszFileName, LPTSTR pszDscrTitle)
  838. {
  839. GetPrivateProfileString(TEXT("Strings"), TEXT("IEAK_DescriptionTitle"), TEXT(""),
  840. pszDscrTitle, ADM_DSCRLINELEN, pcszFileName);
  841. }
  842. // Reads the description from the specified adm file
  843. static void getADMDescription(LPCTSTR pcszFileName, LPTSTR pszDscr)
  844. {
  845. DWORD dwSize = 0;
  846. TCHAR szDscrText[ADM_DSCRLEN];
  847. TCHAR szDscrKey[20];
  848. int nIndex = 0;
  849. int nDscrLines = GetPrivateProfileInt(TEXT("IEAK"), TEXT("NumOfDescLines"), 0, pcszFileName);
  850. *pszDscr = TEXT('\0');
  851. for(nIndex = 1; nIndex <= nDscrLines; nIndex++)
  852. {
  853. wnsprintf(szDscrKey, ARRAYSIZE(szDscrKey), TEXT("IEAK_Description%d"), nIndex);
  854. dwSize = GetPrivateProfileString(TEXT("Strings"), szDscrKey, NULL,
  855. szDscrText, ADM_DSCRLEN, pcszFileName);
  856. if (dwSize)
  857. {
  858. if(nIndex == 1)
  859. StrCpy(pszDscr, szDscrText);
  860. else
  861. {
  862. StrCat(pszDscr, TEXT("\r\n\r\n"));
  863. StrCat(pszDscr, szDscrText);
  864. }
  865. }
  866. }
  867. }
  868. // Imports ADM file from the directory specified by the user to the
  869. // adm directory and calls addADMItemHelper to show the item on the tree list
  870. static void importADMFileHelper(HWND hMainWnd, HWND hTreeView, LPCTSTR pcszADMFilePath,
  871. LPCTSTR pcszWorkDir, int nRole, LPCTSTR pcszInsFile)
  872. {
  873. HTREEITEM hItem = NULL;
  874. TCHAR szFileName[MAX_PATH]=TEXT("");
  875. LPTSTR pExt = NULL;
  876. TCHAR szADMFileName[MAX_PATH];
  877. TCHAR szMessage[512];
  878. TCHAR szTitle[MAX_PATH];
  879. LoadString(g_hDLLInst, IDS_ENGINE_TITLE, szTitle, ARRAYSIZE(szTitle));
  880. if( BrowseForFile( hTreeView, szFileName, ARRAYSIZE(szFileName), GFN_ADM ))
  881. {
  882. pExt = PathFindExtension(szFileName);
  883. if(pExt != NULL)
  884. pExt++;
  885. // Only .adm file extensions to be added to the list
  886. if(StrCmpI(pExt, TEXT("adm")) == 0 || StrCmpI(pExt, TEXT("opa")) == 0)
  887. {
  888. PathCombine(szADMFileName, pcszADMFilePath, PathFindFileName(szFileName));
  889. // if already there exists a file with the same name, prompt
  890. // the user for overwrite confirmation.
  891. if(!CopyFile(szFileName, szADMFileName, TRUE))
  892. {
  893. LoadString(g_hInst, IDS_ADMOVRWWARN, szMessage, ARRAYSIZE(szMessage));
  894. if(MessageBox(hTreeView, szMessage, szTitle, MB_ICONQUESTION|MB_YESNO) == IDYES)
  895. {
  896. CopyFile(szFileName, szADMFileName, FALSE);
  897. hItem = getADMItemHandle(hTreeView, szADMFileName);
  898. if(hItem != NULL)
  899. {
  900. TreeView_Select(hTreeView, NULL, TVGN_CARET);
  901. deleteADMItemHelper(hTreeView, hItem, pcszWorkDir, pcszInsFile,
  902. FALSE, TRUE);
  903. }
  904. // importADMFile is never called in RSoP mode,
  905. // so just pass in FALSE always.
  906. hItem = addADMItemHelper(hTreeView, pcszADMFilePath,
  907. PathFindFileName(szADMFileName), pcszWorkDir, nRole, NULL);
  908. if(hItem != NULL)
  909. {
  910. TreeView_Select(hTreeView, hItem, TVGN_CARET);
  911. CheckForDupKeys(hMainWnd, hTreeView, hItem, FALSE);
  912. }
  913. }
  914. }
  915. else
  916. {
  917. // importADMFile is never called in RSoP mode,
  918. // so just pass in FALSE always.
  919. if((hItem = addADMItemHelper(hTreeView, pcszADMFilePath,
  920. PathFindFileName(szADMFileName), pcszWorkDir, nRole, NULL)) != NULL)
  921. {
  922. TreeView_Select(hTreeView, hItem, TVGN_CARET);
  923. CheckForDupKeys(hMainWnd, hTreeView, hItem, FALSE);
  924. }
  925. }
  926. }
  927. else
  928. {
  929. LoadString(g_hInst, IDS_ADMINVALIDEXTN, szMessage, ARRAYSIZE(szMessage));
  930. MessageBox(hTreeView, szMessage, szTitle, MB_ICONINFORMATION|MB_OK);
  931. }
  932. }
  933. }
  934. static INT_PTR CALLBACK logDialogProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM)
  935. {
  936. HANDLE hFile = NULL;
  937. HGLOBAL hFileMem = NULL;
  938. int nFileSize = 0;
  939. DWORD dwRead = 0;
  940. switch( msg )
  941. {
  942. case WM_INITDIALOG:
  943. EnableDBCSChars(hDlg, IDC_LOGTEXT);
  944. hFile = CreateFile( g_szLogFileName, GENERIC_READ, FILE_SHARE_READ,
  945. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
  946. if( hFile == INVALID_HANDLE_VALUE )
  947. {
  948. EndDialog(hDlg, 1);
  949. break;
  950. }
  951. nFileSize = GetFileSize( hFile, NULL );
  952. hFileMem = LocalAlloc( LPTR, nFileSize + 2);
  953. if( hFileMem != NULL )
  954. {
  955. if (ReadFile( hFile, (LPSTR) hFileMem, (DWORD) nFileSize, &dwRead, NULL)==TRUE)
  956. SetWindowTextA(GetDlgItem(hDlg, IDC_LOGTEXT), (LPCSTR) hFileMem);
  957. PostMessage(GetDlgItem(hDlg, IDC_LOGTEXT), EM_SETSEL, 0, 0L);
  958. LocalFree(hFileMem);
  959. hFileMem = NULL;
  960. }
  961. CloseHandle( hFile );
  962. break;
  963. case WM_COMMAND:
  964. if(HIWORD(wParam) == BN_CLICKED && LOWORD( wParam ) == IDOK)
  965. EndDialog(hDlg, 1);
  966. break;
  967. default:
  968. return 0;
  969. }
  970. return 1;
  971. }
  972. //*********
  973. // All the below functions is used only by the Profile Manager
  974. static BOOL isPolicyTree(HWND hTreeView, HTREEITEM hItem)
  975. {
  976. BOOL bRet = FALSE;
  977. HTREEITEM hParentItem = NULL;
  978. while(1)
  979. {
  980. hParentItem = TreeView_GetParent(hTreeView, hItem);
  981. if(hParentItem == NULL)
  982. {
  983. bRet = (hItem == g_hPolicyRootItem) ? TRUE : FALSE;
  984. break;
  985. }
  986. hItem = hParentItem;
  987. };
  988. return bRet;
  989. }
  990. static void resetAdmFilesHelper(HWND hTreeView, LPCTSTR pcszWorkDir, BOOL bReset)
  991. {
  992. HTREEITEM hItem = TreeView_GetChild(hTreeView, g_hPolicyRootItem); // get first policy item
  993. HTREEITEM hNextItem = NULL;
  994. TV_ITEM tvitem;
  995. TCHAR szInfFile[MAX_PATH];
  996. HTREEITEM hSelectedItem = TreeView_GetSelection(hTreeView); // get selected item
  997. ADMFile* pADMFile = NULL;
  998. ADMCategory* pADMCategory = NULL;
  999. if(g_hPolicyRootItem == NULL) // no elements under policy item
  1000. return;
  1001. while(hItem != NULL) // if items in the tree view
  1002. {
  1003. hNextItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  1004. tvitem.mask = TVIF_PARAM;
  1005. tvitem.hItem = hItem;
  1006. TreeView_GetItem(hTreeView, &tvitem);
  1007. pADMFile = (ADMFile*)tvitem.lParam;
  1008. if (hSelectedItem != NULL &&
  1009. TreeView_GetParent(hTreeView, hSelectedItem) == hItem)
  1010. {
  1011. TV_ITEM tvItem;
  1012. tvItem.mask = TVIF_PARAM;
  1013. tvItem.hItem = hSelectedItem;
  1014. TreeView_GetItem(hTreeView, &tvItem);
  1015. pADMCategory = (ADMCategory*)tvitem.lParam;
  1016. }
  1017. else
  1018. pADMCategory = NULL;
  1019. ZeroMemory(szInfFile, sizeof(szInfFile));
  1020. if(bReset)
  1021. {
  1022. getInfFileName(pADMFile->szFileName, szInfFile,
  1023. ARRAYSIZE(szInfFile), pcszWorkDir);
  1024. if (pADMCategory != NULL)
  1025. AdmReset(pADMFile->dwAdm, szInfFile, pADMFile->pData, pADMCategory->pData);
  1026. else
  1027. AdmReset(pADMFile->dwAdm, szInfFile, pADMFile->pData, NULL);
  1028. }
  1029. else
  1030. {
  1031. if (pADMCategory != NULL)
  1032. AdmReset(pADMFile->dwAdm, NULL, pADMFile->pData, pADMCategory->pData);
  1033. else
  1034. AdmReset(pADMFile->dwAdm, NULL, pADMFile->pData, NULL);
  1035. }
  1036. hItem = hNextItem;
  1037. }
  1038. if(hSelectedItem != NULL && isPolicyTree(hTreeView, hSelectedItem) && hSelectedItem != g_hPolicyRootItem &&
  1039. TreeView_GetParent(hTreeView, hSelectedItem) != g_hPolicyRootItem)
  1040. {
  1041. tvitem.mask = TVIF_PARAM;
  1042. tvitem.hItem = hSelectedItem;
  1043. TreeView_GetItem(hTreeView, &tvitem);
  1044. pADMCategory = (ADMCategory*)tvitem.lParam;
  1045. EnableWindow(pADMCategory->hWnd, TRUE);
  1046. }
  1047. }
  1048. static void saveAdmFilesHelper(HWND hTreeView, LPCTSTR pcszWorkDir, LPCTSTR pcszInsFile)
  1049. {
  1050. HTREEITEM hItem = TreeView_GetChild(hTreeView, g_hPolicyRootItem); // get first policy item
  1051. HTREEITEM hNextItem = NULL;
  1052. TV_ITEM tvitem;
  1053. TCHAR szInfFile[MAX_PATH];
  1054. TCHAR szRegistryData[MAX_PATH + 15];
  1055. TCHAR szBaseFileName[_MAX_FNAME];
  1056. LPTSTR pExt = NULL;
  1057. ADMFile* pADMFile;
  1058. if(!IsAdmDirty() || g_hPolicyRootItem == NULL) // no elements under policy item
  1059. return;
  1060. while(hItem != NULL) // if items in the tree view
  1061. {
  1062. hNextItem = TreeView_GetNextSibling(hTreeView, hItem); // get next item
  1063. tvitem.mask = TVIF_PARAM;
  1064. tvitem.hItem = hItem;
  1065. TreeView_GetItem(hTreeView, &tvitem);
  1066. pADMFile = (ADMFile*)tvitem.lParam;
  1067. ZeroMemory(szInfFile, sizeof(szInfFile));
  1068. getInfFileName(pADMFile->szFileName, szInfFile,
  1069. ARRAYSIZE(szInfFile), pcszWorkDir);
  1070. StrCpy(szBaseFileName, PathFindFileName(szInfFile));
  1071. PathRemoveExtension(szBaseFileName);
  1072. AdmFinished(pADMFile->dwAdm, szInfFile, pADMFile->pData);
  1073. if (PathFileExists(szInfFile))
  1074. {
  1075. pExt = PathFindExtension(szInfFile);
  1076. wnsprintf(szRegistryData, ARRAYSIZE(szRegistryData),
  1077. TEXT("*,%s,DefaultInstall"), PathFindFileName(szInfFile));
  1078. InsWriteString(IS_EXTREGINF, szBaseFileName, szRegistryData, pcszInsFile);
  1079. if (!InsIsSectionEmpty(TEXT("AddRegSection.HKLM"), szInfFile))
  1080. {
  1081. wnsprintf(szRegistryData, ARRAYSIZE(szRegistryData),
  1082. TEXT("%s,IEAKInstall.HKLM"), PathFindFileName(szInfFile));
  1083. InsWriteString(IS_EXTREGINF_HKLM, szBaseFileName, szRegistryData, pcszInsFile);
  1084. }
  1085. if (!InsIsSectionEmpty(TEXT("AddRegSection.HKCU"), szInfFile))
  1086. {
  1087. wnsprintf(szRegistryData, ARRAYSIZE(szRegistryData),
  1088. TEXT("%s,IEAKInstall.HKCU"), PathFindFileName(szInfFile));
  1089. InsWriteString(IS_EXTREGINF_HKCU, szBaseFileName, szRegistryData, pcszInsFile);
  1090. }
  1091. }
  1092. hItem = hNextItem;
  1093. }
  1094. WritePrivateProfileString(NULL, NULL, NULL, pcszInsFile);
  1095. }
  1096. //*********
  1097. // CDscrWnd
  1098. // This window is used to display the description title and text for the top level item selected in the treeview.
  1099. CDscrWnd::CDscrWnd()
  1100. {
  1101. hWndMain = NULL;
  1102. hWndDscrTitle = NULL;
  1103. hWndDscrText = NULL;
  1104. hFontDscrTitle = NULL;
  1105. }
  1106. CDscrWnd::~CDscrWnd()
  1107. {
  1108. if (hFontDscrTitle != NULL)
  1109. {
  1110. DeleteObject(hFontDscrTitle);
  1111. hFontDscrTitle = NULL;
  1112. }
  1113. if (hWndMain != NULL) //destroying the main window destroys its child windows
  1114. DestroyWindow(hWndMain);
  1115. }
  1116. static WNDPROC g_lpfnDscrTextWndProc = NULL;
  1117. LRESULT CALLBACK DscrTextWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1118. {
  1119. if (uMsg == WM_GETDLGCODE)
  1120. return (DLGC_WANTARROWS | DLGC_WANTCHARS);
  1121. return (CallWindowProc(g_lpfnDscrTextWndProc, hWnd, uMsg, wParam, lParam));
  1122. }
  1123. void CDscrWnd::Create(HWND hWndParent, HWND hWndInsertAfter, int nXPos, int nYPos, int nWidth,
  1124. int nHeight)
  1125. {
  1126. if (hWndMain != NULL) // already created
  1127. return;
  1128. // create the main window
  1129. hWndMain = CreateWindowEx(WS_EX_CONTROLPARENT, TEXT("STATIC"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_GROUP,
  1130. nXPos, nYPos, nWidth, nHeight, hWndParent, NULL, g_hInst, NULL);
  1131. if (hWndMain == NULL)
  1132. return;
  1133. if (hWndInsertAfter != NULL)
  1134. SetWindowPos(hWndMain, hWndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  1135. // create the description title window
  1136. hWndDscrTitle = CreateWindowEx(0, TEXT("STATIC"), TEXT(""), WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX,
  1137. 0, 0, nWidth, 0, hWndMain, NULL, g_hInst, NULL );
  1138. if (hWndDscrTitle == NULL)
  1139. return;
  1140. // change the font of the title to make it bold
  1141. HDC hDC = GetDC(hWndDscrTitle);
  1142. if (hFontDscrTitle == NULL)
  1143. hFontDscrTitle = getBoldFont(hWndDscrTitle);
  1144. if (hFontDscrTitle)
  1145. SelectObject(hDC, hFontDscrTitle);
  1146. ReleaseDC(hWndDscrTitle, hDC);
  1147. // create the description text window
  1148. hWndDscrText = CreateWindowEx(0, TEXT("EDIT"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_VSCROLL |
  1149. ES_LEFT | ES_MULTILINE | ES_READONLY,
  1150. 0, 25, nWidth, 0, hWndMain, NULL, g_hInst, NULL );
  1151. if (hWndDscrText == NULL)
  1152. return;
  1153. // change the font of the text to default gui font
  1154. HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
  1155. SendMessage(hWndDscrText, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
  1156. g_lpfnDscrTextWndProc = (WNDPROC) GetWindowLongPtr(hWndDscrText, GWLP_WNDPROC);
  1157. SetWindowLongPtr(hWndDscrText, GWLP_WNDPROC, (LONG_PTR) DscrTextWndProc);
  1158. }
  1159. void CDscrWnd::ShowWindow(BOOL fShow)
  1160. {
  1161. if (hWndMain != NULL)
  1162. {
  1163. if (fShow)
  1164. ::ShowWindow(hWndMain, SW_SHOWNORMAL);
  1165. else
  1166. ::ShowWindow(hWndMain, SW_HIDE);
  1167. }
  1168. }
  1169. void CDscrWnd::SetText(LPCTSTR pcszTitle, LPCTSTR pcszText, BOOL fUpdateWindowState)
  1170. {
  1171. int nYPos = 0;
  1172. HDC hDC = NULL;
  1173. int nHeight = 0;
  1174. int nWidth = 0;
  1175. RECT rect;
  1176. if (hWndMain == NULL)
  1177. return;
  1178. if (fUpdateWindowState)
  1179. ::ShowWindow(hWndMain, SW_SHOWNORMAL);
  1180. if (hWndDscrTitle != NULL)
  1181. {
  1182. if(pcszTitle == NULL || *pcszTitle == TEXT('\0'))
  1183. {
  1184. if (fUpdateWindowState)
  1185. ::ShowWindow(hWndDscrTitle, SW_HIDE);
  1186. }
  1187. else
  1188. {
  1189. GetClientRect(GetParent(hWndDscrTitle), &rect);
  1190. nWidth = rect.right;
  1191. hDC = GetDC(hWndDscrTitle);
  1192. nHeight = DrawText(hDC, pcszTitle, -1, &rect, DT_LEFT | DT_WORDBREAK | DT_CALCRECT);
  1193. ReleaseDC(hWndDscrTitle, hDC);
  1194. SetWindowPos(hWndDscrTitle, NULL, 0, 0, nWidth, nHeight, SWP_NOMOVE | SWP_NOZORDER);
  1195. SetWindowText(hWndDscrTitle, pcszTitle);
  1196. nYPos = nHeight + 5;
  1197. if (fUpdateWindowState)
  1198. ::ShowWindow(hWndDscrTitle, SW_SHOWNORMAL);
  1199. }
  1200. }
  1201. if (hWndDscrText != NULL)
  1202. {
  1203. if (pcszText == NULL || *pcszText == TEXT('\0'))
  1204. {
  1205. if (fUpdateWindowState)
  1206. ::ShowWindow(hWndDscrText, SW_HIDE);
  1207. }
  1208. else
  1209. {
  1210. GetClientRect(GetParent(hWndDscrText), &rect);
  1211. SetWindowPos(hWndDscrText, NULL, 0, nYPos, rect.right, rect.bottom - nYPos, SWP_NOZORDER);
  1212. SetWindowText(hWndDscrText, pcszText);
  1213. if (fUpdateWindowState)
  1214. ::ShowWindow(hWndDscrText, SW_SHOWNORMAL);
  1215. }
  1216. }
  1217. }
  1218. void CDscrWnd::GetRect(RECT* lpRect)
  1219. {
  1220. ZeroMemory(lpRect, sizeof(RECT));
  1221. if (hWndMain != NULL)
  1222. GetWindowRect(hWndMain, lpRect);
  1223. }
  1224. void CDscrWnd::MoveWindow(int nXPos, int nYPos, int nWidth, int nHeight)
  1225. {
  1226. TCHAR szDscrTitle[ADM_TITLELEN];
  1227. TCHAR szDscr[ADM_DSCRLEN];
  1228. if (hWndMain == NULL)
  1229. return;
  1230. ::MoveWindow(hWndMain, nXPos, nYPos, nWidth, nHeight, TRUE);
  1231. ZeroMemory(szDscrTitle, ADM_TITLELEN);
  1232. if (hWndDscrTitle != NULL)
  1233. GetWindowText(hWndDscrTitle, szDscrTitle, ADM_TITLELEN);
  1234. ZeroMemory(szDscr, ADM_DSCRLEN);
  1235. if (hWndDscrText != NULL)
  1236. GetWindowText(hWndDscrText, szDscr, ADM_DSCRLEN);
  1237. SetText(szDscrTitle, szDscr, FALSE);
  1238. }
  1239. static HFONT getBoldFont(HWND hWnd)
  1240. {
  1241. static HFONT hFont = NULL;
  1242. LOGFONT lf;
  1243. TEXTMETRIC tm;
  1244. HDC hDC;
  1245. int nFontSize = 0;
  1246. ZeroMemory(&lf, sizeof(lf));
  1247. if (hFont == NULL)
  1248. {
  1249. if (GetFontInfo != NULL)
  1250. GetFontInfo(lf.lfFaceName, &nFontSize);
  1251. if (*(lf.lfFaceName) == TEXT('\0'))
  1252. {
  1253. StrCpy(lf.lfFaceName, TEXT("MS Sans Serif"));
  1254. nFontSize = 10;
  1255. }
  1256. hDC = GetDC(hWnd);
  1257. lf.lfHeight = -((nFontSize * GetDeviceCaps(hDC, LOGPIXELSY)) / 72);
  1258. lf.lfWeight = FW_BOLD;
  1259. GetTextMetrics(hDC, &tm);
  1260. lf.lfCharSet = tm.tmCharSet;
  1261. ReleaseDC(hWnd, hDC);
  1262. hFont = CreateFontIndirect(&lf);
  1263. }
  1264. return hFont;
  1265. }
  1266. static BOOL getAdmFileListHelper(LPRESULTITEM* pResultItems, int* pnResultItems, int nRole)
  1267. {
  1268. WIN32_FIND_DATA FindFileData;
  1269. TCHAR szFileName[MAX_PATH];
  1270. TCHAR szADMFilePath[MAX_PATH];
  1271. int nAdmFiles = 0;
  1272. int nAllocatedBuffer = 10;
  1273. *pResultItems = (LPRESULTITEM) CoTaskMemAlloc(sizeof(RESULTITEM) * nAllocatedBuffer);
  1274. if (*pResultItems == NULL)
  1275. {
  1276. ErrorMessageBox(NULL, IDS_MEMORY_ERROR, MB_ICONEXCLAMATION | MB_OK);
  1277. return FALSE;
  1278. }
  1279. // BUGBUG: for now assume the admfilepath
  1280. GetWindowsDirectory(szADMFilePath, countof(szADMFilePath));
  1281. PathAppend(szADMFilePath, TEXT("INF"));
  1282. PathCombine(szFileName, szADMFilePath, TEXT("*.adm"));
  1283. HANDLE hFind = FindFirstFile(szFileName, &FindFileData);
  1284. if(hFind != INVALID_HANDLE_VALUE)
  1285. {
  1286. do
  1287. {
  1288. TCHAR szBuffer[MAX_PATH];
  1289. LPRESULTITEM lpResultItem;
  1290. PathCombine(szFileName, szADMFilePath, FindFileData.cFileName);
  1291. if (InsIsSectionEmpty(TEXT("IEAK"), szFileName) ||
  1292. !isADMFileVisibleHelper(szFileName, nRole, g_dwPlatformId))
  1293. continue;
  1294. if (nAdmFiles >= nAllocatedBuffer)
  1295. {
  1296. LPVOID lpTemp;
  1297. nAllocatedBuffer += 5;
  1298. lpTemp = CoTaskMemRealloc(*pResultItems, sizeof(RESULTITEM) * nAllocatedBuffer);
  1299. if (lpTemp == NULL)
  1300. {
  1301. ErrorMessageBox(NULL, IDS_MEMORY_ERROR, MB_ICONINFORMATION | MB_OK);
  1302. CoTaskMemFree(*pResultItems);
  1303. *pResultItems = NULL;
  1304. return FALSE;
  1305. }
  1306. *pResultItems = (LPRESULTITEM) lpTemp;
  1307. }
  1308. ZeroMemory(&((*pResultItems)[nAdmFiles]), sizeof((*pResultItems)[nAdmFiles]));
  1309. GetPrivateProfileString(IS_STRINGS, TEXT("IEAK_Title"), szFileName,
  1310. szBuffer, countof(szBuffer), szFileName);
  1311. lpResultItem = &((*pResultItems)[nAdmFiles]);
  1312. if ((lpResultItem->pszName = (LPTSTR)CoTaskMemAlloc(StrCbFromSz(szBuffer))) != NULL)
  1313. StrCpy(lpResultItem->pszName, szBuffer);
  1314. if ((lpResultItem->pszDesc = (LPTSTR)CoTaskMemAlloc(StrCbFromSz(szFileName))) != NULL)
  1315. StrCpy(lpResultItem->pszDesc, szFileName);
  1316. nAdmFiles++;
  1317. }while(FindNextFile(hFind, &FindFileData));
  1318. FindClose(hFind);
  1319. }
  1320. *pnResultItems = nAdmFiles;
  1321. return TRUE;
  1322. }