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.

2859 lines
99 KiB

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <commdlg.h>
  4. #include <commctrl.h>
  5. #include <stdlib.h>
  6. #include <shellapi.h>
  7. #include <objbase.h>
  8. #include <wininet.h>
  9. #include <shlwapi.h>
  10. #include "iedkbrnd.h"
  11. #include "treeview.h"
  12. #include "resource.h"
  13. #include "extract.h"
  14. #include <advpub.h>
  15. #include <mlang.h>
  16. #include "..\..\ieakeng\exports.h"
  17. #include "..\..\ieakutil\ieakutil.h"
  18. #include "..\..\ieakui\insexe.h"
  19. #include <htmlhelp.h> // for html help calls
  20. #include "insedit.h"
  21. #include "admparse.h"
  22. #include <ntverp.h> //these are for
  23. #include <common.ver> //ver_productversion_str
  24. HINSTANCE g_hInst;
  25. static HINSTANCE s_hInstIeakUI;
  26. HWND g_hMain;
  27. TCHAR g_szInsFile[MAX_PATH];
  28. TCHAR g_szFileName[MAX_PATH];
  29. LPINSDLG g_pInsDialog;
  30. int g_nDialogs;
  31. TCHAR g_szDesktopDir[MAX_PATH];
  32. TCHAR g_szCabsURLPath[INTERNET_MAX_URL_LENGTH];
  33. TCHAR g_szConfigURLPath[INTERNET_MAX_URL_LENGTH];
  34. TCHAR g_szDesktopURLPath[INTERNET_MAX_URL_LENGTH];
  35. TCHAR g_szConfigCabName[MAX_PATH];
  36. TCHAR g_szDesktopCabName[MAX_PATH];
  37. TCHAR g_szNewVersionStr[32];
  38. static TCHAR s_szUnsignedFiles[MAX_PATH*3] = TEXT("");
  39. // for Res2Str
  40. TCHAR g_szTemp[1024];
  41. TCHAR g_szTemp2[1024];
  42. CTreeView TreeView;
  43. HWND g_hDialog = NULL;
  44. HTREEITEM g_hInsRootItem = NULL;
  45. HTREEITEM g_hPolicyRootItem = NULL;
  46. HWND g_hWndAdmInstr = NULL;
  47. int g_InsSettingsOpen, g_InsSettingsClose, g_InsLeafItem, g_TreeLeaf, g_PolicyOpen,
  48. g_PolicyClose, g_ADMOpen, g_ADMClose;
  49. TCHAR g_szCabWorkDir[MAX_PATH];
  50. TCHAR g_szCabTempDir[MAX_PATH];
  51. TCHAR g_szRoot[MAX_PATH];
  52. TCHAR g_szLanguage[10];
  53. DWORD g_dwLanguage = 0xffffffff;
  54. TCHAR g_szDefInf[MAX_PATH];
  55. TCHAR g_szCurrInsPath[MAX_PATH];
  56. DWORD g_dwPlatformId = PLATFORM_WIN32;
  57. TCHAR g_szCmdLine[MAX_PATH];
  58. HWND g_hWndHelp = NULL;
  59. TCHAR *Res2Str(int nString)
  60. {
  61. static BOOL fSet = FALSE;
  62. if(fSet)
  63. {
  64. if (LoadString(g_hInst, nString, g_szTemp, ARRAYSIZE(g_szTemp)) == 0)
  65. LoadString(s_hInstIeakUI, nString, g_szTemp, ARRAYSIZE(g_szTemp));
  66. fSet = FALSE;
  67. return(g_szTemp);
  68. }
  69. if (LoadString(g_hInst, nString, g_szTemp2, ARRAYSIZE(g_szTemp2)) == 0)
  70. LoadString(s_hInstIeakUI, nString, g_szTemp2, ARRAYSIZE(g_szTemp2));
  71. fSet = TRUE;
  72. return(g_szTemp2);
  73. }
  74. BOOL BrowseForFileEx(HWND hWnd, LPTSTR szFilter, LPTSTR szFileName, int cchSize, LPTSTR szDefExt)
  75. {
  76. OPENFILENAME ofn;
  77. ofn.lStructSize = sizeof(OPENFILENAME);
  78. ofn.hwndOwner = hWnd;
  79. ofn.hInstance = g_hInst;
  80. ofn.lpstrFilter = szFilter;
  81. ofn.lpstrCustomFilter = NULL;
  82. ofn.nFilterIndex = 0;
  83. ofn.lpstrFile = szFileName;
  84. ofn.nMaxFile = cchSize;
  85. ofn.lpstrFileTitle = NULL;
  86. ofn.lpstrInitialDir = g_szCurrInsPath;
  87. ofn.lpstrTitle = NULL;
  88. ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  89. ofn.nFileOffset = 0;
  90. ofn.nFileExtension = 0;
  91. ofn.lpstrDefExt = szDefExt;
  92. return GetOpenFileName(&ofn);
  93. }
  94. BOOL BrowseForSave(HWND hWnd, LPTSTR szFilter, LPTSTR szFileName, int nSize, LPTSTR szDefExt)
  95. {
  96. OPENFILENAME ofn;
  97. TCHAR szDir[MAX_PATH];
  98. LPTSTR lpExt;
  99. StrCpy(szDir, szFileName);
  100. lpExt = PathFindExtension(szFileName);
  101. if (*lpExt != TEXT('\0'))
  102. {
  103. StrCpy(szFileName, PathFindFileName(szDir));
  104. PathRemoveFileSpec(szDir);
  105. }
  106. else
  107. *szFileName = TEXT('\0');
  108. ofn.lStructSize = sizeof(OPENFILENAME);
  109. ofn.hwndOwner = hWnd;
  110. ofn.hInstance = g_hInst;
  111. ofn.lpstrFilter = szFilter;
  112. ofn.lpstrCustomFilter = NULL;
  113. ofn.nFilterIndex = 0;
  114. ofn.lpstrFile = szFileName;
  115. ofn.nMaxFile = nSize;
  116. ofn.lpstrFileTitle = NULL;
  117. ofn.lpstrInitialDir = szDir;
  118. ofn.lpstrTitle = NULL;
  119. ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  120. ofn.nFileOffset = 0;
  121. ofn.nFileExtension = 0;
  122. ofn.lpstrDefExt = szDefExt;
  123. return GetSaveFileName(&ofn);
  124. }
  125. void SetTitleBar(HWND hWnd, LPTSTR szFileName)
  126. {
  127. TCHAR szTitleBar[1024];
  128. if(szFileName == NULL)
  129. wsprintf(szTitleBar, Res2Str(IDS_TITLE1));
  130. else
  131. wsprintf(szTitleBar, Res2Str(IDS_TITLE2), szFileName);
  132. SetWindowText(hWnd, szTitleBar);
  133. }
  134. void NewTempFile()
  135. {
  136. TCHAR szTempPath[MAX_PATH];
  137. DeleteFile(g_szInsFile);
  138. ZeroMemory(g_szInsFile, sizeof(g_szInsFile));
  139. GetTempPath(ARRAYSIZE(szTempPath), szTempPath);
  140. GetTempFileName(szTempPath, TEXT("INS"), 0, g_szInsFile);
  141. }
  142. void SetStockFont(HWND hWnd)
  143. {
  144. HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  145. SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
  146. }
  147. int GetSelIndex()
  148. {
  149. int i;
  150. HTREEITEM hItem = TreeView.GetSel();
  151. for(i = 0; i < g_nDialogs; i++)
  152. {
  153. if(hItem == g_pInsDialog[i].hItem)
  154. return i;
  155. }
  156. return 0;
  157. }
  158. BOOL IsPolicyTree(HTREEITEM hItem)
  159. {
  160. BOOL bRet = FALSE;
  161. HTREEITEM hParentItem = NULL;
  162. while(1)
  163. {
  164. hParentItem = TreeView_GetParent(TreeView.GetHandle(), hItem);
  165. if(hParentItem == NULL)
  166. {
  167. bRet = (hItem == g_hPolicyRootItem) ? TRUE : FALSE;
  168. break;
  169. }
  170. hItem = hParentItem;
  171. };
  172. return bRet;
  173. }
  174. // Creates image list, adds bitmaps/icons to it, and associates the image
  175. // list with the treeview control.
  176. LRESULT InitImageList(HWND hTreeView)
  177. {
  178. HIMAGELIST hWndImageList;
  179. HICON hIcon;
  180. hWndImageList = ImageList_Create(GetSystemMetrics (SM_CXSMICON),
  181. GetSystemMetrics (SM_CYSMICON),
  182. TRUE,
  183. NUM_ICONS,
  184. 8);
  185. if(!hWndImageList)
  186. {
  187. return FALSE;
  188. }
  189. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2));
  190. g_InsSettingsOpen = ImageList_AddIcon(hWndImageList, hIcon);
  191. DestroyIcon(hIcon);
  192. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON3));
  193. g_InsSettingsClose = ImageList_AddIcon(hWndImageList, hIcon);
  194. DestroyIcon(hIcon);
  195. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON4));
  196. g_TreeLeaf = ImageList_AddIcon(hWndImageList, hIcon);
  197. DestroyIcon(hIcon);
  198. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON5));
  199. g_PolicyOpen = ImageList_AddIcon(hWndImageList, hIcon);
  200. DestroyIcon(hIcon);
  201. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON6));
  202. g_PolicyClose = ImageList_AddIcon(hWndImageList, hIcon);
  203. DestroyIcon(hIcon);
  204. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON7));
  205. g_ADMOpen = ImageList_AddIcon(hWndImageList, hIcon);
  206. DestroyIcon(hIcon);
  207. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON8));
  208. g_ADMClose = ImageList_AddIcon(hWndImageList, hIcon);
  209. DestroyIcon(hIcon);
  210. hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON9));
  211. g_InsLeafItem = ImageList_AddIcon(hWndImageList, hIcon);
  212. DestroyIcon(hIcon);
  213. // Fail if not all images were added.
  214. if (ImageList_GetImageCount(hWndImageList) < NUM_ICONS)
  215. {
  216. // ERROR: Unable to add all images to image list.
  217. return FALSE;
  218. }
  219. // Associate image list with treeView control.
  220. TreeView_SetImageList(hTreeView, hWndImageList, TVSIL_NORMAL);
  221. return TRUE;
  222. }
  223. void InitTreeView(HWND hTreeView, HWND hInfoWnd)
  224. {
  225. TCHAR szTemp[MAX_PATH];
  226. ShowADMWindow(hTreeView, FALSE);
  227. for(int i = 0; i < g_nDialogs; i++)
  228. g_pInsDialog[i].hItem = TreeView.AddItem(g_pInsDialog[i].szName, g_hInsRootItem);
  229. SetInfoWindowText(hInfoWnd, Res2Str(IDS_LOADADMFILEMSG));
  230. wsprintf(szTemp, TEXT("%sPolicies\\%s"), g_szRoot, g_szLanguage);
  231. LoadADMFiles(TreeView.GetHandle(), g_hPolicyRootItem, szTemp, g_szCabWorkDir,
  232. g_dwPlatformId, ROLE_CORP, g_ADMClose, g_InsLeafItem);
  233. if(TreeView_GetChild(TreeView.GetHandle(), g_hPolicyRootItem) == NULL) // if no items in the tree view
  234. MessageBox(hTreeView, Res2Str(IDS_NOPOLICYFILE), Res2Str(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  235. SetInfoWindowText(hInfoWnd, Res2Str(IDS_READYMSG));
  236. TreeView_Expand(TreeView.GetHandle(), g_hPolicyRootItem, TVE_EXPAND);
  237. TreeView_Expand(TreeView.GetHandle(), g_hInsRootItem, TVE_EXPAND);
  238. ShowADMWindow(hTreeView, TRUE);
  239. TreeView.SetSel(g_hInsRootItem);
  240. }
  241. LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  242. {
  243. int i;
  244. int nMinWidth = 0;
  245. int nMinHeight = 0;
  246. DWORD dwType = REG_SZ;
  247. DWORD dwSize = sizeof(g_szCurrInsPath);
  248. DWORD dwDisposition;
  249. DWORD dwCabBuildStatus;
  250. TCHAR szItem[100];
  251. TCHAR szTempFile[MAX_PATH];
  252. TCHAR szMsg[MAX_PATH];
  253. TCHAR szLangId[MAX_PATH];
  254. TCHAR szTemp[MAX_PATH];
  255. TCHAR szFilter[MAX_PATH];
  256. LPTSTR pszFilter = NULL;
  257. NM_TREEVIEW *lpNMTreeView;
  258. TV_ITEM tvitem, tvitem1;
  259. HTREEITEM hItem;
  260. HWND hWndFocus;
  261. HMENU hMenu;
  262. HKEY hKey;
  263. RECT rect1, rect2;
  264. LPMINMAXINFO lpmmi = NULL;
  265. static BOOL bSwitchScreen = TRUE;
  266. static BOOL fCanResize = FALSE;
  267. static BOOL fDirty = FALSE;
  268. static HWND hWndSizeBar = NULL;
  269. static HWND hInfoWnd = NULL;
  270. static HCURSOR hCurVTResize = NULL;
  271. static int nPrevXPos = 0;
  272. static int nTreeViewWidth = TREEVIEW_WIDTH;
  273. static TCHAR szRecentFileList[5][MAX_PATH];
  274. static TCHAR szFileToOpen[MAX_PATH];
  275. static HWND hErrorDlgCtrl = NULL;
  276. switch(msg)
  277. {
  278. case WM_CREATE:
  279. SetWindowText(hWnd, Res2Str(IDS_TITLE));
  280. ZeroMemory(g_szCurrInsPath, sizeof(g_szCurrInsPath));
  281. if(RegOpenKeyEx(HKEY_CURRENT_USER, RK_IEAK_SERVER TEXT("\\ProfMgr"), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  282. {
  283. RegQueryValueEx(hKey, TEXT("LastOpenedPath"), NULL, &dwType, (LPBYTE) g_szCurrInsPath, &dwSize);
  284. dwType = REG_DWORD;
  285. dwSize = sizeof(nTreeViewWidth);
  286. if (RegQueryValueEx(hKey, TEXT("TreeviewWidth"), NULL, &dwType, (LPBYTE) &nTreeViewWidth, &dwSize) != ERROR_SUCCESS)
  287. nTreeViewWidth = TREEVIEW_WIDTH;
  288. RegCloseKey(hKey);
  289. }
  290. TreeView.Create(hWnd, MARGIN, MARGIN, nTreeViewWidth, TREEVIEW_HEIGHT);
  291. InitImageList(TreeView.GetHandle());
  292. // Create the INS dialog to get the intial size of the right hand pane
  293. g_hDialog = CreateInsDialog(hWnd, nTreeViewWidth + (2*MARGIN), 0, 0, g_szInsFile, g_szCabWorkDir);
  294. EnableWindow(g_hDialog, FALSE);
  295. hInfoWnd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("STATIC"), TEXT(""), WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hWnd, NULL, g_hInst, 0);
  296. if (hInfoWnd)
  297. SetStockFont(hInfoWnd);
  298. GetWindowRect(g_hDialog, &rect1);
  299. GetWindowRect(hWnd, &rect2);
  300. nMinWidth = (3 * MARGIN) + nTreeViewWidth + (rect1.right - rect1.left) +
  301. (2 * GetSystemMetrics(SM_CXFIXEDFRAME)) + 4;
  302. nMinHeight = (2 * MARGIN) + (rect1.bottom - rect1.top) +
  303. (hInfoWnd ? INFOWINDOW_HEIGHT : 0) +
  304. GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION) +
  305. (2 * GetSystemMetrics(SM_CYFIXEDFRAME)) + 4;
  306. GetWindowRect(GetDesktopWindow(), &rect1); // center the window on the desktop
  307. rect2.left = ((rect1.right - rect1.left)/2) - (nMinWidth/2);
  308. rect2.top = ((rect1.bottom - rect1.top)/2) - (nMinHeight/2);
  309. MoveWindow(hWnd, (rect2.left > 0) ? rect2.left : 0, (rect2.top > 0) ? rect2.top : 0, nMinWidth, nMinHeight, TRUE);
  310. g_hWndAdmInstr = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("STATIC"), TEXT(""),
  311. WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hWnd, NULL, g_hInst, 0);
  312. CreateADMWindow(TreeView.GetHandle(), NULL, 0, 0, 0, 0);
  313. ShowADMWindow(TreeView.GetHandle(), FALSE);
  314. hWndSizeBar = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("STATIC"), TEXT("SizeBarWnd"),
  315. WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hWnd, NULL, g_hInst, 0);
  316. LoadString(g_hInst, IDS_WIZARDSETTINGS, szMsg, ARRAYSIZE(szMsg));
  317. g_hInsRootItem = TreeView.AddItem(szMsg);
  318. DestroyInsDialog(g_hDialog);
  319. g_hDialog = NULL;
  320. LoadString(g_hInst, IDS_POLICYSETTINGS, szMsg, ARRAYSIZE(szMsg));
  321. g_hPolicyRootItem = TreeView.AddItem(szMsg);
  322. ShowWindow(hWnd, SW_SHOWNORMAL);
  323. ZeroMemory(g_szLanguage, sizeof(g_szLanguage));
  324. ZeroMemory(g_szDefInf, sizeof(g_szDefInf));
  325. DialogBox(g_hInst, MAKEINTRESOURCE(IDD_LANGDLG), hWnd, LanguageDialogProc);
  326. if(*g_szLanguage != TEXT('\0'))
  327. {
  328. // check whether the Optional Cab has been downloaded for a particular platform
  329. // and language.
  330. hMenu = GetSubMenu(GetMenu(hWnd), 2);
  331. CheckMenuItem(hMenu, IDM_PLATFORM_WIN32, MF_BYCOMMAND | MF_UNCHECKED);
  332. if (PlatformExists(hWnd, g_szLanguage, g_dwPlatformId)) // g_dwPlatformId = PLATFORM_WIN32
  333. CheckMenuItem(hMenu, IDM_PLATFORM_WIN32, MF_BYCOMMAND | MF_CHECKED);
  334. else
  335. g_dwPlatformId = 0;
  336. }
  337. if (*g_szLanguage == TEXT('\0') || !g_dwPlatformId)
  338. {
  339. TCHAR szWin32Text[25];
  340. LPTSTR pMsg;
  341. StrCpy(szWin32Text, Res2Str(IDS_WIN32));
  342. pMsg = FormatString(Res2Str(IDS_NOLANGDIR), szWin32Text);
  343. MessageBox(hWnd, pMsg, Res2Str(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  344. LocalFree(pMsg);
  345. return -1;
  346. }
  347. // default inf
  348. GetDefaultInf(g_dwPlatformId);
  349. SetDefaultInf(g_szDefInf);
  350. SetPlatformInfo(g_dwPlatformId);
  351. ReInitializeInsDialogProcs();
  352. g_pInsDialog = GetInsDlgStruct(&g_nDialogs);
  353. SetFocus(g_hWndAdmInstr);
  354. EnableWindow(TreeView.GetHandle(), FALSE);
  355. // read the recent file list from the registry
  356. ReadRecentFileList(szRecentFileList);
  357. UpdateRecentFileListMenu(hWnd, szRecentFileList);
  358. hCurVTResize = LoadCursor(NULL, IDC_SIZEWE);
  359. SetInfoWindowText(hInfoWnd);
  360. // forcing the status info window to redraw entirely before initilaizing the treeview.
  361. RedrawWindow(hInfoWnd, NULL, NULL, RDW_ERASENOW | RDW_UPDATENOW);
  362. PostMessage(hWnd, UM_INIT_TREEVIEW, 0, 0L);
  363. if (*g_szCmdLine != TEXT('\0'))
  364. {
  365. StrCpy(szFileToOpen, g_szCmdLine);
  366. PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_FILEOPEN, 0), 1L);
  367. }
  368. break;
  369. case UM_INIT_TREEVIEW:
  370. InitTreeView(TreeView.GetHandle(), hInfoWnd);
  371. break;
  372. case WM_GETMINMAXINFO:
  373. lpmmi = (LPMINMAXINFO) lParam;
  374. lpmmi->ptMaxTrackSize.x = MAX_WINDOW_WIDTH;
  375. lpmmi->ptMaxTrackSize.y = MAX_WINDOW_HEIGHT;
  376. return FALSE;
  377. case WM_SIZE:
  378. TreeView.MoveWindow(MARGIN, MARGIN, nTreeViewWidth, (int)HIWORD(lParam)-(2*MARGIN));
  379. MoveWindow(g_hWndAdmInstr, nTreeViewWidth + (2*MARGIN),
  380. MARGIN, LOWORD(lParam) - (nTreeViewWidth + (2*MARGIN)) - MARGIN,
  381. (int)HIWORD(lParam) - (hInfoWnd ? INFOWINDOW_HEIGHT : 0) -
  382. (2*MARGIN), TRUE);
  383. MoveADMWindow(TreeView.GetHandle(), nTreeViewWidth + (2*MARGIN) + 2, MARGIN + 2,
  384. LOWORD(lParam) - (nTreeViewWidth + (2*MARGIN)) - MARGIN - 4,
  385. (int)HIWORD(lParam) - (hInfoWnd ? INFOWINDOW_HEIGHT : 0) -
  386. (2*MARGIN) - 4);
  387. MoveWindow(hWndSizeBar, nTreeViewWidth + MARGIN, MARGIN, 4, (int)HIWORD(lParam)-(2*MARGIN), TRUE);
  388. MoveWindow(hInfoWnd, nTreeViewWidth + (2*MARGIN), (int)HIWORD(lParam) - INFOWINDOW_HEIGHT - MARGIN,
  389. LOWORD(lParam) - (nTreeViewWidth + (3*MARGIN)), INFOWINDOW_HEIGHT, TRUE);
  390. RedrawWindow(hInfoWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
  391. if (g_hDialog)
  392. {
  393. SetWindowPos(g_hDialog, HWND_TOP, nTreeViewWidth + (2*MARGIN) + 2, MARGIN + 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  394. RedrawWindow(g_hDialog, NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
  395. }
  396. else
  397. {
  398. hItem = TreeView.GetSel(); // get selected item
  399. if (hItem != NULL && IsPolicyTree(hItem))
  400. {
  401. HTREEITEM hParentItem = TreeView_GetParent(TreeView.GetHandle(), hItem);
  402. if (hParentItem != NULL && hParentItem != g_hPolicyRootItem)
  403. { // is a ADM category
  404. HWND hWndAdm = GetAdmWindowHandle(TreeView.GetHandle(), hItem); // category window handle
  405. if (hWndAdm)
  406. {
  407. SetWindowPos(hWndAdm, HWND_TOP, nTreeViewWidth + (2*MARGIN) + 2, MARGIN + 2, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  408. RedrawWindow(hWndAdm, NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
  409. }
  410. }
  411. }
  412. }
  413. break;
  414. case WM_NOTIFY:
  415. lpNMTreeView = (NM_TREEVIEW FAR *) lParam;
  416. if(lpNMTreeView->hdr.code == TVN_SELCHANGED)
  417. {
  418. if(bSwitchScreen == FALSE)
  419. {
  420. bSwitchScreen = TRUE;
  421. break;
  422. }
  423. if (lpNMTreeView->itemOld.hItem == NULL)
  424. ; // do nothing.
  425. else if (!IsPolicyTree(lpNMTreeView->itemOld.hItem)) // is ins item
  426. {
  427. if (lpNMTreeView->itemOld.hItem == g_hInsRootItem) // is root ins item
  428. ShowADMWindow(TreeView.GetHandle(), FALSE);
  429. else
  430. {
  431. if(g_hDialog)
  432. {
  433. if (!(bSwitchScreen = SaveInsDialog(g_hDialog, ITEM_SAVE | ITEM_DESTROY)))
  434. {
  435. fDirty = !bSwitchScreen;
  436. hErrorDlgCtrl = GetFocus();
  437. TreeView.SetSel(lpNMTreeView->itemOld.hItem);
  438. return 1;
  439. }
  440. else
  441. g_hDialog = NULL;
  442. }
  443. }
  444. }
  445. else // is policy item
  446. {
  447. if (lpNMTreeView->itemOld.hItem == g_hPolicyRootItem) // is root policy item
  448. ShowADMWindow(TreeView.GetHandle(), FALSE);
  449. else
  450. SelectADMItem(hWnd, TreeView.GetHandle(), &lpNMTreeView->itemOld, FALSE, FALSE);
  451. }
  452. if (lpNMTreeView->itemNew.hItem == NULL)
  453. ShowADMWindow(TreeView.GetHandle(), FALSE);
  454. else if (!IsPolicyTree(lpNMTreeView->itemNew.hItem)) // is ins item
  455. {
  456. if(lpNMTreeView->itemNew.hItem == g_hInsRootItem) // is root ins item
  457. {
  458. SetADMWindowText(TreeView.GetHandle(), Res2Str(IDS_WIZARDBRANCHTITLE), Res2Str(IDS_WIZARDBRANCHTEXT));
  459. }
  460. else
  461. {
  462. TreeView.GetItemText(lpNMTreeView->itemNew.hItem, szItem, ARRAYSIZE(szItem));
  463. for (i = 0; i < g_nDialogs; i++)
  464. {
  465. if (StrCmp(szItem, g_pInsDialog[i].szName) == 0)
  466. {
  467. g_hDialog = CreateInsDialog(hWnd, nTreeViewWidth + (2*MARGIN) + 2, MARGIN + 2, i, g_szInsFile, g_szCabWorkDir);
  468. if(lstrlen(g_szInsFile) == 0)
  469. EnableWindow(g_hDialog, FALSE);
  470. break;
  471. }
  472. }
  473. }
  474. }
  475. else // is policy item
  476. SelectADMItem(hWnd, TreeView.GetHandle(), &lpNMTreeView->itemNew, TRUE, ISNULL(g_szInsFile));
  477. SetInfoWindowText(hInfoWnd);
  478. }
  479. else if(lpNMTreeView->hdr.code == TVN_ITEMEXPANDED)
  480. {
  481. tvitem.mask = TVIF_IMAGE;
  482. tvitem.hItem = lpNMTreeView->itemNew.hItem;
  483. TreeView_GetItem(TreeView.GetHandle(), &tvitem);
  484. // If tree item is EXPANDING (opening up) and
  485. // current icon == CloseFolder, change icon to OpenFolder
  486. if(lpNMTreeView->action == TVE_EXPAND)
  487. {
  488. tvitem1.hItem = lpNMTreeView->itemNew.hItem;
  489. tvitem1.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  490. if(tvitem.iImage == g_InsSettingsClose)
  491. {
  492. tvitem1.iImage = g_InsSettingsOpen;
  493. tvitem1.iSelectedImage = g_InsSettingsOpen;
  494. }
  495. else if(tvitem.iImage == g_PolicyClose)
  496. {
  497. tvitem1.iImage = g_PolicyOpen;
  498. tvitem1.iSelectedImage = g_PolicyOpen;
  499. }
  500. else if(tvitem.iImage == g_ADMClose)
  501. {
  502. tvitem1.iImage = g_ADMOpen;
  503. tvitem1.iSelectedImage = g_ADMOpen;
  504. }
  505. else
  506. break;
  507. TreeView_SetItem(TreeView.GetHandle(), &tvitem1);
  508. }
  509. // If tree item is COLLAPSING (closing up) and
  510. // current icon == OpenFolder, change icon to CloseFolder
  511. else if(lpNMTreeView->action == TVE_COLLAPSE)
  512. {
  513. tvitem1.hItem = lpNMTreeView->itemNew.hItem;
  514. tvitem1.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  515. if(tvitem.iImage == g_InsSettingsOpen)
  516. {
  517. tvitem1.iImage = g_InsSettingsClose;
  518. tvitem1.iSelectedImage = g_InsSettingsClose;
  519. }
  520. else if(tvitem.iImage == g_PolicyOpen)
  521. {
  522. tvitem1.iImage = g_PolicyClose;
  523. tvitem1.iSelectedImage = g_PolicyClose;
  524. }
  525. else if(tvitem.iImage == g_ADMOpen)
  526. {
  527. tvitem1.iImage = g_ADMClose;
  528. tvitem1.iSelectedImage = g_ADMClose;
  529. }
  530. else
  531. break;
  532. TreeView_SetItem(TreeView.GetHandle(), &tvitem1);
  533. }
  534. break;
  535. }
  536. else if(lpNMTreeView->hdr.code == NM_SETFOCUS)
  537. {
  538. if (lpNMTreeView->hdr.hwndFrom == TreeView.GetHandle() && hErrorDlgCtrl != NULL)
  539. {
  540. SetFocus(g_hDialog);
  541. SetFocus(hErrorDlgCtrl);
  542. hErrorDlgCtrl = NULL;
  543. }
  544. }
  545. return DefWindowProc(hWnd, msg, wParam, lParam);
  546. case WM_COMMAND:
  547. // patch: if the message is a button down (return key), send the message to the
  548. // corresponding window
  549. if(g_hDialog && HIWORD(wParam) == BN_CLICKED)
  550. {
  551. hWndFocus = GetFocus();
  552. if(IsChild(g_hDialog, hWndFocus) && hWndFocus == (HWND) lParam)
  553. {
  554. SendMessage(g_hDialog, msg, MAKEWPARAM(LOWORD(GetDlgCtrlID(hWndFocus)), HIWORD(wParam)), (LPARAM) hWndFocus);
  555. }
  556. }
  557. switch (LOWORD(wParam))
  558. {
  559. case IDM_FILEEXIT:
  560. SendMessage(hWnd, WM_CLOSE, 0, 0);
  561. break;
  562. case IDM_FILENEW:
  563. if(lstrlen(g_szInsFile))
  564. {
  565. //save the current page
  566. SaveCurrentSelItem(TreeView.GetHandle(), ITEM_CHECKDIRTY);
  567. SetInfoWindowText(hInfoWnd);
  568. if (IsDirty())
  569. {
  570. int nError;
  571. wsprintf(szMsg, Res2Str(IDS_SAVE), lstrlen(g_szFileName) ? g_szFileName : Res2Str(IDS_UNTITLED));
  572. switch(MessageBox(hWnd, szMsg, Res2Str(IDS_TITLE), MB_YESNOCANCEL))
  573. {
  574. case IDCANCEL:
  575. return 1;
  576. case IDYES:
  577. nError = (int) SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_FILESAVE, 0), 0);
  578. if (nError == PAGE_ERROR || nError == SAVE_ERROR || nError == SAVE_CANCEL)
  579. return 1;
  580. break;
  581. case IDNO:
  582. break;
  583. }
  584. }
  585. ZeroMemory(g_szFileName, sizeof(g_szFileName));
  586. }
  587. ZeroMemory(g_szCabsURLPath, sizeof(g_szCabsURLPath));
  588. ZeroMemory(g_szConfigURLPath, sizeof(g_szConfigURLPath));
  589. ZeroMemory(g_szDesktopURLPath, sizeof(g_szDesktopURLPath));
  590. ZeroMemory(g_szConfigCabName, sizeof(g_szConfigCabName));
  591. ZeroMemory(g_szDesktopCabName, sizeof(g_szDesktopCabName));
  592. ZeroMemory(g_szNewVersionStr, sizeof(g_szNewVersionStr));
  593. EnableWindow(TreeView.GetHandle(), TRUE);
  594. DeleteCabWorkDirs();
  595. SaveCurrentSelItem(TreeView.GetHandle(), ITEM_DESTROY);
  596. TreeView.SetSel(NULL);
  597. ResetAdmFiles(TreeView.GetHandle(), g_szCabWorkDir, FALSE);
  598. NewTempFile();
  599. CreateCabWorkDirs(TEXT("new"));
  600. SetTitleBar(hWnd, NULL);
  601. WritePrivateProfileString(TEXT("Branding"), TEXT("Language Locale"), g_szLanguage, g_szInsFile);
  602. if(g_dwLanguage != 0xffffffff)
  603. {
  604. wsprintf(szLangId, TEXT("%lu"), g_dwLanguage);
  605. WritePrivateProfileString(TEXT("Branding"), TEXT("Language ID"), szLangId, g_szInsFile);
  606. }
  607. WritePrivateProfileString(URL_SECT, TEXT("AutoConfig"), TEXT("0"), g_szInsFile);
  608. // Collapse all policy treeview items that has been expanded
  609. TreeView.CollapseChildNodes(g_hPolicyRootItem);
  610. TreeView.SetSel(g_pInsDialog[0].hItem);
  611. SetFocus(TreeView.GetHandle());
  612. ClearDirtyFlag();
  613. SetInfoWindowText(hInfoWnd);
  614. break;
  615. case IDM_FILESAVE:
  616. if (!SaveCurrentSelItem(TreeView.GetHandle(), ITEM_SAVE))
  617. return PAGE_ERROR;
  618. SetInfoWindowText(hInfoWnd);
  619. dwCabBuildStatus = GetCabBuildStatus();
  620. DirectoryName(g_szFileName, szTemp); // szTemp will contain the INS path.
  621. if((PathFileExists(g_szFileName) &&
  622. ((!HasFlag(dwCabBuildStatus, CAB_TYPE_CONFIG) &&
  623. !HasFlag(dwCabBuildStatus, CAB_TYPE_DESKTOP)) || *g_szCabsURLPath) &&
  624. (!HasFlag(dwCabBuildStatus, CAB_TYPE_CONFIG) || *g_szConfigCabName) &&
  625. (!HasFlag(dwCabBuildStatus, CAB_TYPE_DESKTOP) || *g_szDesktopCabName)) &&
  626. !IsFileReadOnly(g_szFileName) && !IsFileReadOnly(g_szConfigCabName, szTemp) &&
  627. !IsFileReadOnly(g_szDesktopCabName, szTemp))
  628. {
  629. SetInfoWindowText(hInfoWnd, Res2Str(IDS_SAVEFILEMSG));
  630. wsprintf(szTemp, TEXT("%d"), g_dwPlatformId);
  631. WritePrivateProfileString(TEXT("Branding"), TEXT("Platform"), szTemp, g_szInsFile);
  632. SaveAdmFiles(TreeView.GetHandle(), g_szCabWorkDir, g_szInsFile);
  633. PrepareFolderForCabbing(g_szCabWorkDir, PM_COPY | PM_CLEAR);
  634. if (!DialogBox(s_hInstIeakUI, MAKEINTRESOURCE(IDD_DISPLAYSAVE), hWnd, DisplaySaveDlgProc))
  635. {
  636. SetInfoWindowText(hInfoWnd, Res2Str(IDS_READYMSG));
  637. return SAVE_ERROR;
  638. }
  639. SetInfoWindowText(hInfoWnd, Res2Str(IDS_READYMSG));
  640. ClearDirtyFlag();
  641. SetInfoWindowText(hInfoWnd);
  642. break;
  643. }
  644. // fallthrough
  645. case IDM_FILESAVEAS:
  646. if (LOWORD(wParam) == IDM_FILESAVEAS && !SaveCurrentSelItem(TreeView.GetHandle(), ITEM_SAVE))
  647. return PAGE_ERROR;
  648. SetInfoWindowText(hInfoWnd);
  649. StrCpy(szTempFile, g_szFileName);
  650. if(DialogBox(s_hInstIeakUI, MAKEINTRESOURCE(IDD_SAVEAS), hWnd, SaveAsDlgProc) == 0)
  651. {
  652. SetInfoWindowText(hInfoWnd, Res2Str(IDS_SAVEFILEMSG));
  653. wsprintf(szTemp, TEXT("%d"), g_dwPlatformId);
  654. WritePrivateProfileString(TEXT("Branding"), TEXT("Platform"), szTemp, g_szInsFile);
  655. SaveAdmFiles(TreeView.GetHandle(), g_szCabWorkDir, g_szInsFile);
  656. PrepareFolderForCabbing(g_szCabWorkDir, PM_COPY | PM_CLEAR);
  657. if (!DialogBox(s_hInstIeakUI, MAKEINTRESOURCE(IDD_DISPLAYSAVE), hWnd, DisplaySaveDlgProc))
  658. {
  659. SetInfoWindowText(hInfoWnd, Res2Str(IDS_READYMSG));
  660. // revert back the previous INS filename and CAB names.
  661. StrCpy(g_szFileName, szTempFile);
  662. GetCabName(g_szFileName, CAB_TYPE_CONFIG, g_szConfigCabName);
  663. GetCabName(g_szFileName, CAB_TYPE_DESKTOP, g_szDesktopCabName);
  664. return SAVE_ERROR;
  665. }
  666. SetTitleBar(hWnd, g_szFileName);
  667. UpdateRecentFileList(g_szFileName, TRUE, szRecentFileList);
  668. UpdateRecentFileListMenu(hWnd, szRecentFileList);
  669. SetInfoWindowText(hInfoWnd, Res2Str(IDS_READYMSG));
  670. ClearDirtyFlag();
  671. SetInfoWindowText(hInfoWnd);
  672. }
  673. else
  674. return SAVE_CANCEL;
  675. break;
  676. case IDM_FILEOPEN:
  677. if(lstrlen(g_szInsFile))
  678. {
  679. SaveCurrentSelItem(TreeView.GetHandle(), ITEM_CHECKDIRTY);
  680. SetInfoWindowText(hInfoWnd);
  681. if (IsDirty())
  682. {
  683. int nError;
  684. wsprintf(szMsg, Res2Str(IDS_SAVE), lstrlen(g_szFileName) ? g_szFileName : Res2Str(IDS_UNTITLED));
  685. switch(MessageBox(hWnd, szMsg, Res2Str(IDS_TITLE), MB_YESNOCANCEL))
  686. {
  687. case IDCANCEL:
  688. return 1;
  689. case IDYES:
  690. nError = (int) SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_FILESAVE, 0), 0);
  691. if (nError == PAGE_ERROR || nError == SAVE_ERROR || nError == SAVE_CANCEL)
  692. return 1;
  693. break;
  694. case IDNO:
  695. break;
  696. }
  697. }
  698. }
  699. ZeroMemory(szTempFile, sizeof(szTempFile));
  700. ZeroMemory(szFilter, sizeof(szFilter));
  701. LoadString(g_hInst, IDS_INSFILTERNAME, szFilter, ARRAYSIZE(szFilter));
  702. pszFilter = szFilter + lstrlen(szFilter) + 1;
  703. lstrcpy(pszFilter, TEXT("*.ins"));
  704. if (lParam == 0)
  705. {
  706. if (!BrowseForFileEx(hWnd, szFilter, szTempFile, ARRAYSIZE(szTempFile), TEXT("*.ins")))
  707. break;
  708. }
  709. else
  710. StrCpy(szTempFile, szFileToOpen);
  711. if (PathFileExists(szTempFile))
  712. {
  713. LPTSTR pExtn;
  714. TCHAR szLang[10];
  715. DWORD dwInsPlatformId;
  716. pExtn = PathFindExtension(szTempFile);
  717. if (pExtn == NULL || ((StrCmpI(pExtn, TEXT(".ins")) != 0) && (StrCmpI(pExtn, TEXT(".INS")) != 0))) //looks weird, but hack is needed for turkish locale
  718. {
  719. MessageBox(hWnd, Res2Str(IDS_INVALIDEXTN), Res2Str(IDS_TITLE), MB_OK);
  720. break;
  721. }
  722. // check if it is a Win32/W2K INS file
  723. if (!IsWin32INSFile(szTempFile))
  724. break;
  725. // check if the associated cab files are available.
  726. if (CabFilesExist(hWnd, szTempFile))
  727. {
  728. // check whether the INS language matches the language selected in the profile manager.
  729. GetPrivateProfileString(TEXT("Branding"), TEXT("Language Locale"), TEXT(""),
  730. szLang, ARRAYSIZE(szLang), szTempFile);
  731. if (StrCmpI(szLang, g_szLanguage) != 0)
  732. {
  733. TCHAR szMsg[MAX_PATH];
  734. wsprintf(szMsg, Res2Str(IDS_LANGDIFFERS), szTempFile);
  735. if (MessageBox(hWnd, szMsg, Res2Str(IDS_TITLE),
  736. MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDNO)
  737. break;
  738. }
  739. // check if the selected platform Optional cab is available for the selected language.
  740. dwInsPlatformId = GetPrivateProfileInt(TEXT("Branding"), TEXT("Platform"),
  741. IDM_PLATFORM_WIN32, szTempFile);
  742. if (!PlatformExists(hWnd, g_szLanguage, dwInsPlatformId, TRUE))
  743. break;
  744. ZeroMemory(g_szCabsURLPath, sizeof(g_szCabsURLPath));
  745. ZeroMemory(g_szConfigURLPath, sizeof(g_szConfigURLPath));
  746. ZeroMemory(g_szDesktopURLPath, sizeof(g_szDesktopURLPath));
  747. ZeroMemory(g_szConfigCabName, sizeof(g_szConfigCabName));
  748. ZeroMemory(g_szDesktopCabName, sizeof(g_szDesktopCabName));
  749. ZeroMemory(g_szNewVersionStr, sizeof(g_szNewVersionStr));
  750. EnableWindow(TreeView.GetHandle(), TRUE);
  751. SetInfoWindowText(hInfoWnd, Res2Str(IDS_OPENFILEMSG));
  752. DeleteCabWorkDirs();
  753. if (*g_szInsFile)
  754. {
  755. DeleteFile(g_szInsFile);
  756. ZeroMemory(g_szInsFile, sizeof(g_szInsFile));
  757. }
  758. SaveCurrentSelItem(TreeView.GetHandle(), ITEM_DESTROY);
  759. TreeView.SetSel(NULL);
  760. ResetAdmFiles(TreeView.GetHandle(), g_szCabWorkDir, FALSE);
  761. lstrcpy(g_szFileName, szTempFile);
  762. SetTitleBar(hWnd, g_szFileName);
  763. switch(dwInsPlatformId)
  764. {
  765. case PLATFORM_W2K:
  766. SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_PLATFORM_W2K, 0), 0L);
  767. break;
  768. case PLATFORM_WIN32:
  769. default:
  770. SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_PLATFORM_WIN32, 0), 0L);
  771. break;
  772. }
  773. NewTempFile();
  774. CopyFile(g_szFileName, g_szInsFile, FALSE);
  775. SetFileAttributes(g_szInsFile, FILE_ATTRIBUTE_NORMAL);
  776. ExtractCabFile();
  777. // Collapse all policy treeview items that has been expanded
  778. TreeView.CollapseChildNodes(g_hPolicyRootItem);
  779. TreeView.SetSel(g_pInsDialog[0].hItem);
  780. SetFocus(TreeView.GetHandle());
  781. ResetAdmFiles(TreeView.GetHandle(), g_szCabWorkDir, TRUE);
  782. SetInfoWindowText(hInfoWnd, Res2Str(IDS_READYMSG));
  783. lstrcpy(szTemp, szTempFile);
  784. PathRemoveFileSpec(szTemp);
  785. lstrcpy(g_szCurrInsPath, szTemp);
  786. UpdateRecentFileList(szTempFile, TRUE, szRecentFileList);
  787. }
  788. }
  789. else
  790. {
  791. TCHAR szErrMsg[MAX_PATH + 20];
  792. TCHAR szStr[MAX_PATH];
  793. LoadString(g_hInst, IDS_FILENOTFOUND, szStr, ARRAYSIZE(szStr));
  794. wsprintf(szErrMsg, szStr, szTempFile);
  795. MessageBox(hWnd, szErrMsg, Res2Str(IDS_TITLE), MB_OK | MB_ICONEXCLAMATION);
  796. UpdateRecentFileList(szTempFile, FALSE, szRecentFileList);
  797. }
  798. UpdateRecentFileListMenu(hWnd, szRecentFileList);
  799. ClearDirtyFlag();
  800. SetInfoWindowText(hInfoWnd);
  801. break;
  802. case IDM_ADMIMPORT:
  803. wsprintf(szTemp, TEXT("%sPolicies\\%s"), g_szRoot, g_szLanguage);
  804. ImportADMFile(hWnd, TreeView.GetHandle(), szTemp, g_szCabWorkDir, ROLE_CORP, g_szInsFile);
  805. break;
  806. case IDM_ADMDELETE:
  807. LoadString(g_hInst, IDS_ADMDELWARN, szMsg, ARRAYSIZE(szMsg));
  808. if(MessageBox(hWnd, szMsg, Res2Str(IDS_TITLE), MB_ICONQUESTION|MB_YESNO) == IDYES)
  809. {
  810. hItem = TreeView.GetSel();
  811. DeleteADMItem(TreeView.GetHandle(), hItem, g_szCabWorkDir, g_szInsFile, TRUE, TRUE);
  812. }
  813. break;
  814. case IDM_CHKDUPKEYS:
  815. hItem = TreeView.GetSel();
  816. CheckForDupKeys(g_hMain, TreeView.GetHandle(), hItem, TRUE);
  817. break;
  818. case IDM_PLATFORM_WIN32:
  819. case IDM_PLATFORM_W2K:
  820. InitializePlatform(hWnd, hInfoWnd, LOWORD(wParam));
  821. break;
  822. case IDM_HELP:
  823. SendMessage(hWnd, WM_HELP, 0, 0L);
  824. break;
  825. }
  826. if (LOWORD(wParam) >= IDM_RECENTFILELIST && LOWORD(wParam) < IDM_RECENTFILELIST + 5)
  827. {
  828. if (!(LOWORD(wParam) == IDM_RECENTFILELIST && StrCmpI(g_szFileName, szRecentFileList[0]) == 0))
  829. {
  830. StrCpy(szFileToOpen, szRecentFileList[LOWORD(wParam) - IDM_RECENTFILELIST]);
  831. SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_FILEOPEN, 0), 1L);
  832. }
  833. }
  834. break;
  835. case WM_MENUSELECT:
  836. if(LOWORD(wParam) == 0) // FILE menu
  837. {
  838. hMenu = GetSubMenu((HMENU) lParam, 0);
  839. if(lstrlen(g_szInsFile) == 0)
  840. {
  841. EnableMenuItem(hMenu, IDM_FILESAVE, MF_BYCOMMAND | MF_GRAYED);
  842. EnableMenuItem(hMenu, IDM_FILESAVEAS, MF_BYCOMMAND | MF_GRAYED);
  843. }
  844. else
  845. {
  846. EnableMenuItem(hMenu, IDM_FILESAVE, MF_BYCOMMAND | MF_ENABLED);
  847. EnableMenuItem(hMenu, IDM_FILESAVEAS, MF_BYCOMMAND | MF_ENABLED);
  848. }
  849. }
  850. else if(LOWORD(wParam) == 1) // POLICY menu
  851. {
  852. hItem = TreeView.GetSel();
  853. hMenu = GetSubMenu((HMENU) lParam, 1);
  854. if(!IsPolicyTree(hItem) || hItem == g_hPolicyRootItem ||
  855. TreeView_GetParent(TreeView.GetHandle(), hItem) != g_hPolicyRootItem ||
  856. !CanDeleteADM(TreeView.GetHandle(), hItem))
  857. {
  858. EnableMenuItem(hMenu, IDM_ADMDELETE, MF_BYCOMMAND | MF_GRAYED);
  859. }
  860. else
  861. EnableMenuItem(hMenu, IDM_ADMDELETE, MF_BYCOMMAND | MF_ENABLED);
  862. if(!IsPolicyTree(hItem) || hItem == g_hPolicyRootItem ||
  863. TreeView_GetParent(TreeView.GetHandle(), hItem) != g_hPolicyRootItem)
  864. {
  865. EnableMenuItem(hMenu, IDM_CHKDUPKEYS, MF_BYCOMMAND | MF_GRAYED);
  866. }
  867. else
  868. EnableMenuItem(hMenu, IDM_CHKDUPKEYS, MF_BYCOMMAND | MF_ENABLED);
  869. if(lstrlen(g_szLanguage))
  870. EnableMenuItem(hMenu, IDM_ADMIMPORT, MF_BYCOMMAND | MF_ENABLED);
  871. else
  872. EnableMenuItem(hMenu, IDM_ADMIMPORT, MF_BYCOMMAND | MF_GRAYED);
  873. }
  874. break;
  875. case WM_HELP:
  876. if (GetForegroundWindow() != g_hMain)
  877. break;
  878. hItem = TreeView.GetSel();
  879. if (hItem != NULL)
  880. {
  881. if (TreeView_GetParent(TreeView.GetHandle(), hItem) != NULL && !IsPolicyTree(hItem))
  882. {
  883. TreeView.GetItemText(hItem, szItem, countof(szItem));
  884. for(i = 0; i < g_nDialogs; i++)
  885. {
  886. if(StrCmp(szItem, g_pInsDialog[i].szName) == 0)
  887. IeakPageHelp(hWnd, g_pInsDialog[i].DlgId);
  888. }
  889. }
  890. else if (hItem == g_hInsRootItem)
  891. IeakPageHelp(hWnd, MAKEINTRESOURCE(IDD_CORPWELCOME));
  892. else if (IsPolicyTree(hItem))
  893. IeakPageHelp(hWnd, MAKEINTRESOURCE(IDD_ADM));
  894. }
  895. break;
  896. case WM_MOUSEMOVE:
  897. fCanResize = FALSE;
  898. if (GetCapture() == hWnd)
  899. {
  900. DrawTrackLine(hWnd, nPrevXPos);
  901. DrawTrackLine(hWnd, LOWORD(lParam));
  902. nPrevXPos = LOWORD(lParam);
  903. break;
  904. }
  905. GetWindowRect(hWndSizeBar, &rect1);
  906. {
  907. int nXPos = LOWORD(lParam);
  908. int nYPos = HIWORD(lParam);
  909. POINT ptLeftTop;
  910. POINT ptRightBottom;
  911. ptLeftTop.x = rect1.left;
  912. ptLeftTop.y = rect1.top;
  913. ScreenToClient(hWnd, &ptLeftTop);
  914. ptRightBottom.x = rect1.right;
  915. ptRightBottom.y = rect1.bottom;
  916. ScreenToClient(hWnd, &ptRightBottom);
  917. if (nXPos >= ptLeftTop.x - 1 && nXPos <= ptRightBottom.x && nYPos >= ptLeftTop.y && nYPos <= ptRightBottom.y)
  918. {
  919. fCanResize = TRUE;
  920. SetCursor(hCurVTResize);
  921. }
  922. }
  923. break;
  924. case WM_LBUTTONDOWN:
  925. if (fCanResize)
  926. {
  927. POINT pt;
  928. RECT rectTrack;
  929. HDC hDC = NULL;
  930. GetWindowRect(TreeView.GetHandle(), &rect1);
  931. rect2.left = rect1.left + 10;
  932. rect2.top = rect1.top;
  933. rect2.right = rect2.left + TREEVIEW_WIDTH - 10 + 1;
  934. rect2.bottom = rect2.top + (rect1.bottom - rect1.top);
  935. ClipCursor(&rect2);
  936. pt.x = 0;
  937. pt.y = HIWORD(lParam);
  938. ClientToScreen(hWnd, &pt);
  939. GetWindowRect(hWndSizeBar, &rect1);
  940. SetCursor(hCurVTResize);
  941. SetCursorPos(rect1.left, pt.y);
  942. SetCapture(hWnd);
  943. pt.x = rect1.left;
  944. pt.y = 0;
  945. ScreenToClient(hWnd, &pt);
  946. DrawTrackLine(hWnd, pt.x);
  947. nPrevXPos = pt.x;
  948. }
  949. break;
  950. case WM_LBUTTONUP:
  951. if (GetCapture() == hWnd)
  952. {
  953. RECT rectWnd;
  954. ReleaseCapture();
  955. ClipCursor(NULL);
  956. DrawTrackLine(hWnd, nPrevXPos);
  957. nTreeViewWidth = nPrevXPos - MARGIN;
  958. GetWindowRect(TreeView.GetHandle(), &rect1);
  959. GetWindowRect(hWnd, &rectWnd);
  960. SetWindowPos(hWnd, HWND_TOP, 0, 0, (rectWnd.right - rectWnd.left) + (nTreeViewWidth - (rect1.right - rect1.left)),
  961. rectWnd.bottom - rectWnd.top, SWP_NOMOVE | SWP_NOZORDER);
  962. }
  963. break;
  964. case WM_CLOSE:
  965. if(*g_szInsFile != TEXT('\0'))
  966. {
  967. SaveCurrentSelItem(TreeView.GetHandle(), ITEM_CHECKDIRTY);
  968. SetInfoWindowText(hInfoWnd);
  969. if (IsDirty())
  970. {
  971. int nError;
  972. wsprintf(szMsg, Res2Str(IDS_SAVE), (*g_szFileName != TEXT('\0')) ? g_szFileName : Res2Str(IDS_UNTITLED));
  973. switch(MessageBox(hWnd, szMsg, Res2Str(IDS_TITLE), MB_YESNOCANCEL))
  974. {
  975. case IDYES:
  976. nError = (int) SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_FILESAVE, 0), 0);
  977. if (nError == PAGE_ERROR || nError == SAVE_ERROR || nError == SAVE_CANCEL)
  978. return 1;
  979. break;
  980. case IDCANCEL:
  981. return 1;
  982. case IDNO:
  983. break;
  984. }
  985. }
  986. ZeroMemory(g_szFileName, sizeof(g_szFileName));
  987. DeleteFile(g_szInsFile);
  988. ZeroMemory(g_szInsFile, sizeof(g_szInsFile));
  989. }
  990. if (RegCreateKeyEx(HKEY_CURRENT_USER, RK_IEAK_SERVER TEXT("\\ProfMgr"), 0, NULL, REG_OPTION_NON_VOLATILE,
  991. KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  992. {
  993. RegSetValueEx(hKey, TEXT("LastOpenedPath"), 0, dwType, (const BYTE*) g_szCurrInsPath, lstrlen(g_szCurrInsPath) + 1);
  994. RegSetValueEx(hKey, TEXT("TreeviewWidth"), 0, REG_DWORD, (const BYTE*) &nTreeViewWidth, sizeof(DWORD));
  995. RegCloseKey(hKey);
  996. }
  997. SaveCurrentSelItem(TreeView.GetHandle(), ITEM_DESTROY);
  998. DeleteADMItems(TreeView.GetHandle(), g_szCabWorkDir, g_szInsFile, TRUE);
  999. DestroyWindow(g_hWndAdmInstr);
  1000. DestroyADMWindow(TreeView.GetHandle());
  1001. DeleteCabWorkDirs();
  1002. WriteRecentFileList(szRecentFileList);
  1003. ReleaseCapture();
  1004. ClipCursor(NULL);
  1005. if (g_hWndHelp != NULL)
  1006. SendMessage(g_hWndHelp, WM_CLOSE, 0, 0L);
  1007. return DefWindowProc(hWnd, msg, wParam, lParam);
  1008. case WM_DESTROY:
  1009. DeleteFile(g_szInsFile);
  1010. PostQuitMessage(0);
  1011. break;
  1012. default:
  1013. return DefWindowProc(hWnd, msg, wParam, lParam);
  1014. }
  1015. return 1;
  1016. }
  1017. void DrawTrackLine(HWND hWnd, int nXPos)
  1018. {
  1019. RECT rectTV;
  1020. RECT rectTrack;
  1021. HDC hDC = NULL;
  1022. GetWindowRect(TreeView.GetHandle(), &rectTV);
  1023. rectTrack.left = nXPos;
  1024. rectTrack.top = MARGIN;
  1025. rectTrack.right= nXPos + 4;
  1026. rectTrack.bottom = rectTrack.top + (rectTV.bottom - rectTV.top);
  1027. hDC = GetDC(hWnd);
  1028. InvertRect(hDC, &rectTrack);
  1029. ReleaseDC(hWnd, hDC);
  1030. }
  1031. BOOL CanOverwriteFiles(HWND hDlg)
  1032. {
  1033. TCHAR szExistingFiles[MAX_PATH*5];
  1034. TCHAR szTemp[MAX_PATH];
  1035. TCHAR szDir[MAX_PATH];
  1036. TCHAR szFile[MAX_PATH];
  1037. TCHAR szReadOnlyFiles[MAX_PATH*5];
  1038. *szExistingFiles = TEXT('\0');
  1039. *szReadOnlyFiles = TEXT('\0');
  1040. // check for file already exists in the destination directory.
  1041. GetDlgItemText(hDlg, IDE_INSFILE, szTemp, ARRAYSIZE(szTemp));
  1042. if (PathFileExists(szTemp))
  1043. {
  1044. StrCat(szExistingFiles, szTemp);
  1045. StrCat(szExistingFiles, TEXT("\r\n"));
  1046. if (IsFileReadOnly(szTemp))
  1047. StrCpy(szReadOnlyFiles, szExistingFiles);
  1048. }
  1049. StrCpy(szDir, szTemp);
  1050. PathRemoveFileSpec(szDir);
  1051. if (IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB1NAME)))
  1052. {
  1053. GetDlgItemText(hDlg, IDE_CAB1NAME, szTemp, ARRAYSIZE(szTemp));
  1054. PathCombine(szFile, szDir, szTemp);
  1055. if (PathFileExists(szFile))
  1056. {
  1057. StrCat(szExistingFiles, szFile);
  1058. StrCat(szExistingFiles, TEXT("\r\n"));
  1059. if (IsFileReadOnly(szFile))
  1060. {
  1061. StrCat(szReadOnlyFiles, szFile);
  1062. StrCat(szReadOnlyFiles, TEXT("\r\n"));
  1063. }
  1064. }
  1065. }
  1066. if (IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB2NAME)))
  1067. {
  1068. GetDlgItemText(hDlg, IDE_CAB2NAME, szTemp, ARRAYSIZE(szTemp));
  1069. PathCombine(szFile, szDir, szTemp);
  1070. if (PathFileExists(szFile))
  1071. {
  1072. StrCat(szExistingFiles, szFile);
  1073. StrCat(szExistingFiles, TEXT("\r\n"));
  1074. if (IsFileReadOnly(szFile))
  1075. {
  1076. StrCat(szReadOnlyFiles, szFile);
  1077. StrCat(szReadOnlyFiles, TEXT("\r\n"));
  1078. }
  1079. }
  1080. }
  1081. if (*szReadOnlyFiles != TEXT('\0'))
  1082. {
  1083. TCHAR szMsg[MAX_PATH*6];
  1084. wsprintf(szMsg, Res2Str(IDS_FILE_READONLY), szReadOnlyFiles);
  1085. MessageBox(hDlg, szMsg, Res2Str(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK);
  1086. return FALSE;
  1087. }
  1088. if (*szExistingFiles != TEXT('\0'))
  1089. {
  1090. TCHAR szMsg[MAX_PATH*6];
  1091. wsprintf(szMsg, Res2Str(IDS_FILE_ALREADY_EXISTS), szExistingFiles);
  1092. if (MessageBox(hDlg, szMsg, Res2Str(IDS_TITLE),
  1093. MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2) == IDNO)
  1094. return FALSE;
  1095. }
  1096. return TRUE;
  1097. }
  1098. INT_PTR CALLBACK SaveAsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1099. {
  1100. TCHAR szInsFile[MAX_PATH];
  1101. TCHAR szCabsURL[INTERNET_MAX_URL_LENGTH];
  1102. TCHAR szPrefix[MAX_PATH];
  1103. TCHAR szCabName[MAX_PATH];
  1104. HWND hCtrl;
  1105. TCHAR szFilter[MAX_PATH];
  1106. LPTSTR pszFilter = NULL;
  1107. TCHAR szTemp[MAX_PATH];
  1108. DWORD dwCabBuildStatus = 0;
  1109. switch(uMsg)
  1110. {
  1111. case WM_INITDIALOG:
  1112. EnableDBCSChars(hDlg, IDE_INSFILE); // enable DBCS chars
  1113. EnableDBCSChars(hDlg, IDE_CABSURL);
  1114. EnableDBCSChars(hDlg, IDE_CAB1NAME);
  1115. EnableDBCSChars(hDlg, IDE_CAB2NAME);
  1116. // since base INS filename will be used as prefix to the respective
  1117. // cab names and the largest cab suffix string is _channnels.cab (which has
  1118. // 13 chars in it), the prefix can be at the max only 246 chars long.
  1119. // So limit the text to be entered in the IDE_INSFILE to MAX_PATH - 20.
  1120. Edit_LimitText(GetDlgItem(hDlg, IDE_INSFILE), ARRAYSIZE(g_szFileName) - 20);
  1121. Edit_LimitText(GetDlgItem(hDlg, IDE_CABSURL), ARRAYSIZE(g_szCabsURLPath) - 1);
  1122. Edit_LimitText(GetDlgItem(hDlg, IDE_CAB1NAME), ARRAYSIZE(g_szConfigCabName) - 1);
  1123. Edit_LimitText(GetDlgItem(hDlg, IDE_CAB2NAME), ARRAYSIZE(g_szDesktopCabName) - 1);
  1124. dwCabBuildStatus = GetCabBuildStatus();
  1125. if (!HasFlag(dwCabBuildStatus, CAB_TYPE_CONFIG))
  1126. {
  1127. EnableWindow(GetDlgItem(hDlg, IDC_CAB1TEXT), FALSE);
  1128. EnableWindow(GetDlgItem(hDlg, IDE_CAB1NAME), FALSE);
  1129. }
  1130. if (!HasFlag(dwCabBuildStatus, CAB_TYPE_DESKTOP))
  1131. {
  1132. EnableWindow(GetDlgItem(hDlg, IDC_CAB2TEXT), FALSE);
  1133. EnableWindow(GetDlgItem(hDlg, IDE_CAB2NAME), FALSE);
  1134. }
  1135. if (!IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB1NAME)) &&
  1136. !IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB2NAME)))
  1137. {
  1138. EnableWindow(GetDlgItem(hDlg, IDC_CABSURLTEXT), FALSE);
  1139. EnableWindow(GetDlgItem(hDlg, IDE_CABSURL), FALSE);
  1140. }
  1141. *szPrefix = TEXT('\0');
  1142. //----------------- InsFile
  1143. if (PathFileExists(g_szFileName))
  1144. {
  1145. SetDlgItemText(hDlg, IDE_INSFILE, g_szFileName);
  1146. GetBaseFileName(g_szFileName, szPrefix, ARRAYSIZE(szPrefix));
  1147. if(StrCmpI(szPrefix, TEXT("install")) == 0)
  1148. StrCpy(szPrefix, TEXT("Default"));
  1149. }
  1150. //----------------- CabsURLPath
  1151. if (*g_szCabsURLPath)
  1152. SetDlgItemText(hDlg, IDE_CABSURL, g_szCabsURLPath);
  1153. //----------------- Config
  1154. if (HasFlag(dwCabBuildStatus, CAB_TYPE_CONFIG))
  1155. {
  1156. if (*g_szConfigCabName == TEXT('\0'))
  1157. GetDefaultCabName(CAB_TYPE_CONFIG, szPrefix, szCabName);
  1158. else
  1159. GetDefaultCabName(CAB_TYPE_CONFIG, g_szConfigCabName, szCabName);
  1160. SetDlgItemText(hDlg, IDE_CAB1NAME, szCabName);
  1161. }
  1162. //----------------- Desktop
  1163. if (HasFlag(dwCabBuildStatus, CAB_TYPE_DESKTOP))
  1164. {
  1165. if (*g_szDesktopCabName == TEXT('\0'))
  1166. GetDefaultCabName(CAB_TYPE_DESKTOP, szPrefix, szCabName);
  1167. else
  1168. GetDefaultCabName(CAB_TYPE_DESKTOP, g_szDesktopCabName, szCabName);
  1169. SetDlgItemText(hDlg, IDE_CAB2NAME, szCabName);
  1170. }
  1171. //----------------- Version
  1172. if (*g_szNewVersionStr == TEXT('\0'))
  1173. GenerateNewVersionStr(g_szFileName, g_szNewVersionStr);
  1174. SetDlgItemText(hDlg, IDC_CABVERSION, g_szNewVersionStr);
  1175. return TRUE;
  1176. case WM_COMMAND:
  1177. switch (wParam)
  1178. {
  1179. case IDOK:
  1180. GetDlgItemText(hDlg, IDE_INSFILE, szInsFile, ARRAYSIZE(szInsFile));
  1181. if(*szInsFile != TEXT('\0') && (StrCmpI(PathFindExtension(szInsFile), TEXT(".ins")) != 0) && (StrCmpI(PathFindExtension(szInsFile), TEXT(".INS")) != 0))
  1182. {
  1183. MessageBox(hDlg, Res2Str(IDS_INVALIDEXTN), Res2Str(IDS_TITLE), MB_OK);
  1184. SendMessage(hCtrl = GetDlgItem(hDlg, IDE_INSFILE), EM_SETSEL, 0, -1);
  1185. SetFocus(hCtrl);
  1186. }
  1187. else if (IsFileCreatable(szInsFile))
  1188. {
  1189. ZeroMemory(szCabsURL, sizeof(szCabsURL));
  1190. if (!IsWindowEnabled(GetDlgItem(hDlg, IDE_CABSURL)) ||
  1191. (GetDlgItemText(hDlg, IDE_CABSURL, szCabsURL, ARRAYSIZE(szCabsURL)) && PathIsURL(szCabsURL)))
  1192. {
  1193. int nLen = 0;
  1194. if (!IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB1NAME)) ||
  1195. ((nLen = GetDlgItemText(hDlg, IDE_CAB1NAME, szCabName, ARRAYSIZE(szCabName)))))
  1196. {
  1197. if (!IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB2NAME)) ||
  1198. ((nLen = GetDlgItemText(hDlg, IDE_CAB2NAME, szCabName, ARRAYSIZE(szCabName)))))
  1199. {
  1200. if(!CanOverwriteFiles(hDlg))
  1201. return TRUE;
  1202. StrCpy(g_szFileName, szInsFile);
  1203. StrCpy(g_szCabsURLPath, szCabsURL);
  1204. GetDlgItemText(hDlg, IDE_CAB1NAME, g_szConfigCabName, ARRAYSIZE(g_szConfigCabName));
  1205. GetDlgItemText(hDlg, IDE_CAB2NAME, g_szDesktopCabName, ARRAYSIZE(g_szDesktopCabName));
  1206. // clear out the version buffer so that it gets initialized properly in SetOrClearVersionInfo
  1207. ZeroMemory(g_szNewVersionStr, sizeof(g_szNewVersionStr));
  1208. EndDialog(hDlg, 0);
  1209. lstrcpy(szTemp, szInsFile);
  1210. PathRemoveFileSpec(szTemp);
  1211. lstrcpy(g_szCurrInsPath, szTemp);
  1212. break;
  1213. }
  1214. else
  1215. hCtrl = GetDlgItem(hDlg, IDE_CAB2NAME);
  1216. }
  1217. else
  1218. hCtrl = GetDlgItem(hDlg, IDE_CAB1NAME);
  1219. MessageBox(hDlg, Res2Str(IDS_MUSTSPECIFYNAME), Res2Str(IDS_TITLE), MB_OK);
  1220. SendMessage(hCtrl, EM_SETSEL, 0, -1);
  1221. SetFocus(hCtrl);
  1222. }
  1223. else
  1224. {
  1225. hCtrl = GetDlgItem(hDlg, IDE_CABSURL);
  1226. MessageBox(hDlg, Res2Str(IDS_MUSTSPECIFYURL), Res2Str(IDS_TITLE), MB_OK);
  1227. SendMessage(hCtrl, EM_SETSEL, 0, -1);
  1228. SetFocus(hCtrl);
  1229. }
  1230. }
  1231. else
  1232. {
  1233. MessageBox(hDlg, Res2Str(IDS_CANTCREATEFILE), Res2Str(IDS_TITLE), MB_OK);
  1234. SendMessage(hCtrl = GetDlgItem(hDlg, IDE_INSFILE), EM_SETSEL, 0, -1);
  1235. SetFocus(hCtrl);
  1236. }
  1237. return TRUE;
  1238. case IDCANCEL:
  1239. EndDialog(hDlg, -1);
  1240. break;
  1241. case IDC_INSBROWSE:
  1242. *szInsFile = TEXT('\0');
  1243. GetDlgItemText(hDlg, IDE_INSFILE, szInsFile, ARRAYSIZE(szInsFile));
  1244. ZeroMemory(szFilter, sizeof(szFilter));
  1245. LoadString(g_hInst, IDS_INSFILTERNAME, szFilter, ARRAYSIZE(szFilter));
  1246. pszFilter = szFilter + lstrlen(szFilter) + 1;
  1247. lstrcpy(pszFilter, TEXT("*.ins"));
  1248. if (BrowseForSave(hDlg, szFilter, szInsFile, ARRAYSIZE(szInsFile), TEXT("*.ins")))
  1249. SetDlgItemText(hDlg, IDE_INSFILE, szInsFile);
  1250. return TRUE;
  1251. }
  1252. if (LOWORD(wParam) == IDE_INSFILE && HIWORD(wParam) == EN_CHANGE)
  1253. {
  1254. GetDlgItemText(hDlg, IDE_INSFILE, szInsFile, ARRAYSIZE(szInsFile));
  1255. if(*szInsFile != TEXT('\0') && StrCmpI(PathFindExtension(szInsFile), TEXT(".ins")) == 0)
  1256. {
  1257. GetBaseFileName(szInsFile, szPrefix, ARRAYSIZE(szPrefix));
  1258. if(StrCmpI(szPrefix, TEXT("install")) == 0)
  1259. StrCpy(szPrefix, TEXT("Default"));
  1260. if (IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB1NAME)))
  1261. {
  1262. TCHAR szTempCabName[MAX_PATH];
  1263. GetDlgItemText(hDlg, IDE_CAB1NAME, szTempCabName, countof(szTempCabName));
  1264. if (*szTempCabName == TEXT('\0') ||
  1265. (StrStrI(szTempCabName, TEXT("_config.cab")) != NULL))
  1266. {
  1267. GetDefaultCabName(CAB_TYPE_CONFIG, szPrefix, szCabName);
  1268. SetDlgItemText(hDlg, IDE_CAB1NAME, szCabName);
  1269. }
  1270. }
  1271. if (IsWindowEnabled(GetDlgItem(hDlg, IDE_CAB2NAME)))
  1272. {
  1273. TCHAR szTempCabName[MAX_PATH];
  1274. GetDlgItemText(hDlg, IDE_CAB2NAME, szTempCabName, countof(szTempCabName));
  1275. if (*szTempCabName == TEXT('\0') ||
  1276. (StrStrI(szTempCabName, TEXT("_desktop.cab")) != NULL))
  1277. {
  1278. GetDefaultCabName(CAB_TYPE_DESKTOP, szPrefix, szCabName);
  1279. SetDlgItemText(hDlg, IDE_CAB2NAME, szCabName);
  1280. }
  1281. }
  1282. }
  1283. }
  1284. break;
  1285. }
  1286. return FALSE;
  1287. }
  1288. int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
  1289. {
  1290. HANDLE hMutex;
  1291. HINSTANCE hInsDll;
  1292. WNDCLASSEX wc;
  1293. MSG msg;
  1294. TCHAR* pLastSlash = NULL;
  1295. DWORD dwSize, dwIEVer;
  1296. int iType;
  1297. dwSize = sizeof(DWORD);
  1298. if (SHGetValue(HKEY_LOCAL_MACHINE, TEXT("Software\\Microsoft\\IEAK"), TEXT("Mode"), NULL, &iType, &dwSize) == ERROR_SUCCESS)
  1299. {
  1300. if ((iType == REDIST) || (iType == BRANDED))
  1301. {
  1302. ErrorMessageBox(NULL, IDS_REQUIRE_CORPMODE);
  1303. return FALSE;
  1304. }
  1305. }
  1306. // allow only one instance running at a time
  1307. hMutex = CreateMutex(NULL, TRUE, TEXT("IEAK6ProfMgr.Mutex"));
  1308. if ((hMutex != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS))
  1309. {
  1310. CloseHandle(hMutex);
  1311. ErrorMessageBox(NULL, IDS_ERROR_MULTPROFMGR);
  1312. return FALSE;
  1313. }
  1314. g_hInst = hInst;
  1315. s_hInstIeakUI = LoadLibrary(TEXT("ieakui.dll"));
  1316. if (s_hInstIeakUI == NULL)
  1317. return (int)FALSE;
  1318. ZeroMemory(g_szFileName, sizeof(g_szFileName));
  1319. ZeroMemory(g_szInsFile, sizeof(g_szInsFile));
  1320. ZeroMemory(g_szCabWorkDir, sizeof(g_szCabWorkDir));
  1321. wc.cbSize = sizeof(WNDCLASSEX);
  1322. wc.style = 0;
  1323. wc.lpfnWndProc = WndProc;
  1324. wc.cbClsExtra = 0;
  1325. wc.cbWndExtra = 0;
  1326. wc.hInstance = hInst;
  1327. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1328. wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
  1329. wc.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
  1330. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
  1331. wc.lpszMenuName = NULL;
  1332. wc.lpszClassName = TEXT("InsEdit4Class");
  1333. if(!RegisterClassEx(&wc))
  1334. {
  1335. FreeLibrary(s_hInstIeakUI);
  1336. return 0;
  1337. }
  1338. // if ie5.5 is not installed, bail out
  1339. dwIEVer = GetIEVersion();
  1340. if (HIWORD(dwIEVer) < 6)
  1341. {
  1342. TCHAR szMsgBoxTitle[128];
  1343. TCHAR szMsgBoxText[MAX_PATH];
  1344. LoadString(g_hInst, IDS_NOIE, szMsgBoxText, ARRAYSIZE(szMsgBoxText));
  1345. LoadString(g_hInst, IDS_TITLE, szMsgBoxTitle, ARRAYSIZE(szMsgBoxTitle));
  1346. MessageBox(NULL, szMsgBoxText, szMsgBoxTitle, MB_OK);
  1347. FreeLibrary(s_hInstIeakUI);
  1348. return FALSE;
  1349. }
  1350. dwSize = sizeof(g_szRoot);
  1351. ZeroMemory(g_szRoot, sizeof(g_szRoot));
  1352. GetModuleFileName(GetModuleHandle(NULL), g_szRoot, MAX_PATH);
  1353. if(*g_szRoot == 0)
  1354. SHGetValue(HKEY_LOCAL_MACHINE, CURRENTVERSIONKEY TEXT("\\App Paths\\IEAK6WIZ.EXE"), NULL, NULL, (LPVOID) g_szRoot, &dwSize);
  1355. if(*g_szRoot != 0)
  1356. {
  1357. pLastSlash = StrRChr(g_szRoot, NULL, TEXT('\\'));
  1358. if (pLastSlash)
  1359. *(++pLastSlash) = 0;
  1360. CharUpper(g_szRoot);
  1361. }
  1362. else
  1363. {
  1364. FreeLibrary(s_hInstIeakUI);
  1365. return 0;
  1366. }
  1367. hInsDll = LoadLibrary(TEXT("insedit.dll"));
  1368. if(!hInsDll)
  1369. {
  1370. MessageBox(NULL, Res2Str(IDS_ERRDLL), Res2Str(IDS_TITLE), MB_OK);
  1371. FreeLibrary(s_hInstIeakUI);
  1372. return 0;
  1373. }
  1374. CreateInsDialog = (CREATEINSDIALOG) GetProcAddress(hInsDll, "CreateInsDialog");
  1375. GetInsDlgStruct = (GETINSDLGSTRUCT) GetProcAddress(hInsDll, "GetInsDlgStruct");
  1376. DestroyInsDialog = (DESTROYINSDIALOG) GetProcAddress(hInsDll, "DestroyInsDialog");
  1377. SetDefaultInf = (SETDEFAULTINF) GetProcAddress(hInsDll, "SetDefaultInf");
  1378. ReInitializeInsDialogProcs = (REINITIALIZEINSDIALOGPROCS) GetProcAddress(hInsDll, "ReInitializeInsDialogProcs");
  1379. SetPlatformInfo = (SETPLATFORMINFO) GetProcAddress(hInsDll, "SetPlatformInfo");
  1380. InsDirty = (INSDIRTY) GetProcAddress(hInsDll, "InsDirty");
  1381. ClearInsDirtyFlag = (CLEARINSDIRTYFLAG) GetProcAddress(hInsDll, "ClearInsDirtyFlag");
  1382. SaveInsDialog = (SAVEINSDIALOG) GetProcAddress(hInsDll, "SaveInsDialog");
  1383. CheckForExChar = (CHECKFOREXCHAR) GetProcAddress(hInsDll, "CheckForExChar");
  1384. if(!CreateInsDialog || !GetInsDlgStruct || !DestroyInsDialog || !SetDefaultInf ||
  1385. !ReInitializeInsDialogProcs || !SetPlatformInfo || !InsDirty || !ClearInsDirtyFlag ||
  1386. !SaveInsDialog || !CheckForExChar)
  1387. {
  1388. FreeLibrary(s_hInstIeakUI);
  1389. return 0;
  1390. }
  1391. if (CoInitialize(NULL) != S_OK)
  1392. {
  1393. MessageBox(NULL, Res2Str(IDS_COMINITFAILURE), Res2Str(IDS_TITLE), MB_OK);
  1394. return 0;
  1395. }
  1396. *g_szCmdLine = TEXT('\0');
  1397. if (*lpCmdLine != TEXT('\0'))
  1398. {
  1399. PathUnquoteSpaces(lpCmdLine);
  1400. if (lstrlen(lpCmdLine) < MAX_PATH)
  1401. lstrcpy(g_szCmdLine, lpCmdLine);
  1402. }
  1403. g_pInsDialog = GetInsDlgStruct(&g_nDialogs);
  1404. g_hMain = CreateWindowEx(0, TEXT("InsEdit4Class"), Res2Str(IDS_TITLE), WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX),
  1405. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
  1406. LoadMenu(hInst, MAKEINTRESOURCE(IDR_MAINMENU)), hInst, NULL);
  1407. if(g_hMain != NULL)
  1408. {
  1409. while(GetMessage(&msg, NULL, 0, 0))
  1410. {
  1411. if(msg.message == WM_QUIT)
  1412. break;
  1413. if(IsDialogMessage(g_hMain, &msg))
  1414. continue;
  1415. TranslateMessage(&msg);
  1416. DispatchMessage(&msg);
  1417. }
  1418. }
  1419. if(hInsDll != NULL)
  1420. FreeLibrary(hInsDll);
  1421. FreeLibrary(s_hInstIeakUI);
  1422. if (hMutex != NULL)
  1423. CloseHandle(hMutex);
  1424. CoUninitialize();
  1425. return 1;
  1426. }
  1427. BOOL DirectoryName(LPCTSTR lpDirectory, LPTSTR szDirectoryPath)
  1428. {
  1429. TCHAR* ptr = StrRChr((LPTSTR)lpDirectory, NULL, TEXT('\\'));
  1430. ZeroMemory(szDirectoryPath, sizeof(szDirectoryPath));
  1431. if(ptr == NULL)
  1432. return FALSE;
  1433. lstrcpyn(szDirectoryPath, lpDirectory, (int) (ptr - lpDirectory + 1));
  1434. return TRUE;
  1435. }
  1436. void ExtractCabFile()
  1437. {
  1438. TCHAR szBaseInsFileName[_MAX_FNAME];
  1439. TCHAR szCabFullFileName[MAX_PATH];
  1440. CHAR szCabFullNameA[MAX_PATH];
  1441. CHAR szCabDirA[MAX_PATH];
  1442. GetBaseFileName(g_szFileName, szBaseInsFileName, ARRAYSIZE(szBaseInsFileName));
  1443. CreateCabWorkDirs(szBaseInsFileName);
  1444. // read in the URL path for the cabs
  1445. GetPrivateProfileString(BRANDING, CABSURLPATH, TEXT(""), g_szCabsURLPath, ARRAYSIZE(g_szCabsURLPath), g_szFileName);
  1446. if (GetCabName(g_szFileName, CAB_TYPE_CONFIG, szCabFullFileName) != NULL)
  1447. {
  1448. #ifdef UNICODE
  1449. WideCharToMultiByte(CP_ACP, 0, szCabFullFileName, -1, szCabFullNameA, sizeof(szCabFullNameA), NULL, NULL);
  1450. WideCharToMultiByte(CP_ACP, 0, g_szCabWorkDir, -1, szCabDirA, sizeof(szCabDirA), NULL, NULL);
  1451. #else
  1452. StrCpyA(szCabFullNameA, szCabFullFileName);
  1453. StrCpyA(szCabDirA, g_szCabWorkDir);
  1454. #endif
  1455. ExtractFiles(szCabFullNameA, szCabDirA, 0, NULL, NULL, NULL);
  1456. }
  1457. if (GetCabName(g_szFileName, CAB_TYPE_DESKTOP, szCabFullFileName) != NULL)
  1458. {
  1459. #ifdef UNICODE
  1460. WideCharToMultiByte(CP_ACP, 0, szCabFullFileName, -1, szCabFullNameA, sizeof(szCabFullNameA), NULL, NULL);
  1461. WideCharToMultiByte(CP_ACP, 0, g_szDesktopDir, -1, szCabDirA, sizeof(szCabDirA), NULL, NULL);
  1462. #else
  1463. StrCpyA(szCabFullNameA, szCabFullFileName);
  1464. StrCpyA(szCabDirA, g_szDesktopDir);
  1465. #endif
  1466. ExtractFiles(szCabFullNameA, szCabDirA, 0, NULL, NULL, NULL);
  1467. }
  1468. if (GetCabName(g_szFileName, CAB_TYPE_CHANNELS, szCabFullFileName) != NULL)
  1469. {
  1470. #ifdef UNICODE
  1471. WideCharToMultiByte(CP_ACP, 0, szCabFullFileName, -1, szCabFullNameA, sizeof(szCabFullNameA), NULL, NULL);
  1472. WideCharToMultiByte(CP_ACP, 0, g_szDesktopDir, -1, szCabDirA, sizeof(szCabDirA), NULL, NULL);
  1473. #else
  1474. StrCpyA(szCabFullNameA, szCabFullFileName);
  1475. StrCpyA(szCabDirA, g_szDesktopDir);
  1476. #endif
  1477. ExtractFiles(szCabFullNameA, szCabDirA, 0, NULL, NULL, NULL);
  1478. }
  1479. }
  1480. void GetCabNameFromINS(LPCTSTR pcszInsFile, DWORD dwCabType, LPTSTR pszCabFullFileName, LPTSTR pszCabInfoLine /* = NULL*/)
  1481. {
  1482. LPCTSTR pcszSection = NULL, pcszKey = NULL;
  1483. TCHAR szCabFilePath[MAX_PATH];
  1484. TCHAR szCabName[MAX_PATH];
  1485. TCHAR szCabInfoLine[INTERNET_MAX_URL_LENGTH + 128];
  1486. if (pcszInsFile == NULL || *pcszInsFile == TEXT('\0') || pszCabFullFileName == NULL)
  1487. return;
  1488. *pszCabFullFileName = TEXT('\0');
  1489. if (pszCabInfoLine != NULL)
  1490. *pszCabInfoLine = TEXT('\0');
  1491. switch (dwCabType)
  1492. {
  1493. case CAB_TYPE_CONFIG:
  1494. pcszSection = CUSTBRNDSECT;
  1495. pcszKey = CUSTBRNDNAME;
  1496. break;
  1497. case CAB_TYPE_DESKTOP:
  1498. pcszSection = CUSTDESKSECT;
  1499. pcszKey = CUSTDESKNAME;
  1500. break;
  1501. case CAB_TYPE_CHANNELS:
  1502. pcszSection = CUSTCHANSECT;
  1503. pcszKey = CUSTCHANNAME;
  1504. break;
  1505. }
  1506. if (pcszSection == NULL || pcszKey == NULL)
  1507. return;
  1508. DirectoryName(pcszInsFile, szCabFilePath);
  1509. if (GetPrivateProfileString(pcszSection, pcszKey, TEXT(""), szCabInfoLine, ARRAYSIZE(szCabInfoLine), pcszInsFile) == 0)
  1510. GetPrivateProfileString(CUSTOMVERSECT, pcszKey, TEXT(""), szCabInfoLine, ARRAYSIZE(szCabInfoLine), pcszInsFile);
  1511. if (*szCabInfoLine)
  1512. {
  1513. LPTSTR pszT;
  1514. if ((pszT = StrChr(szCabInfoLine, TEXT(','))) != NULL)
  1515. *pszT = TEXT('\0');
  1516. if ((pszT = PathFindFileName(szCabInfoLine)) > szCabInfoLine)
  1517. {
  1518. // cab URL path is specified
  1519. *(pszT - 1) = TEXT('\0'); // nul the '/' char
  1520. }
  1521. StrCpy(szCabName, pszT);
  1522. PathCombine(pszCabFullFileName, szCabFilePath, szCabName);
  1523. if (pszCabInfoLine)
  1524. StrCpy(pszCabInfoLine, szCabInfoLine);
  1525. }
  1526. }
  1527. LPTSTR GetCabName(LPCTSTR pcszInsFile, DWORD dwCabType, TCHAR szCabFullFileName[])
  1528. // NOTE: It's assumed that the length of szCabName is atleast MAX_PATH
  1529. {
  1530. TCHAR szCabName[MAX_PATH];
  1531. TCHAR szCabInfoLine[INTERNET_MAX_URL_LENGTH + 128];
  1532. TCHAR szCabFilePath[MAX_PATH];
  1533. *szCabInfoLine = TEXT('\0');
  1534. // first check if a cab file is already specified in pcszInsFile
  1535. GetCabNameFromINS(pcszInsFile, dwCabType, szCabFullFileName, szCabInfoLine);
  1536. if (*szCabFullFileName != TEXT('\0') && PathFileExists(szCabFullFileName))
  1537. {
  1538. switch (dwCabType)
  1539. {
  1540. case CAB_TYPE_CONFIG:
  1541. StrCpy(g_szConfigURLPath, szCabInfoLine);
  1542. StrCpy(g_szConfigCabName, PathFindFileName(szCabFullFileName));
  1543. break;
  1544. case CAB_TYPE_DESKTOP:
  1545. StrCpy(g_szDesktopURLPath, szCabInfoLine);
  1546. StrCpy(g_szDesktopCabName, PathFindFileName(szCabFullFileName));
  1547. break;
  1548. }
  1549. return szCabFullFileName;
  1550. }
  1551. // use the default cab name output by ieakwiz.exe
  1552. switch (dwCabType)
  1553. {
  1554. case CAB_TYPE_CONFIG:
  1555. GetBaseFileName(pcszInsFile, szCabName, ARRAYSIZE(szCabName));
  1556. if (StrCmpI(szCabName, TEXT("install")) == 0)
  1557. StrCpy(szCabName, TEXT("branding"));
  1558. StrCat(szCabName, TEXT(".cab"));
  1559. break;
  1560. case CAB_TYPE_DESKTOP:
  1561. StrCpy(szCabName, TEXT("desktop.cab"));
  1562. break;
  1563. case CAB_TYPE_CHANNELS:
  1564. StrCpy(szCabName, TEXT("chnls.cab"));
  1565. break;
  1566. }
  1567. DirectoryName(pcszInsFile, szCabFilePath);
  1568. PathCombine(szCabFullFileName, szCabFilePath, szCabName);
  1569. if (PathFileExists(szCabFullFileName))
  1570. return szCabFullFileName;
  1571. else
  1572. *szCabFullFileName = TEXT('\0');
  1573. return NULL;
  1574. }
  1575. void CabUpFolder(HWND hWnd, LPTSTR szFolderPath, LPTSTR szDestDir, LPTSTR szCabname, BOOL fSubDirs)
  1576. {
  1577. TCHAR szFrom[MAX_PATH];
  1578. TCHAR szCabPath[MAX_PATH];
  1579. TCHAR szDiamondParams[MAX_PATH * 2];
  1580. SHELLEXECUTEINFO shInfo;
  1581. TCHAR szToolsFile[MAX_PATH];
  1582. DWORD dwCode;
  1583. wsprintf(szCabPath, TEXT("%s\\%s"), szDestDir, szCabname);
  1584. if (fSubDirs)
  1585. wsprintf(szDiamondParams, TEXT("-p -r n \"%s\" *.*"), szCabPath);
  1586. else
  1587. wsprintf(szDiamondParams, TEXT("n \"%s\" *.*"), szCabPath);
  1588. ZeroMemory(&shInfo, sizeof(shInfo));
  1589. shInfo.cbSize = sizeof(shInfo);
  1590. shInfo.hwnd = hWnd;
  1591. shInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  1592. shInfo.lpVerb = TEXT("open");
  1593. wsprintf(szToolsFile, TEXT("%stools\\CABARC.EXE"), g_szRoot);
  1594. shInfo.lpFile = szToolsFile;
  1595. shInfo.lpParameters = szDiamondParams;
  1596. shInfo.lpDirectory = szFolderPath;
  1597. shInfo.nShow = SW_MINIMIZE;
  1598. SetCurrentDirectory(szFolderPath);
  1599. ShellExecuteEx(&shInfo);
  1600. while (MsgWaitForMultipleObjects(1, &shInfo.hProcess, FALSE, INFINITE, QS_ALLINPUT) != WAIT_OBJECT_0)
  1601. {
  1602. MSG msg;
  1603. while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  1604. {
  1605. TranslateMessage(&msg);
  1606. DispatchMessage(&msg);
  1607. }
  1608. }
  1609. GetExitCodeProcess(shInfo.hProcess, &dwCode);
  1610. CloseHandle(shInfo.hProcess);
  1611. if (g_dwPlatformId == PLATFORM_WIN32)
  1612. {
  1613. TCHAR szDest[MAX_PATH];
  1614. PathCombine(szToolsFile, g_szRoot, TEXT("tools\\signcode.exe"));
  1615. PathCombine(szDest, szDestDir, TEXT("signcode.exe"));
  1616. CopyFile(szToolsFile, szDest, FALSE);
  1617. PathCombine(szToolsFile, g_szRoot, TEXT("tools\\signer.dll"));
  1618. PathCombine(szDest, szDestDir, TEXT("signer.dll"));
  1619. CopyFile(szToolsFile, szDest, FALSE);
  1620. SignFile(szCabname, szDestDir, g_szInsFile, s_szUnsignedFiles);
  1621. }
  1622. SetCurrentDirectory(g_szRoot);
  1623. }
  1624. BOOL CompressCabFile()
  1625. {
  1626. TCHAR szCabFilePath[MAX_PATH];
  1627. TCHAR szCif[MAX_PATH];
  1628. TCHAR szDisplayName[MAX_PATH];
  1629. TCHAR szBaseInsFileName[_MAX_FNAME];
  1630. TCHAR szCabSrcFile[MAX_PATH];
  1631. TCHAR szCabDestFile[MAX_PATH];
  1632. TCHAR szType[8];
  1633. BOOL fUpdateInsVer = FALSE;
  1634. DWORD dwSpaceReq, dwSpaceFree;
  1635. ZeroMemory(szCif, sizeof(szCif));
  1636. ZeroMemory(szDisplayName, sizeof(szDisplayName));
  1637. DirectoryName(g_szFileName, szCabFilePath);
  1638. GetBaseFileName(g_szFileName, szBaseInsFileName, ARRAYSIZE(szBaseInsFileName));
  1639. if(lstrcmpi(szBaseInsFileName, TEXT("install")) == 0)
  1640. lstrcpy(szBaseInsFileName, TEXT("branding"));
  1641. wsprintf(szCif, TEXT("%s\\%s.cif"), g_szCabTempDir, szBaseInsFileName);
  1642. lstrcpy(szDisplayName, szBaseInsFileName);
  1643. DeleteFileInDir(TEXT("*.cab"), g_szCabTempDir);
  1644. //-------------------- Config
  1645. if (*g_szConfigCabName != TEXT('\0') && !PathIsEmptyPath(g_szCabWorkDir))
  1646. {
  1647. TCHAR szConfigDir[MAX_PATH];
  1648. PathCombine(szConfigDir, g_szCabWorkDir, TEXT("Config"));
  1649. // before copying files to the config dir, clear the dir if there were old
  1650. // files from a previous save.
  1651. PathRemovePath(szConfigDir);
  1652. CopyDir(g_szCabWorkDir, szConfigDir);
  1653. if (!PathIsEmptyPath(szConfigDir))
  1654. {
  1655. CabUpFolder(NULL, szConfigDir, g_szCabTempDir, TEXT("config.cab"));
  1656. wsprintf(szCabSrcFile, TEXT("%s\\%s"), g_szCabTempDir, TEXT("config.cab"));
  1657. wsprintf(szCabDestFile, TEXT("%s\\%s"), g_szCabTempDir, g_szConfigCabName);
  1658. MoveFile(szCabSrcFile, szCabDestFile);
  1659. }
  1660. }
  1661. //-------------------- Desktop
  1662. if (*g_szDesktopCabName != TEXT('\0') && !PathIsEmptyPath(g_szDesktopDir, FILES_ONLY))
  1663. {
  1664. CabUpFolder(NULL, g_szDesktopDir, g_szCabTempDir, TEXT("desktop.cab"));
  1665. wsprintf(szCabSrcFile, TEXT("%s\\%s"), g_szCabTempDir, TEXT("desktop.cab"));
  1666. wsprintf(szCabDestFile, TEXT("%s\\%s"), g_szCabTempDir, g_szDesktopCabName);
  1667. MoveFile(szCabSrcFile, szCabDestFile);
  1668. }
  1669. // Check for disk space availability
  1670. while (!EnoughDiskSpace(g_szCabTempDir, szCabFilePath, &dwSpaceReq, &dwSpaceFree))
  1671. {
  1672. LPTSTR pMsg;
  1673. int nResult;
  1674. pMsg = FormatString(Res2Str(IDS_INSUFFICIENT_DISKSPACE), dwSpaceReq, dwSpaceFree);
  1675. nResult = MessageBox(g_hMain, pMsg, Res2Str(IDS_TITLE), MB_ICONQUESTION | MB_YESNO);
  1676. LocalFree(pMsg);
  1677. if (nResult == IDNO)
  1678. return FALSE;
  1679. }
  1680. //flush temp INS file
  1681. InsFlushChanges(g_szInsFile);
  1682. //-------------------- Ins file
  1683. SetFileAttributes(g_szFileName, FILE_ATTRIBUTE_NORMAL);
  1684. CopyFile(g_szInsFile, g_szFileName, FALSE);
  1685. //-------------------- Config
  1686. wsprintf(szCabSrcFile, TEXT("%s\\%s"), g_szCabTempDir, g_szConfigCabName);
  1687. if (*g_szConfigCabName != TEXT('\0') && PathFileExists(szCabSrcFile))
  1688. {
  1689. CopyFileToDir(szCabSrcFile, szCabFilePath);
  1690. fUpdateInsVer = TRUE;
  1691. SetOrClearVersionInfo(g_szFileName, CAB_TYPE_CONFIG, g_szConfigCabName,
  1692. g_szCabsURLPath, g_szNewVersionStr, SET);
  1693. }
  1694. else
  1695. SetOrClearVersionInfo(g_szFileName, CAB_TYPE_CONFIG, g_szConfigCabName,
  1696. g_szCabsURLPath, g_szNewVersionStr, CLEAR);
  1697. //-------------------- Desktop
  1698. wsprintf(szCabSrcFile, TEXT("%s\\%s"), g_szCabTempDir, g_szDesktopCabName);
  1699. if (*g_szDesktopCabName != TEXT('\0') && PathFileExists(szCabSrcFile))
  1700. {
  1701. CopyFileToDir(szCabSrcFile, szCabFilePath);
  1702. fUpdateInsVer = TRUE;
  1703. SetOrClearVersionInfo(g_szFileName, CAB_TYPE_DESKTOP, g_szDesktopCabName,
  1704. g_szCabsURLPath, g_szNewVersionStr, SET);
  1705. }
  1706. else
  1707. SetOrClearVersionInfo(g_szFileName, CAB_TYPE_DESKTOP, g_szDesktopCabName,
  1708. g_szCabsURLPath, g_szNewVersionStr, CLEAR);
  1709. WritePrivateProfileString(BRANDING, CABSURLPATH, fUpdateInsVer ? g_szCabsURLPath : NULL, g_szFileName);
  1710. WritePrivateProfileString(BRANDING, INSVERKEY, fUpdateInsVer ? g_szNewVersionStr : NULL, g_szFileName);
  1711. WritePrivateProfileString(BRANDING, PMVERKEY, A2CT(VER_PRODUCTVERSION_STR), g_szFileName);
  1712. //clear other keys so we're sure this is profmgr
  1713. WritePrivateProfileString(BRANDING, GPVERKEY, NULL, g_szFileName);
  1714. WritePrivateProfileString(BRANDING, IK_WIZVERSION, NULL, g_szFileName);
  1715. // write the type as INTRANET so that the branding DLL extracts and processes the cabs in the CUSTOM dir
  1716. wsprintf(szType, TEXT("%u"), INTRANET);
  1717. WritePrivateProfileString(BRANDING, TEXT("Type"), szType, g_szFileName);
  1718. SetForegroundWindow(g_hMain);
  1719. if (g_dwPlatformId == PLATFORM_WIN32)
  1720. {
  1721. if (ISNONNULL(s_szUnsignedFiles))
  1722. {
  1723. TCHAR szMessage[MAX_PATH*3];
  1724. TCHAR szMsg[64];
  1725. LoadString(g_hInst, IDS_CABSIGN_ERROR, szMsg, ARRAYSIZE(szMsg));
  1726. wsprintf(szMessage, szMsg, s_szUnsignedFiles);
  1727. MessageBox(g_hMain, szMessage, TEXT(""), MB_OK | MB_SETFOREGROUND);
  1728. ZeroMemory(s_szUnsignedFiles, sizeof(s_szUnsignedFiles));
  1729. }
  1730. }
  1731. InsFlushChanges(g_szFileName);
  1732. return TRUE;
  1733. }
  1734. void DeleteCabWorkDirs()
  1735. {
  1736. if(*g_szCabWorkDir)
  1737. {
  1738. PathRemovePath(g_szCabWorkDir);
  1739. ZeroMemory(g_szCabWorkDir, sizeof(g_szCabWorkDir));
  1740. }
  1741. if(*g_szCabTempDir)
  1742. {
  1743. PathRemovePath(g_szCabTempDir);
  1744. ZeroMemory(g_szCabTempDir, sizeof(g_szCabTempDir));
  1745. }
  1746. }
  1747. void CreateCabWorkDirs(LPCTSTR szWorkDir)
  1748. {
  1749. TCHAR szTempPath[MAX_PATH];
  1750. if(*g_szCabWorkDir)
  1751. DeleteCabWorkDirs();
  1752. GetTempPath(ARRAYSIZE(szTempPath), szTempPath);
  1753. wsprintf(g_szCabWorkDir, TEXT("%s%scabwrk"), szTempPath, szWorkDir);
  1754. CreateDirectory(g_szCabWorkDir, NULL);
  1755. PathCombine(g_szDesktopDir, g_szCabWorkDir, TEXT("desktop"));
  1756. CreateDirectory(g_szDesktopDir, NULL);
  1757. wsprintf(g_szCabTempDir, TEXT("%scabtmp"), szTempPath);
  1758. CreateDirectory(g_szCabTempDir, NULL);
  1759. }
  1760. void CopyDir(LPCTSTR szSrcDir, LPCTSTR szDestDir)
  1761. {
  1762. WIN32_FIND_DATA wfdFind;
  1763. HANDLE hFind;
  1764. TCHAR szNewDir[MAX_PATH];
  1765. TCHAR szTemp[MAX_PATH];
  1766. TCHAR szTemp1[MAX_PATH];
  1767. wsprintf(szTemp, TEXT("%s\\*.*"), szSrcDir);
  1768. hFind = FindFirstFile(szTemp, &wfdFind);
  1769. if(hFind == INVALID_HANDLE_VALUE)
  1770. return;
  1771. CreateDirectory(szDestDir, NULL);
  1772. do
  1773. {
  1774. if(!(wfdFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  1775. {
  1776. wsprintf(szTemp, TEXT("%s\\%s"), szSrcDir, wfdFind.cFileName);
  1777. wsprintf(szTemp1, TEXT("%s\\%s"), szDestDir, wfdFind.cFileName);
  1778. SetFileAttributes(szTemp, FILE_ATTRIBUTE_NORMAL);
  1779. CopyFile(szTemp, szTemp1, FALSE);
  1780. }
  1781. }while(FindNextFile(hFind, &wfdFind));
  1782. FindClose(hFind);
  1783. }
  1784. void GetLangDesc(LPTSTR szLangId, LPTSTR szLangDesc, int cchLangDescSize, LPDWORD dwLangId)
  1785. {
  1786. DWORD dwErr = 0;
  1787. RFC1766INFO rInfo;
  1788. LCID lcid;
  1789. BOOL fDef = FALSE;
  1790. LCID curLcid = GetUserDefaultLCID();
  1791. LPMULTILANGUAGE pMLang = NULL;
  1792. TCHAR szLocale[MAX_PATH];
  1793. ZeroMemory(szLangDesc, cchLangDescSize * sizeof(TCHAR));
  1794. wsprintf(szLocale, TEXT("%sLocale.ini"), g_szRoot);
  1795. GetPrivateProfileString(TEXT("Strings"), szLangId, TEXT(""), szLangDesc, cchLangDescSize, szLocale);
  1796. CharLower(szLangId);
  1797. dwErr = CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER, IID_IMultiLanguage, (void **) &pMLang);
  1798. if(pMLang)
  1799. {
  1800. if((dwErr = GetLcid(&lcid, szLangId, szLocale)) == NOERROR)
  1801. {
  1802. if(*szLangDesc == 0)
  1803. {
  1804. dwErr = pMLang->GetRfc1766Info(lcid, &rInfo);
  1805. #ifdef UNICODE
  1806. StrCpyW(szLangDesc, rInfo.wszLocaleName);
  1807. #else
  1808. WideCharToMultiByte(CP_ACP, 0, rInfo.wszLocaleName, -1, szLangDesc, 32, TEXT(" "), &fDef);
  1809. #endif
  1810. }
  1811. }
  1812. else
  1813. lcid = curLcid;
  1814. pMLang->Release();
  1815. }
  1816. *dwLangId = lcid;
  1817. }
  1818. INT_PTR CALLBACK LanguageDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1819. {
  1820. WIN32_FIND_DATA wfdFind;
  1821. HANDLE hFind;
  1822. TCHAR szPolicyDir[MAX_PATH];
  1823. TCHAR szLangDir[10];
  1824. int nItems = 0;
  1825. int nSelItem = -1;
  1826. TCHAR szLangDesc[100];
  1827. LPTSTR pLangId = NULL;
  1828. int nIndex = -1;
  1829. TCHAR szMsg[MAX_PATH];
  1830. DWORD dwLangId = 0;
  1831. typedef struct LangLocale
  1832. {
  1833. TCHAR szLang[10];
  1834. DWORD dwLang;
  1835. } LANGID;
  1836. static LANGID lang[NUMLANG];
  1837. switch(msg)
  1838. {
  1839. case WM_INITDIALOG:
  1840. LoadString(g_hInst, IDS_LANGUAGE, szMsg, ARRAYSIZE(szMsg));
  1841. SetWindowText(hDlg, szMsg);
  1842. // get the all the directories under the ieak\policies directory
  1843. wsprintf(szPolicyDir, TEXT("%s\\iebin\\*.*"), g_szRoot);
  1844. hFind = FindFirstFile(szPolicyDir, &wfdFind);
  1845. if(hFind == INVALID_HANDLE_VALUE)
  1846. {
  1847. EndDialog(hDlg, 1);
  1848. break;
  1849. }
  1850. ZeroMemory(lang, sizeof(LANGID) * NUMLANG);
  1851. do
  1852. {
  1853. if(wfdFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  1854. {
  1855. // avoid the . and .. case
  1856. if(StrCmp(wfdFind.cFileName, TEXT(".")) != 0 && StrCmp(wfdFind.cFileName, TEXT("..")) != 0)
  1857. {
  1858. GetLangDesc(wfdFind.cFileName, szLangDesc, ARRAYSIZE(szLangDesc), &dwLangId);
  1859. if(*szLangDesc != TEXT('\0') &&
  1860. PlatformExists(hDlg, wfdFind.cFileName, PLATFORM_WIN32))
  1861. {
  1862. nIndex = (int) SendMessage(GetDlgItem(hDlg, IDC_LANG), CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) szLangDesc);
  1863. if(nIndex != CB_ERR)
  1864. {
  1865. lstrcpy(lang[nIndex].szLang, wfdFind.cFileName);
  1866. lang[nIndex].dwLang = dwLangId;
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }while(FindNextFile(hFind, &wfdFind));
  1872. FindClose(hFind);
  1873. nItems = (int) SendMessage(GetDlgItem(hDlg, IDC_LANG), CB_GETCOUNT, 0, 0L);
  1874. if(nItems == 0)
  1875. {
  1876. EndDialog(hDlg, 1);
  1877. break;
  1878. }
  1879. else if(nItems == 1)
  1880. {
  1881. lstrcpy(g_szLanguage, lang[0].szLang);
  1882. g_dwLanguage = lang[0].dwLang;
  1883. EndDialog(hDlg, 1);
  1884. break;
  1885. }
  1886. SendMessage(GetDlgItem(hDlg, IDC_LANG), CB_SETCURSEL, 0, 0L);
  1887. EnableWindow(hDlg, TRUE);
  1888. ShowWindow(hDlg, SW_SHOWNORMAL);
  1889. break;
  1890. case WM_COMMAND:
  1891. if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDOK)
  1892. {
  1893. int nSelItem = (int) SendMessage(GetDlgItem(hDlg, IDC_LANG), CB_GETCURSEL, 0, 0L);
  1894. if(nSelItem != CB_ERR)
  1895. {
  1896. lstrcpy(g_szLanguage, lang[nSelItem].szLang);
  1897. g_dwLanguage = lang[nSelItem].dwLang;
  1898. }
  1899. EndDialog(hDlg, 1);
  1900. }
  1901. break;
  1902. case WM_DESTROY:
  1903. case WM_CLOSE:
  1904. SendMessage(GetDlgItem(hDlg, IDC_LANG), CB_RESETCONTENT, 0, 0L);
  1905. break;
  1906. default:
  1907. return 0;
  1908. }
  1909. return 1;
  1910. }
  1911. void PrepareFolderForCabbing(LPCTSTR pcszDestDir, DWORD dwFlags)
  1912. {
  1913. int i;
  1914. for (i = 0; i < g_nDialogs; i++)
  1915. if (g_pInsDialog[i].pfnFinalCopy != NULL)
  1916. g_pInsDialog[i].pfnFinalCopy(pcszDestDir, dwFlags, NULL);
  1917. }
  1918. BOOL DoCompressCabFile(LPVOID lpVoid)
  1919. {
  1920. HWND hDlg = (HWND) lpVoid;
  1921. BOOL fSuccess;
  1922. fSuccess = CompressCabFile();
  1923. PostMessage(hDlg, UM_SAVE_COMPLETE, 0, (LPARAM)fSuccess);
  1924. return TRUE;
  1925. }
  1926. INT_PTR CALLBACK DisplaySaveDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  1927. {
  1928. static HANDLE hIcon = NULL;
  1929. static HANDLE hThread;
  1930. DWORD dwThread;
  1931. switch(msg)
  1932. {
  1933. case WM_INITDIALOG:
  1934. SetWindowText(hDlg, Res2Str(IDS_TITLE));
  1935. Animate_Open( GetDlgItem( hDlg, IDC_ANIMATE ), IDA_GEARS );
  1936. Animate_Play( GetDlgItem( hDlg, IDC_ANIMATE ), 0, -1, -1 );
  1937. if((hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) DoCompressCabFile, (LPVOID) hDlg, 0, &dwThread)) == NULL)
  1938. {
  1939. int nResult = CompressCabFile();
  1940. EndDialog(hDlg, nResult);
  1941. }
  1942. break;
  1943. case UM_SAVE_COMPLETE:
  1944. EndDialog(hDlg, lParam);
  1945. break;
  1946. case WM_DESTROY:
  1947. if (hThread != NULL)
  1948. CloseHandle(hThread);
  1949. if (hIcon != NULL)
  1950. DestroyIcon((HICON) hIcon);
  1951. break;
  1952. default:
  1953. return 0;
  1954. }
  1955. return 1;
  1956. }
  1957. DWORD GetCabBuildStatus()
  1958. // This is a real hacky function. It checks whether the work dirs are empty or not and
  1959. // returns the cabs that will be built.
  1960. {
  1961. DWORD dwCabsToBuild = 0;
  1962. for (int nIndex = 0; nIndex < g_nDialogs; nIndex++)
  1963. {
  1964. if (g_pInsDialog[nIndex].pfnFinalCopy != NULL)
  1965. g_pInsDialog[nIndex].pfnFinalCopy(g_szCabWorkDir, PM_CHECK, &dwCabsToBuild);
  1966. }
  1967. if (IsAdmDirty() || !PathIsEmptyPath(g_szCabWorkDir, FILES_ONLY))
  1968. SetFlag(&dwCabsToBuild, CAB_TYPE_CONFIG);
  1969. if (!PathIsEmptyPath(g_szDesktopDir, FILES_ONLY))
  1970. SetFlag(&dwCabsToBuild, CAB_TYPE_DESKTOP);
  1971. return dwCabsToBuild;
  1972. }
  1973. void GetDefaultInf(DWORD dwPlatformId)
  1974. {
  1975. switch(dwPlatformId)
  1976. {
  1977. case PLATFORM_WIN32:
  1978. case PLATFORM_W2K:
  1979. default:
  1980. wsprintf(g_szDefInf, TEXT("%siebin\\%s\\Optional\\DefFav.inf"), g_szRoot, g_szLanguage);
  1981. break;
  1982. }
  1983. }
  1984. void GetDefaultCabName(DWORD dwCabType, LPCTSTR pcszPrefix, LPTSTR pszCabName)
  1985. {
  1986. TCHAR szActualPrefix[MAX_PATH];
  1987. if (pszCabName == NULL)
  1988. return;
  1989. *pszCabName = TEXT('\0');
  1990. if (pcszPrefix == NULL || *pcszPrefix == TEXT('\0'))
  1991. return;
  1992. if (StrChr(pcszPrefix, '.') != NULL)
  1993. {
  1994. lstrcpy(pszCabName, pcszPrefix);
  1995. return;
  1996. }
  1997. lstrcpy(szActualPrefix, pcszPrefix);
  1998. switch(dwCabType)
  1999. {
  2000. case CAB_TYPE_CONFIG:
  2001. wsprintf(pszCabName, TEXT("%s_config.cab"), szActualPrefix);
  2002. break;
  2003. case CAB_TYPE_DESKTOP:
  2004. wsprintf(pszCabName, TEXT("%s_desktop.cab"), szActualPrefix);
  2005. break;
  2006. }
  2007. }
  2008. BOOL InitializePlatform(HWND hWnd, HWND hInfoWnd, WORD wPlatform)
  2009. {
  2010. TCHAR szTemp[MAX_PATH];
  2011. HMENU hMenu = GetSubMenu(GetMenu(hWnd), 2);
  2012. DWORD dwPlatformId;
  2013. if (hMenu)
  2014. {
  2015. UINT nMenuState = GetMenuState(hMenu, wPlatform, MF_BYCOMMAND);
  2016. if (nMenuState != 0xFFFFFFFF && (nMenuState & MF_CHECKED) == 0) // if not checked
  2017. {
  2018. TreeView.SetSel(g_hInsRootItem);
  2019. if (TreeView.GetSel() != g_hInsRootItem) // error closing/saving the visible page
  2020. return FALSE;
  2021. if (wPlatform == IDM_PLATFORM_WIN32)
  2022. dwPlatformId = PLATFORM_WIN32;
  2023. else if (wPlatform == IDM_PLATFORM_W2K)
  2024. dwPlatformId = PLATFORM_W2K;
  2025. // check if the selected platform Optional cab is available for the language.
  2026. if (!PlatformExists(hWnd, g_szLanguage, dwPlatformId))
  2027. {
  2028. TCHAR szPlatformText[25],
  2029. szLangDesc[200];
  2030. LPTSTR pMsg;
  2031. DWORD dwLangId;
  2032. if (dwPlatformId == PLATFORM_WIN32)
  2033. StrCpy(szPlatformText, Res2Str(IDS_WIN32));
  2034. else if (dwPlatformId == PLATFORM_W2K)
  2035. StrCpy(szPlatformText, Res2Str(IDS_W2K));
  2036. GetLangDesc(g_szLanguage, szLangDesc, ARRAYSIZE(szLangDesc), &dwLangId);
  2037. pMsg = FormatString(Res2Str(IDS_NOPLATFORMDIR), szPlatformText, szLangDesc);
  2038. MessageBox(hWnd, pMsg, Res2Str(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  2039. LocalFree(pMsg);
  2040. return FALSE;
  2041. }
  2042. CheckMenuItem(hMenu, IDM_PLATFORM_WIN32, MF_BYCOMMAND | MF_UNCHECKED);
  2043. CheckMenuItem(hMenu, IDM_PLATFORM_W2K, MF_BYCOMMAND | MF_UNCHECKED);
  2044. CheckMenuItem(hMenu, wPlatform, MF_BYCOMMAND | MF_CHECKED);
  2045. g_dwPlatformId = dwPlatformId;
  2046. GetDefaultInf(g_dwPlatformId);
  2047. SetDefaultInf(g_szDefInf);
  2048. TreeView.DeleteNodes(g_hInsRootItem);
  2049. SetPlatformInfo(g_dwPlatformId);
  2050. ReInitializeInsDialogProcs();
  2051. g_pInsDialog = GetInsDlgStruct(&g_nDialogs);
  2052. DeleteADMItems(TreeView.GetHandle(), g_szCabWorkDir, g_szInsFile, TRUE);
  2053. InitTreeView(TreeView.GetHandle(), hInfoWnd);
  2054. }
  2055. }
  2056. return TRUE;
  2057. }
  2058. void IeakPageHelp(HWND hWnd, LPCTSTR pszData)
  2059. {
  2060. TCHAR szHelpPath[MAX_PATH];
  2061. PathCombine(szHelpPath, g_szRoot, TEXT("ieakhelp.chm"));
  2062. g_hWndHelp = HtmlHelp(NULL, szHelpPath, HH_HELP_CONTEXT, (ULONG_PTR) pszData);
  2063. SetForegroundWindow(g_hWndHelp);
  2064. }
  2065. void UpdateRecentFileListMenu(HWND hWnd, TCHAR pRecentFileList[5][MAX_PATH])
  2066. {
  2067. HMENU hMenu;
  2068. MENUITEMINFO mii;
  2069. hMenu = GetSubMenu(GetMenu(hWnd), 0); // 0 is the position of the FILE menu
  2070. int nMenuItems = GetMenuItemCount(hMenu);
  2071. if (nMenuItems > 7) // 7 is the no. of menu items in the list excluding the recent file list items
  2072. { // delete all the recent file list menu items including the seperator
  2073. for (int nIndex = 0; nIndex < nMenuItems - 7; nIndex++)
  2074. DeleteMenu(hMenu, 6, MF_BYPOSITION); // the recent file list items start at position 6 in the FILE menu
  2075. }
  2076. // add the recent file list menu items
  2077. mii.cbSize = sizeof(MENUITEMINFO);
  2078. for(int nIndex = 0; nIndex < 5; nIndex++)
  2079. {
  2080. if (*pRecentFileList[nIndex] != TEXT('\0'))
  2081. {
  2082. mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA;
  2083. mii.fType = MFT_STRING;
  2084. mii.dwTypeData = pRecentFileList[nIndex];
  2085. mii.cch = StrLen(pRecentFileList[nIndex]);
  2086. mii.wID = IDM_RECENTFILELIST + nIndex;
  2087. InsertMenuItem(hMenu, 6 + nIndex, TRUE, &mii);
  2088. }
  2089. else
  2090. break;
  2091. }
  2092. // add the seperator if menu items were added
  2093. if (nIndex > 0)
  2094. {
  2095. mii.fMask = MIIM_ID | MIIM_TYPE;
  2096. mii.fType = MFT_SEPARATOR;
  2097. mii.wID = IDM_RECENTFILELIST + nIndex;
  2098. InsertMenuItem(hMenu, 6 + nIndex, TRUE, &mii);
  2099. }
  2100. DrawMenuBar(hWnd);
  2101. }
  2102. void ReadRecentFileList(TCHAR pRecentFileList[5][MAX_PATH])
  2103. {
  2104. HKEY hKey;
  2105. TCHAR szValue[20];
  2106. DWORD dwType;
  2107. TCHAR szData[MAX_PATH];
  2108. DWORD dwSize;
  2109. ZeroMemory(pRecentFileList, sizeof(pRecentFileList[0]) * 5);
  2110. if (RegOpenKeyEx(HKEY_CURRENT_USER, RK_IEAK_SERVER TEXT("\\ProfMgr"), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  2111. {
  2112. // get the registry entries
  2113. for (int nIndex = 1; nIndex < 6; nIndex++)
  2114. {
  2115. wsprintf(szValue, TEXT("RecentFile%d"), nIndex);
  2116. dwSize = sizeof(szData);
  2117. if (RegQueryValueEx(hKey, szValue, NULL, &dwType, (LPBYTE) szData, &dwSize) == ERROR_SUCCESS)
  2118. StrCpy(pRecentFileList[nIndex - 1], szData);
  2119. else
  2120. break;
  2121. }
  2122. RegCloseKey(hKey);
  2123. }
  2124. }
  2125. void UpdateRecentFileList(LPCTSTR pcszFile, BOOL fAdd, TCHAR pRecentFileList[5][MAX_PATH])
  2126. {
  2127. HKEY hKey;
  2128. TCHAR szValue[20];
  2129. DWORD dwType;
  2130. DWORD dwSize;
  2131. int nFilenamePos = -1;
  2132. for (int nIndex = 0; nIndex < 5; nIndex++)
  2133. {
  2134. if (StrCmpI(pRecentFileList[nIndex], pcszFile) == 0)
  2135. nFilenamePos = nIndex;
  2136. }
  2137. if (fAdd)
  2138. {
  2139. if (nFilenamePos > 0)
  2140. { // if the filename exists in the list bring to the top
  2141. for (nIndex = nFilenamePos; nIndex > 0; nIndex--)
  2142. StrCpy(pRecentFileList[nIndex], pRecentFileList[nIndex - 1]);
  2143. StrCpy(pRecentFileList[0], pcszFile);
  2144. }
  2145. else if (nFilenamePos == -1)
  2146. { // move the list contents i.e., 1-4 to 2-5
  2147. for (nIndex = 3; nIndex >= 0; nIndex--)
  2148. {
  2149. if (*pRecentFileList[nIndex] != TEXT('\0'))
  2150. StrCpy(pRecentFileList[nIndex + 1], pRecentFileList[nIndex]);
  2151. }
  2152. StrCpy(pRecentFileList[0], pcszFile);
  2153. }
  2154. }
  2155. else
  2156. {
  2157. if (nFilenamePos >= 0)
  2158. {
  2159. for (nIndex = nFilenamePos; nIndex < 4; nIndex++)
  2160. StrCpy(pRecentFileList[nIndex], pRecentFileList[nIndex + 1]);
  2161. ZeroMemory(pRecentFileList[4], sizeof(pRecentFileList[4]));
  2162. }
  2163. }
  2164. }
  2165. void WriteRecentFileList(TCHAR pRecentFileList[5][MAX_PATH])
  2166. {
  2167. HKEY hKey;
  2168. TCHAR szValue[20];
  2169. DWORD dwDisposition;
  2170. if (RegCreateKeyEx(HKEY_CURRENT_USER, RK_IEAK_SERVER TEXT("\\ProfMgr"), 0, TEXT(""), REG_OPTION_NON_VOLATILE,
  2171. KEY_WRITE, NULL, &hKey, &dwDisposition) == ERROR_SUCCESS)
  2172. {
  2173. for (int nIndex = 0; nIndex < 5; nIndex++)
  2174. {
  2175. wsprintf(szValue, TEXT("RecentFile%d"), nIndex + 1);
  2176. if (*pRecentFileList[nIndex] != TEXT('\0'))
  2177. RegSetValueEx(hKey, szValue, 0, REG_SZ, (const BYTE *)pRecentFileList[nIndex], (StrLen(pRecentFileList[nIndex]) + 1) * sizeof(TCHAR));
  2178. else
  2179. RegDeleteValue(hKey, szValue);
  2180. }
  2181. RegCloseKey(hKey);
  2182. }
  2183. }
  2184. BOOL IsDirty()
  2185. {
  2186. return (InsDirty() || IsAdmDirty());
  2187. }
  2188. void ClearDirtyFlag()
  2189. {
  2190. ClearInsDirtyFlag();
  2191. ResetAdmDirtyFlag();
  2192. }
  2193. BOOL SaveCurrentSelItem(HWND hTreeView, DWORD dwFlags)
  2194. {
  2195. BOOL fRetVal = TRUE;
  2196. HTREEITEM hItem = TreeView.GetSel();
  2197. HTREEITEM hParentItem = TreeView_GetParent(hTreeView, hItem);
  2198. TVITEM tvitem;
  2199. DWORD dwItemFlags = 0;
  2200. if (hItem != NULL && hParentItem != NULL)
  2201. {
  2202. if (!IsPolicyTree(hItem))
  2203. {
  2204. if (g_hDialog)
  2205. {
  2206. fRetVal = SaveInsDialog(g_hDialog, dwFlags);
  2207. if (HasFlag(dwFlags, ITEM_DESTROY))
  2208. g_hDialog = NULL;
  2209. }
  2210. }
  2211. else if (hParentItem != g_hPolicyRootItem)
  2212. {
  2213. tvitem.mask = TVIF_PARAM;
  2214. tvitem.hItem = hItem;
  2215. TreeView_GetItem(hTreeView, &tvitem);
  2216. if (HasFlag(dwFlags, ITEM_CHECKDIRTY)) // for adm items checkitem for dirty
  2217. dwFlags |= ITEM_SAVE; // is same as saveitem
  2218. SaveADMItem(hTreeView, &tvitem, dwFlags);
  2219. }
  2220. }
  2221. return fRetVal;
  2222. }
  2223. void SetInfoWindowText(HWND hInfoWnd, LPCTSTR pcszStatusText /*= NULL*/)
  2224. {
  2225. TCHAR szInfoText[MAX_PATH*2],
  2226. szProfileState[MAX_PATH],
  2227. szCabsUrlPath[MAX_PATH],
  2228. szVersion[MAX_PATH],
  2229. szDefaultStr[MAX_PATH],
  2230. szStatusText[MAX_PATH],
  2231. szCabsUrlPathText[MAX_PATH],
  2232. szVersionText[MAX_PATH];
  2233. if (hInfoWnd == NULL)
  2234. return;
  2235. StrCpy(szDefaultStr, Res2Str(IDS_NOTAVAILABLE));
  2236. if (*g_szInsFile != TEXT('\0'))
  2237. {
  2238. if (IsDirty())
  2239. StrCpy(szProfileState, Res2Str(IDS_PROFILE_DIRTY));
  2240. else
  2241. StrCpy(szProfileState, Res2Str(IDS_PROFILE_NOCHANGE));
  2242. if (*g_szFileName != TEXT('\0') && *g_szNewVersionStr != TEXT('\0'))
  2243. StrCpy(szVersion, g_szNewVersionStr);
  2244. else
  2245. GetPrivateProfileString(BRANDING, INSVERKEY, szDefaultStr, szVersion, ARRAYSIZE(szVersion), g_szInsFile);
  2246. }
  2247. else
  2248. {
  2249. StrCpy(szProfileState, szDefaultStr);
  2250. StrCpy(szVersion, szDefaultStr);
  2251. }
  2252. if (pcszStatusText != NULL && *pcszStatusText != TEXT('\0'))
  2253. StrCpy(szProfileState, pcszStatusText);
  2254. if (*g_szCabsURLPath == TEXT('\0'))
  2255. StrCpy(szCabsUrlPath, szDefaultStr);
  2256. else
  2257. {
  2258. if (StrLen(g_szCabsURLPath) > 80) // 80 is the max. characters that can be displayed.
  2259. {
  2260. StrCpyN(szCabsUrlPath, g_szCabsURLPath, 77);
  2261. StrCat(szCabsUrlPath, TEXT("..."));
  2262. }
  2263. else
  2264. #pragma prefast(suppress:202,"g_szCabsURLPath length is less than 80, dest. buffer is MAX_PATH")
  2265. StrCpy(szCabsUrlPath, g_szCabsURLPath);
  2266. }
  2267. wsprintf(szStatusText, Res2Str(IDS_STATUS), szProfileState);
  2268. wsprintf(szCabsUrlPathText, Res2Str(IDS_CABSURLPATH), szCabsUrlPath);
  2269. wsprintf(szVersionText, Res2Str(IDS_VERSIONINFO), szVersion);
  2270. wsprintf(szInfoText, TEXT("%s%s%s"), szStatusText, szCabsUrlPathText, szVersionText);
  2271. SendMessage(hInfoWnd, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)szInfoText);
  2272. }
  2273. BOOL PlatformExists(HWND hWnd, LPTSTR pLang, DWORD dwPlatform, BOOL fShowError /*= FALSE*/)
  2274. {
  2275. WIN32_FIND_DATA wfdFind;
  2276. HANDLE hFind;
  2277. TCHAR szLangDir[MAX_PATH],
  2278. szPlatform[10];
  2279. BOOL fRetVal = FALSE;
  2280. // get the all the directories under the ieak\iebin\<language>\Optional directory
  2281. wsprintf(szLangDir, TEXT("%s\\iebin\\%s\\Optional"), g_szRoot, pLang);
  2282. PathAppend(szLangDir, TEXT("deffav.inf"));
  2283. if (PathFileExists(szLangDir))
  2284. fRetVal = TRUE;
  2285. if (!fRetVal && fShowError)
  2286. {
  2287. TCHAR szPlatformText[25],
  2288. szLangDesc[200];
  2289. LPTSTR pMsg;
  2290. DWORD dwLangId;
  2291. if (dwPlatform == PLATFORM_WIN32)
  2292. StrCpy(szPlatformText, Res2Str(IDS_WIN32));
  2293. else if (dwPlatform == PLATFORM_W2K)
  2294. StrCpy(szPlatformText, Res2Str(IDS_W2K));
  2295. GetLangDesc(g_szLanguage, szLangDesc, ARRAYSIZE(szLangDesc), &dwLangId);
  2296. pMsg = FormatString(Res2Str(IDS_NOPLATFORMDIR), szPlatformText, szLangDesc);
  2297. MessageBox(hWnd, pMsg, Res2Str(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  2298. LocalFree(pMsg);
  2299. }
  2300. return fRetVal;
  2301. }
  2302. BOOL EnoughDiskSpace(LPCTSTR szSrcDir, LPCTSTR szDestDir, LPDWORD pdwSpaceReq, LPDWORD pdwSpaceFree)
  2303. {
  2304. TCHAR szDestFile[MAX_PATH];
  2305. DWORD dwFreeSpace = 0,
  2306. dwFlags = 0,
  2307. dwSrcSize = 0,
  2308. dwDestSize = 0,
  2309. dwSpaceReq = 0;
  2310. if (!GetFreeDiskSpace(szDestDir, &dwFreeSpace, &dwFlags))
  2311. return TRUE;
  2312. dwSrcSize = FileSize(g_szInsFile);
  2313. dwDestSize = FileSize(g_szFileName);
  2314. if (dwSrcSize > dwDestSize)
  2315. {
  2316. dwSpaceReq = dwSrcSize - dwDestSize;
  2317. dwSpaceReq >>= 10; // divide by 1024 (we are interested in KBytes)
  2318. dwSpaceReq++;
  2319. }
  2320. dwSpaceReq += FindSpaceRequired(szSrcDir, TEXT("*.cab"), szDestDir);
  2321. if (dwSpaceReq)
  2322. dwSpaceReq += 5; // 5K buffer to account for random stuff
  2323. if (dwFlags & FS_VOL_IS_COMPRESSED)
  2324. {
  2325. // if the destination volume is compressed, the space free returned is only
  2326. // a guesstimate; for example, if it's a DoubleSpace volume, the system thinks
  2327. // that it can compress by 50% and so it reports the free space as (actual free space * 2)
  2328. // it's better to be safe when dealing with compressed volumes; so bump up the space
  2329. // requirement by a factor 2
  2330. dwSpaceReq <<= 1; // multiply by 2
  2331. }
  2332. if (pdwSpaceReq != NULL)
  2333. *pdwSpaceReq = dwSpaceReq;
  2334. if (pdwSpaceFree != NULL)
  2335. *pdwSpaceFree = dwFreeSpace;
  2336. return dwFreeSpace > dwSpaceReq;
  2337. }
  2338. BOOL CabFilesExist(HWND hWnd, LPCTSTR pcszInsFile)
  2339. {
  2340. TCHAR szBrandingCab[MAX_PATH];
  2341. TCHAR szDesktopCab[MAX_PATH];
  2342. TCHAR szCabFailStr[MAX_PATH];
  2343. if (pcszInsFile == NULL || *pcszInsFile == TEXT('\0'))
  2344. return FALSE;
  2345. GetCabNameFromINS(pcszInsFile, CAB_TYPE_CONFIG, szBrandingCab);
  2346. GetCabNameFromINS(pcszInsFile, CAB_TYPE_DESKTOP, szDesktopCab);
  2347. *szCabFailStr = TEXT('\0');
  2348. if (*szBrandingCab != TEXT('\0') && !PathFileExists(szBrandingCab))
  2349. StrCpy(szCabFailStr, PathFindFileName(szBrandingCab));
  2350. if (*szDesktopCab != TEXT('\0') && !PathFileExists(szDesktopCab))
  2351. {
  2352. if (*szCabFailStr != TEXT('\0'))
  2353. StrCat(szCabFailStr, TEXT("\r\n"));
  2354. StrCat(szCabFailStr, PathFindFileName(szDesktopCab));
  2355. }
  2356. if (*szCabFailStr != TEXT('\0'))
  2357. {
  2358. LPTSTR pMsg = NULL;
  2359. pMsg = FormatString(Res2Str(IDS_CAB_DOESNOTEXIST), pcszInsFile, szCabFailStr);
  2360. MessageBox(hWnd, pMsg, Res2Str(IDS_TITLE), MB_ICONEXCLAMATION | MB_OK);
  2361. LocalFree(pMsg);
  2362. return FALSE;
  2363. }
  2364. return TRUE;
  2365. }
  2366. BOOL IsWin32INSFile(LPCTSTR pcszIns)
  2367. {
  2368. int nPlatformId = 0;
  2369. TCHAR szTemp[MAX_PATH];
  2370. InsGetString(IS_BRANDING, TEXT("Platform"), szTemp, countof(szTemp), pcszIns);
  2371. nPlatformId = StrToInt(szTemp);
  2372. if (nPlatformId != 0 && nPlatformId != PLATFORM_WIN32 && nPlatformId != PLATFORM_W2K)
  2373. {
  2374. TCHAR szMsg[MAX_PATH+128];
  2375. wsprintf(szMsg, Res2Str(IDS_UNSUPPORTED_PLATFORM), pcszIns);
  2376. MessageBox(g_hMain, szMsg, Res2Str(IDS_TITLE), MB_ICONINFORMATION | MB_OK);
  2377. return FALSE;
  2378. }
  2379. else if (nPlatformId == 0)
  2380. nPlatformId = PLATFORM_WIN32;
  2381. return TRUE;
  2382. }