Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6080 lines
207 KiB

  1. #define INC_OLE2
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shlobj.h>
  5. #include <prsht.h>
  6. #include <tchar.h>
  7. #include <windef.h>
  8. #include "resource.h"
  9. #include "commdlg.h"
  10. #include "shlwapi.h"
  11. #include "shellapi.h"
  12. #include "migwiz.h"
  13. #include "miginf.h"
  14. #include "migutil.h"
  15. #include "migtask.h"
  16. #include "migeng.h"
  17. #include "basetypes.h"
  18. #include "utiltypes.h"
  19. #include "objstr.h"
  20. #include "container.h"
  21. extern "C" {
  22. #include "ism.h"
  23. #include "main.h"
  24. }
  25. #include "modules.h"
  26. #define ENGINE_RULE_MAXLEN 4000
  27. #define ENGINE_TIMEOUT 180000
  28. #define DOWNSHIFT_PIXEL_OFFSET 60
  29. #define UPSHIFT_PIXEL_OFFSET -11
  30. #define PATH_SAFETY_CHARS 26
  31. #define ANIMATE_OPEN(w,c,x) SendDlgItemMessage(w,c,ACM_OPEN,(WPARAM)NULL,(LPARAM)(LPTSTR)MAKEINTRESOURCE(x))
  32. #define ANIMATE_PLAY(w,c) SendDlgItemMessage(w,c,ACM_PLAY,(WPARAM)-1,(LPARAM)MAKELONG(0,-1))
  33. #define ANIMATE_STOP(w,c) SendDlgItemMessage(w,c,ACM_STOP,(WPARAM)0,(LPARAM)0);
  34. #define ANIMATE_CLOSE(w,c) SendDlgItemMessage(w,c,ACM_OPEN,(WPARAM)NULL,(LPARAM)NULL);
  35. ///////////////////////////////////////////////////////////////
  36. // globals
  37. extern BOOL g_LogOffSystem;
  38. extern BOOL g_RebootSystem;
  39. extern BOOL g_ConfirmedLogOff;
  40. extern BOOL g_ConfirmedReboot;
  41. MigrationWizard* g_migwiz;
  42. HTREEITEM g_htiFolders;
  43. HTREEITEM g_htiFiles;
  44. HTREEITEM g_htiSettings;
  45. HTREEITEM g_htiTypes;
  46. // ISSUE: embed selections within the migration wizard
  47. BOOL g_fStoreToNetwork; // OLD COMPUTER ONLY: this means we've selected to store to the network
  48. BOOL g_fStoreToFloppy; // OLD COMPUTER ONLY: this means we've selected to store to floppies
  49. BOOL g_fStoreToCable; // this means we've selected direct cable transport
  50. BOOL g_fReadFromNetwork; // NEW COMPUTER ONLY: this means go ahead and read from the network immediately
  51. TCHAR g_szStore[MAX_PATH];
  52. BOOL g_NextPressed;
  53. BOOL g_fHaveWhistlerCD = FALSE;
  54. BOOL g_fAlreadyCollected = FALSE;
  55. TCHAR g_szToolDiskDrive[MAX_PATH];
  56. INT g_iEngineInit = ENGINE_NOTINIT;
  57. BOOL g_fCustomize; // used to store whether we've customized or not to help with navigation
  58. BOOL g_fOldComputer; // used to store whether we're on the old computer or not to help with navigation
  59. BOOL g_fHaveJaz = FALSE;
  60. BOOL g_fHaveZip = FALSE;
  61. BOOL g_fHaveNet = FALSE;
  62. BOOL g_hInitResult = E_FAIL;
  63. BOOL g_fCancelPressed = FALSE;
  64. BOOL g_fPickMethodReset = TRUE; // used to trigger a re-default of the PickMethod page
  65. BOOL g_fCustomizeComp = FALSE; // if the user has some customization
  66. BOOL g_CompleteLogOff = FALSE;
  67. BOOL g_CompleteReboot = FALSE;
  68. HWND g_hwndCurrent;
  69. extern BOOL g_fUberCancel; // has the user has confirmed cancel?
  70. HWND g_hwndDlg;
  71. HWND g_hwndWizard;
  72. UINT g_uChosenComponent = (UINT) -1;
  73. HANDLE g_TerminateEvent = NULL;
  74. CRITICAL_SECTION g_AppInfoCritSection;
  75. MIG_PROGRESSPHASE g_AppInfoPhase;
  76. UINT g_AppInfoSubPhase;
  77. MIG_OBJECTTYPEID g_AppInfoObjectTypeId;
  78. TCHAR g_AppInfoObjectName [4096];
  79. TCHAR g_AppInfoText [4096];
  80. extern Container *g_WebContainer;
  81. extern TCHAR g_HTMLAppList[MAX_PATH];
  82. extern TCHAR g_HTMLLog[MAX_PATH];
  83. extern DWORD g_HTMLErrArea;
  84. extern DWORD g_HTMLErrInstr;
  85. extern PCTSTR g_HTMLErrObjectType;
  86. extern PCTSTR g_HTMLErrObjectName;
  87. extern POBJLIST g_HTMLApps;
  88. extern POBJLIST g_HTMLWrnFile;
  89. extern POBJLIST g_HTMLWrnAltFile;
  90. extern POBJLIST g_HTMLWrnRas;
  91. extern POBJLIST g_HTMLWrnNet;
  92. extern POBJLIST g_HTMLWrnPrn;
  93. extern POBJLIST g_HTMLWrnGeneral;
  94. DWORD g_BaudRate [] = {CBR_110,
  95. CBR_300,
  96. CBR_600,
  97. CBR_1200,
  98. CBR_2400,
  99. CBR_4800,
  100. CBR_9600,
  101. CBR_14400,
  102. CBR_19200,
  103. CBR_38400,
  104. CBR_56000,
  105. CBR_57600,
  106. CBR_115200,
  107. CBR_128000,
  108. CBR_256000,
  109. 0};
  110. // environment variables
  111. BOOL _ShiftControl (HWND hwndControl, HWND hwndDlg, DWORD dwOffset)
  112. {
  113. RECT rc;
  114. POINT pt;
  115. LONG lExStyles;
  116. GetWindowRect(hwndControl, &rc);
  117. // This should really be done once per dialog, not once per control
  118. lExStyles = GetWindowLong (hwndDlg, GWL_EXSTYLE);
  119. if (lExStyles & WS_EX_LAYOUTRTL)
  120. {
  121. pt.x = rc.right;
  122. }
  123. else
  124. {
  125. pt.x = rc.left;
  126. }
  127. pt.y = rc.top;
  128. ScreenToClient(hwndDlg, &pt);
  129. SetWindowPos(hwndControl, 0, pt.x, pt.y + dwOffset, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  130. return TRUE;
  131. }
  132. BOOL CALLBACK _DownshiftControl (HWND hwndControl, LPARAM lParam)
  133. {
  134. return _ShiftControl(hwndControl, (HWND)lParam, DOWNSHIFT_PIXEL_OFFSET);
  135. }
  136. BOOL CALLBACK _UpshiftControl (HWND hwndControl, LPARAM lParam)
  137. {
  138. return _ShiftControl(hwndControl, (HWND)lParam, UPSHIFT_PIXEL_OFFSET);
  139. }
  140. VOID _OldStylify (HWND hwndDlg, UINT uTitleStrID)
  141. {
  142. HWND hwnd;
  143. // First, shift everything down
  144. EnumChildWindows(hwndDlg, _DownshiftControl, (LPARAM)hwndDlg);
  145. // Add a divider bar
  146. CreateWindow(TEXT("STATIC"),
  147. NULL,
  148. WS_CHILD | WS_VISIBLE | SS_SUNKEN,
  149. 0, 45,
  150. 515, 2,
  151. hwndDlg,
  152. (HMENU)IDC_WIZ95DIVIDER,
  153. g_migwiz->GetInstance(),
  154. NULL);
  155. // Add the Title
  156. hwnd = CreateWindow(TEXT("STATIC"),
  157. NULL,
  158. WS_CHILD | WS_VISIBLE,
  159. 11, 0,
  160. 475, 15,
  161. hwndDlg,
  162. (HMENU)IDC_WIZ95TITLE,
  163. g_migwiz->GetInstance(),
  164. NULL);
  165. // Set the Title font
  166. SetWindowFont(hwnd, g_migwiz->Get95HeaderFont(), TRUE);
  167. // Set the title string
  168. if (uTitleStrID != 0)
  169. {
  170. _SetTextLoadString(g_migwiz->GetInstance(), hwnd, uTitleStrID);
  171. }
  172. }
  173. // For Welcome and Completing pages
  174. VOID _OldStylifyTitle (HWND hwndDlg)
  175. {
  176. HWND hwnd;
  177. HANDLE hBitmap;
  178. // First, shift everything up
  179. EnumChildWindows(hwndDlg, _UpshiftControl, (LPARAM)hwndDlg);
  180. // Create the bitmap window
  181. hwnd = CreateWindow(TEXT("STATIC"),
  182. NULL,
  183. WS_CHILD | WS_VISIBLE | SS_BITMAP,
  184. 0, 0,
  185. 152, 290,
  186. hwndDlg,
  187. (HMENU)IDC_WIZ95WATERMARK,
  188. g_migwiz->GetInstance(),
  189. NULL);
  190. hBitmap = LoadImage(g_migwiz->GetInstance(),
  191. MAKEINTRESOURCE(IDB_WATERMARK),
  192. IMAGE_BITMAP,
  193. 0, 0,
  194. LR_SHARED);
  195. SendMessage(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);
  196. hBitmap = (HANDLE)SendMessage(hwnd, STM_GETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)NULL);
  197. }
  198. HTREEITEM __GetRootType (HWND hwndTree)
  199. {
  200. TV_INSERTSTRUCT tisTypes;
  201. TCHAR szPickTypes[MAX_LOADSTRING];
  202. if (!g_htiTypes) {
  203. tisTypes.hParent = NULL;
  204. tisTypes.hInsertAfter = TVI_ROOT;
  205. tisTypes.item.mask = TVIF_TEXT | TVIF_STATE;
  206. tisTypes.item.state = TVIS_EXPANDED;
  207. tisTypes.item.stateMask = TVIS_EXPANDED;
  208. LoadString(g_migwiz->GetInstance(), IDS_PICK_TYPES, szPickTypes, ARRAYSIZE(szPickTypes));
  209. tisTypes.item.pszText = szPickTypes;
  210. g_htiTypes = TreeView_InsertItem(hwndTree, &tisTypes);
  211. }
  212. return g_htiTypes;
  213. }
  214. HTREEITEM __GetRootFolder (HWND hwndTree)
  215. {
  216. TV_INSERTSTRUCT tisFolders;
  217. TCHAR szPickFolders[MAX_LOADSTRING];
  218. if (!g_htiFolders) {
  219. tisFolders.hParent = NULL;
  220. tisFolders.hInsertAfter = TVI_ROOT;
  221. tisFolders.item.mask = TVIF_TEXT | TVIF_STATE;
  222. tisFolders.item.state = TVIS_EXPANDED;
  223. tisFolders.item.stateMask = TVIS_EXPANDED;
  224. LoadString(g_migwiz->GetInstance(), IDS_PICK_FOLDERS, szPickFolders, ARRAYSIZE(szPickFolders));
  225. tisFolders.item.pszText = szPickFolders;
  226. g_htiFolders = TreeView_InsertItem(hwndTree, &tisFolders);
  227. }
  228. return g_htiFolders;
  229. }
  230. HTREEITEM __GetRootFile (HWND hwndTree)
  231. {
  232. TV_INSERTSTRUCT tisFiles;
  233. TCHAR szPickFiles[MAX_LOADSTRING];
  234. if (!g_htiFiles) {
  235. tisFiles.hParent = NULL;
  236. tisFiles.hInsertAfter = TVI_ROOT;
  237. tisFiles.item.mask = TVIF_TEXT | TVIF_STATE;
  238. tisFiles.item.state = TVIS_EXPANDED;
  239. tisFiles.item.stateMask = TVIS_EXPANDED;
  240. LoadString(g_migwiz->GetInstance(), IDS_PICK_FILES, szPickFiles, ARRAYSIZE(szPickFiles));
  241. tisFiles.item.pszText = szPickFiles;
  242. g_htiFiles = TreeView_InsertItem(hwndTree, &tisFiles);
  243. }
  244. return g_htiFiles;
  245. }
  246. HTREEITEM __GetRootSetting (HWND hwndTree)
  247. {
  248. TV_INSERTSTRUCT tisSettings;
  249. TCHAR szPickSettings[MAX_LOADSTRING];
  250. if (!g_htiSettings) {
  251. tisSettings.hParent = NULL;
  252. tisSettings.hInsertAfter = TVI_ROOT;
  253. tisSettings.item.mask = TVIF_TEXT | TVIF_STATE;
  254. tisSettings.item.state = TVIS_EXPANDED;
  255. tisSettings.item.stateMask = TVIS_EXPANDED;
  256. LoadString(g_migwiz->GetInstance(), IDS_PICKSETTINGS, szPickSettings, ARRAYSIZE(szPickSettings));
  257. tisSettings.item.pszText = szPickSettings;
  258. g_htiSettings = TreeView_InsertItem(hwndTree, &tisSettings);
  259. }
  260. return g_htiSettings;
  261. }
  262. HRESULT _AddType (HWND hwndTree, LPCTSTR lpszFileType, LPCTSTR lpszFileTypePretty)
  263. {
  264. HRESULT hr = E_OUTOFMEMORY;
  265. TCHAR tszCombine[2000];
  266. if (_tcslen(lpszFileType) + _tcslen(lpszFileTypePretty) + 6 >= 2000) {
  267. return E_FAIL;
  268. }
  269. // ISSUE: potential for overflow, but wnsprintf doesn't work on downlevel. Ideas?
  270. lstrcpy(tszCombine, TEXT("*."));
  271. lstrcat(tszCombine, lpszFileType);
  272. if (lpszFileTypePretty && *lpszFileTypePretty)
  273. {
  274. lstrcat(tszCombine, TEXT(" - "));
  275. lstrcat(tszCombine, lpszFileTypePretty);
  276. }
  277. TV_INSERTSTRUCT tis = {0};
  278. tis.hParent = __GetRootType(hwndTree);
  279. tis.hInsertAfter = TVI_SORT;
  280. tis.item.mask = TVIF_TEXT | TVIF_PARAM;
  281. tis.item.pszText = tszCombine;
  282. tis.item.lParam = (LPARAM)LocalAlloc(LPTR, sizeof(LV_DATASTRUCT));
  283. if (tis.item.lParam)
  284. {
  285. ((LV_DATASTRUCT*)tis.item.lParam)->fOverwrite = FALSE;
  286. ((LV_DATASTRUCT*)tis.item.lParam)->pszPureName = StrDup(lpszFileType);
  287. if (!((LV_DATASTRUCT*)tis.item.lParam)->pszPureName)
  288. {
  289. LocalFree((HLOCAL)tis.item.lParam);
  290. }
  291. else
  292. {
  293. //
  294. // Add the component to the engine and tree control, unless it already exists
  295. //
  296. // Check if it is already in the tree
  297. if (!IsmIsComponentSelected (lpszFileType, COMPONENT_EXTENSION)) {
  298. // Not in the tree; select it if it exists as a component
  299. if (!IsmSelectComponent (lpszFileType, COMPONENT_EXTENSION, TRUE)) {
  300. // Not a component; add the component
  301. IsmAddComponentAlias (
  302. NULL,
  303. MASTERGROUP_FILES_AND_FOLDERS,
  304. lpszFileType,
  305. COMPONENT_EXTENSION,
  306. TRUE
  307. );
  308. }
  309. TreeView_InsertItem(hwndTree, &tis);
  310. // if the user hits BACK we will remember that the user customized stuff
  311. g_fCustomizeComp = TRUE;
  312. }
  313. hr = S_OK;
  314. }
  315. }
  316. return hr;
  317. }
  318. VOID
  319. CopyStorePath(LPTSTR pszIn, LPTSTR pszOut)
  320. {
  321. TCHAR *ptsLastSpace = NULL;
  322. *pszOut = '\0';
  323. if( ! pszIn )
  324. return;
  325. //
  326. // Step 1: Skip over leading white space
  327. //
  328. while( *pszIn && _istspace(*pszIn) )
  329. pszIn = _tcsinc(pszIn);
  330. //
  331. // Step 2: Copy the string, stripping out quotes and keeping
  332. // track of the last space after valid text in order
  333. // to strip out trailing space.
  334. //
  335. while( *pszIn )
  336. {
  337. if( _tcsnextc(pszIn) == '\"' )
  338. {
  339. pszIn = _tcsinc(pszIn);
  340. continue;
  341. }
  342. if( _istspace(*pszIn) )
  343. {
  344. if( ! ptsLastSpace )
  345. {
  346. ptsLastSpace = pszOut;
  347. }
  348. }
  349. else
  350. {
  351. ptsLastSpace = NULL;
  352. }
  353. #ifdef UNICODE
  354. *pszOut++ = *pszIn++;
  355. #else
  356. if( isleadbyte(*pszIn) )
  357. {
  358. *pszOut++ = *pszIn++;
  359. }
  360. *pszOut++ = *pszIn++;
  361. #endif
  362. }
  363. //
  364. // Step 3: Terminate the output string correctly
  365. //
  366. if( ptsLastSpace )
  367. {
  368. *ptsLastSpace = '\0';
  369. }
  370. else
  371. {
  372. *pszOut = '\0';
  373. }
  374. return;
  375. }
  376. BOOL _IsNetworkPath(LPTSTR pszPath)
  377. {
  378. TCHAR tszDriveName[4] = TEXT("?:\\");
  379. tszDriveName[0] = pszPath[0];
  380. return ((pszPath[0] == '\\' && pszPath[1] == '\\') || DRIVE_REMOTE == GetDriveType(tszDriveName));
  381. }
  382. int CALLBACK
  383. AddFolderCallback (
  384. HWND hwnd,
  385. UINT uMsg,
  386. LPARAM lParam,
  387. LPARAM lpData
  388. )
  389. {
  390. HRESULT hr = S_OK;
  391. TCHAR tszFolderName[MAX_PATH];
  392. IMalloc *mallocFn = NULL;
  393. IShellFolder *psfParent = NULL;
  394. IShellLink *pslLink = NULL;
  395. LPCITEMIDLIST pidl;
  396. LPCITEMIDLIST pidlRelative = NULL;
  397. LPITEMIDLIST pidlReal = NULL;
  398. if (uMsg == BFFM_SELCHANGED) {
  399. hr = SHGetMalloc (&mallocFn);
  400. if (!SUCCEEDED (hr)) {
  401. mallocFn = NULL;
  402. }
  403. pidl = (LPCITEMIDLIST) lParam;
  404. pidlReal = NULL;
  405. if (pidl) {
  406. hr = OurSHBindToParent (pidl, IID_IShellFolder, (void **)&psfParent, &pidlRelative);
  407. if (SUCCEEDED(hr)) {
  408. hr = psfParent->GetUIObjectOf (hwnd, 1, &pidlRelative, IID_IShellLink, NULL, (void **)&pslLink);
  409. if (SUCCEEDED(hr)) {
  410. hr = pslLink->GetIDList (&pidlReal);
  411. if (!SUCCEEDED(hr)) {
  412. pidlReal = NULL;
  413. }
  414. pslLink->Release ();
  415. }
  416. pidlRelative = NULL;
  417. psfParent->Release ();
  418. }
  419. if (SHGetPathFromIDList(pidlReal?pidlReal:pidl, tszFolderName) == TRUE)
  420. {
  421. if ((tszFolderName[0] == 0) ||
  422. (_IsNetworkPath(tszFolderName))
  423. ) {
  424. SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
  425. }
  426. } else {
  427. SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
  428. }
  429. if (pidlReal) {
  430. if (mallocFn) {
  431. mallocFn->Free ((void *)pidlReal);
  432. }
  433. pidlReal = NULL;
  434. }
  435. }
  436. if (mallocFn) {
  437. mallocFn->Release ();
  438. mallocFn = NULL;
  439. }
  440. }
  441. return 0;
  442. }
  443. HRESULT _AddFolder (HWND hwndDlg, HWND hwndTree)
  444. {
  445. HRESULT hr = S_OK;
  446. TCHAR tszFolderName[MAX_PATH];
  447. IMalloc *mallocFn = NULL;
  448. IShellFolder *psfParent = NULL;
  449. IShellLink *pslLink = NULL;
  450. LPCITEMIDLIST pidl;
  451. LPCITEMIDLIST pidlRelative = NULL;
  452. LPITEMIDLIST pidlReal = NULL;
  453. TCHAR szPick[MAX_LOADSTRING];
  454. hr = SHGetMalloc (&mallocFn);
  455. if (!SUCCEEDED (hr)) {
  456. mallocFn = NULL;
  457. }
  458. LoadString(g_migwiz->GetInstance(), IDS_ADDAFOLDER, szPick, ARRAYSIZE(szPick));
  459. BROWSEINFO brwsinf = { hwndDlg, NULL, NULL, szPick, BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE, AddFolderCallback, 0, 0 };
  460. // loop until we get pidl or cancel cancels
  461. BOOL fDone = FALSE;
  462. while (!fDone)
  463. {
  464. pidl = SHBrowseForFolder(&brwsinf);
  465. if (pidl)
  466. {
  467. hr = OurSHBindToParent (pidl, IID_IShellFolder, (void **)&psfParent, &pidlRelative);
  468. if (SUCCEEDED(hr)) {
  469. hr = psfParent->GetUIObjectOf (hwndDlg, 1, &pidlRelative, IID_IShellLink, NULL, (void **)&pslLink);
  470. if (SUCCEEDED(hr)) {
  471. hr = pslLink->GetIDList (&pidlReal);
  472. if (SUCCEEDED(hr)) {
  473. if (mallocFn) {
  474. mallocFn->Free ((void *)pidl);
  475. }
  476. pidl = pidlReal;
  477. pidlReal = NULL;
  478. }
  479. pslLink->Release ();
  480. }
  481. pidlRelative = NULL;
  482. psfParent->Release ();
  483. }
  484. if (SHGetPathFromIDList(pidl, tszFolderName))
  485. {
  486. fDone = TRUE; // user chose a valid folder
  487. }
  488. }
  489. else
  490. {
  491. fDone = TRUE; // user cancelled
  492. }
  493. }
  494. if (pidl)
  495. {
  496. TCHAR tszPrettyFolderName[MAX_PATH];
  497. hr = _GetPrettyFolderName (
  498. g_migwiz->GetInstance(),
  499. g_migwiz->GetWinNT4(),
  500. tszFolderName,
  501. tszPrettyFolderName,
  502. ARRAYSIZE(tszPrettyFolderName)
  503. );
  504. if (SUCCEEDED(hr))
  505. {
  506. hr = E_OUTOFMEMORY;
  507. SHFILEINFO sfi = {0};
  508. SHGetFileInfo((PCTSTR) (pidlReal?pidlReal:pidl), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_PIDL);
  509. TV_INSERTSTRUCT tis = {0};
  510. tis.hParent = __GetRootFolder (hwndTree);
  511. tis.hInsertAfter = TVI_SORT;
  512. tis.item.mask = TVIF_TEXT | TVIF_PARAM;
  513. tis.item.pszText = tszPrettyFolderName;
  514. tis.item.lParam = (LPARAM)LocalAlloc(LPTR, sizeof(LV_DATASTRUCT));
  515. if (tis.item.lParam)
  516. {
  517. ((LV_DATASTRUCT*)tis.item.lParam)->fOverwrite = FALSE;
  518. ((LV_DATASTRUCT*)tis.item.lParam)->pszPureName = StrDup(tszFolderName);
  519. if (!((LV_DATASTRUCT*)tis.item.lParam)->pszPureName)
  520. {
  521. LocalFree((HLOCAL)tis.item.lParam);
  522. }
  523. else
  524. {
  525. //
  526. // Add the component to the engine and tree control, unless it already exists
  527. //
  528. // Check if it is already in the tree
  529. if (!IsmIsComponentSelected (tszFolderName, COMPONENT_FOLDER)) {
  530. // Not in the tree; select it if it exists as a component
  531. if (!IsmSelectComponent (tszFolderName, COMPONENT_FOLDER, TRUE)) {
  532. // Not a component; add the component
  533. IsmAddComponentAlias (
  534. NULL,
  535. MASTERGROUP_FILES_AND_FOLDERS,
  536. tszFolderName,
  537. COMPONENT_FOLDER,
  538. TRUE
  539. );
  540. }
  541. TreeView_InsertItem(hwndTree, &tis);
  542. // if the user hits BACK we will remember that the user customized stuff
  543. g_fCustomizeComp = TRUE;
  544. }
  545. hr = S_OK;
  546. }
  547. }
  548. }
  549. if (mallocFn) {
  550. mallocFn->Free ((void *)pidl);
  551. }
  552. pidl = NULL;
  553. }
  554. if (mallocFn) {
  555. mallocFn->Release ();
  556. mallocFn = NULL;
  557. }
  558. return hr;
  559. }
  560. HRESULT _AddSetting (HWND hwndTree, LPTSTR lpszSetting)
  561. {
  562. HRESULT hr = E_OUTOFMEMORY;
  563. TV_INSERTSTRUCT tis = {0};
  564. tis.hParent = __GetRootSetting(hwndTree);
  565. tis.hInsertAfter = TVI_SORT;
  566. tis.item.mask = TVIF_TEXT | TVIF_PARAM;
  567. tis.item.pszText = lpszSetting;
  568. tis.item.lParam = (LPARAM)LocalAlloc(LPTR, sizeof(LV_DATASTRUCT));
  569. if (tis.item.lParam)
  570. {
  571. ((LV_DATASTRUCT*)tis.item.lParam)->pszPureName = NULL;
  572. ((LV_DATASTRUCT*)tis.item.lParam)->fOverwrite = FALSE;
  573. //
  574. // Add the component to the engine and tree control, unless it already exists
  575. //
  576. // Check if it is already in the tree
  577. if (!IsmIsComponentSelected (lpszSetting, COMPONENT_NAME)) {
  578. // Not in the tree; select it if it exists as a component
  579. if (!IsmSelectComponent (lpszSetting, COMPONENT_NAME, TRUE)) {
  580. // Not a component; add the component
  581. IsmAddComponentAlias (
  582. NULL,
  583. MASTERGROUP_FILES_AND_FOLDERS,
  584. lpszSetting,
  585. COMPONENT_NAME,
  586. TRUE
  587. );
  588. }
  589. TreeView_InsertItem(hwndTree, &tis);
  590. // if the user hits BACK we will remember that the user customized stuff
  591. g_fCustomizeComp = TRUE;
  592. }
  593. hr = S_OK;
  594. }
  595. return hr;
  596. }
  597. HRESULT _AddFile (HWND hwndDlg, HWND hwndTree)
  598. {
  599. TCHAR szCurrDir[MAX_PATH] = TEXT("");
  600. TCHAR szPath[MAX_PATH];
  601. szPath[0] = TEXT('\0');
  602. TCHAR szPick[MAX_LOADSTRING];
  603. TCHAR szAll[MAX_LOADSTRING + 6];
  604. HRESULT hr = S_OK;
  605. BOOL fDone = FALSE;
  606. BOOL fGotFile = FALSE;
  607. PTSTR mydocsDir = NULL;
  608. PTSTR lpstrFilter;
  609. DWORD dwLength;
  610. LoadString(g_migwiz->GetInstance(), IDS_PICKAFILE, szPick, ARRAYSIZE(szPick));
  611. dwLength = LoadString(g_migwiz->GetInstance(), IDS_OPENFILEFILTER_ALL, szAll, MAX_LOADSTRING);
  612. memcpy (szAll + dwLength, TEXT("\0*.*\0\0"), 6 * sizeof (TCHAR));
  613. OPENFILENAME of = {
  614. g_migwiz->GetLegacy() ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME), // DWORD lStructSize;
  615. hwndDlg, // HWND hwndOwner;
  616. NULL, // HINSTANCE hInstance;
  617. szAll, // LPCTSTR lpstrFilter;
  618. NULL, // LPTSTR lpstrCustomFilter;
  619. NULL, // DWORD nMaxCustFilter;
  620. 1, // DWORD nFilterIndex;
  621. szPath, // LPTSTR lpstrFile;
  622. MAX_PATH, // DWORD nMaxFile;
  623. NULL, // LPTSTR lpstrFileTitle;
  624. NULL, // DWORD nMaxFileTitle;
  625. NULL, // LPCTSTR lpstrInitialDir;
  626. szPick, // LPCTSTR lpstrTitle;
  627. OFN_NODEREFERENCELINKS | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_HIDEREADONLY, // DWORD Flags;
  628. 0, // WORD nFileOffset;
  629. 0, // WORD nFileExtension;
  630. NULL, // LPCTSTR lpstrDefExt;
  631. NULL, // LPARAM lCustData;
  632. NULL, // LPOFNHOOKPROC lpfnHook;
  633. NULL, // LPCTSTR lpTemplateName;
  634. };
  635. while (!fDone)
  636. {
  637. // we need to set the current directory to be in "My Documents" for this dialog
  638. // to work properly. If we don't the dialog will open in the current directory
  639. // which is the temp dir where we copied the wizard.
  640. if (GetCurrentDirectory(ARRAYSIZE(szCurrDir), szCurrDir)) {
  641. mydocsDir = GetShellFolderPath (CSIDL_MYDOCUMENTS, TEXT("My Documents"), TRUE, NULL);
  642. if (!mydocsDir) {
  643. mydocsDir = GetShellFolderPath (CSIDL_PERSONAL, TEXT("Personal"), TRUE, NULL);
  644. }
  645. if (mydocsDir) {
  646. SetCurrentDirectory (mydocsDir);
  647. LocalFree (mydocsDir);
  648. }
  649. }
  650. fGotFile = GetOpenFileName(&of);
  651. if (szCurrDir [0]) {
  652. SetCurrentDirectory (szCurrDir);
  653. }
  654. if (!fGotFile)
  655. {
  656. fDone = TRUE;
  657. }
  658. else
  659. {
  660. if (_IsNetworkPath(szPath))
  661. {
  662. // if LoadStrings fail, we default to english
  663. TCHAR szNoNetworkMsg[MAX_LOADSTRING];
  664. TCHAR szNoNetworkCaption[MAX_LOADSTRING] = TEXT("Files and Settings Transfer Wizard");
  665. if (!LoadString(g_migwiz->GetInstance(), IDS_NONETWORK, szNoNetworkMsg, ARRAYSIZE(szPick)))
  666. {
  667. StrCpyN(szNoNetworkMsg, TEXT("Network files and folders cannot be transferred. Please choose again."), ARRAYSIZE(szNoNetworkMsg));
  668. }
  669. if (!LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szNoNetworkCaption, ARRAYSIZE(szPick)))
  670. {
  671. StrCpyN(szNoNetworkCaption, TEXT("Files and Settings Transfer Wizard"), ARRAYSIZE(szNoNetworkMsg));
  672. }
  673. _ExclusiveMessageBox(hwndDlg, szNoNetworkMsg, szNoNetworkCaption, MB_OK);
  674. }
  675. else
  676. {
  677. fDone = TRUE; // user chose a non-network folder
  678. }
  679. }
  680. }
  681. if (fGotFile)
  682. {
  683. hr = E_OUTOFMEMORY;
  684. TV_INSERTSTRUCT tis = {0};
  685. tis.hParent = __GetRootFile (hwndTree);
  686. tis.hInsertAfter = TVI_SORT;
  687. tis.item.mask = TVIF_TEXT | TVIF_PARAM;
  688. tis.item.pszText = szPath;
  689. tis.item.lParam = (LPARAM)LocalAlloc(LPTR, sizeof(LV_DATASTRUCT));
  690. if (tis.item.lParam)
  691. {
  692. ((LV_DATASTRUCT*)tis.item.lParam)->pszPureName = NULL;
  693. ((LV_DATASTRUCT*)tis.item.lParam)->fOverwrite = FALSE;
  694. //
  695. // Add the component to the engine and tree control, unless it already exists
  696. //
  697. // Check if it is already in the tree
  698. if (!IsmIsComponentSelected (szPath, COMPONENT_FILE)) {
  699. // Not in the tree; select it if it exists as a component
  700. if (!IsmSelectComponent (szPath, COMPONENT_FILE, TRUE)) {
  701. // Not a component; add the component
  702. IsmAddComponentAlias (
  703. NULL,
  704. MASTERGROUP_FILES_AND_FOLDERS,
  705. szPath,
  706. COMPONENT_FILE,
  707. TRUE
  708. );
  709. }
  710. TreeView_InsertItem(hwndTree, &tis);
  711. // if the user hits BACK we will remember that the user customized stuff
  712. g_fCustomizeComp = TRUE;
  713. }
  714. hr = S_OK;
  715. }
  716. }
  717. return hr;
  718. }
  719. ///////////////////////////////////////////////////////////////
  720. INT_PTR CALLBACK _FileTypeDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  721. {
  722. static bool fDoneInit;
  723. static HWND hwndParent;
  724. switch (uMsg)
  725. {
  726. case WM_NOTIFY :
  727. switch (((LPNMHDR)lParam)->code)
  728. {
  729. case NM_DBLCLK:
  730. // On this dialog, this message can only come from the listview.
  731. // If there is something selected, that means the user doubleclicked on an item
  732. // On a doubleclick we will trigger the OK button
  733. if (ListView_GetSelectedCount(GetDlgItem(hwndDlg, IDC_FILETYPE_LIST)) > 0)
  734. {
  735. SendMessage (GetDlgItem(hwndDlg, IDOK), BM_CLICK, 0, 0);
  736. }
  737. break;
  738. case LVN_ITEMCHANGED:
  739. {
  740. if (fDoneInit) // ignore messages during WM_INITDIALOG
  741. {
  742. if (ListView_GetSelectedCount(GetDlgItem(hwndDlg, IDC_FILETYPE_LIST)) > 0)
  743. {
  744. Button_Enable(GetDlgItem(hwndDlg, IDOK), TRUE);
  745. }
  746. else
  747. {
  748. Button_Enable(GetDlgItem(hwndDlg, IDOK), FALSE);
  749. }
  750. }
  751. }
  752. break;
  753. }
  754. break;
  755. case WM_INITDIALOG :
  756. {
  757. fDoneInit = FALSE;
  758. hwndParent = (HWND)lParam;
  759. HWND hwndList = GetDlgItem(hwndDlg, IDC_FILETYPE_LIST);
  760. ListView_DeleteAllItems(hwndList);
  761. Button_Enable(GetDlgItem(hwndDlg, IDOK), FALSE);
  762. LVCOLUMN lvcolumn;
  763. lvcolumn.mask = LVCF_TEXT | LVCF_WIDTH;
  764. lvcolumn.cx = 75;
  765. TCHAR szColumn[MAX_LOADSTRING];
  766. LoadString(g_migwiz->GetInstance(), IDS_COLS_EXTENSIONS, szColumn, ARRAYSIZE(szColumn));
  767. lvcolumn.pszText = szColumn;
  768. ListView_InsertColumn(hwndList, 0, &lvcolumn);
  769. lvcolumn.cx = 235;
  770. LoadString(g_migwiz->GetInstance(), IDS_COLS_FILETYPES, szColumn, ARRAYSIZE(szColumn));
  771. lvcolumn.pszText = szColumn;
  772. ListView_InsertColumn(hwndList, 1, &lvcolumn);
  773. DWORD dwRetVal = ERROR_SUCCESS;
  774. UINT i = 0;
  775. BOOL fImageListSet = FALSE;
  776. // 1. insert all the extensions
  777. while (ERROR_SUCCESS == dwRetVal)
  778. {
  779. TCHAR szKeyName[MAX_PATH];
  780. DWORD cchKeyName = ARRAYSIZE(szKeyName);
  781. dwRetVal = RegEnumKeyEx(HKEY_CLASSES_ROOT, i++, szKeyName, &cchKeyName,
  782. NULL, NULL, NULL, NULL);
  783. if (dwRetVal == ERROR_SUCCESS && cchKeyName > 0)
  784. {
  785. if (szKeyName[0] == TEXT('.'))// &&
  786. //!IsmIsComponentSelected(szKeyName + 1, COMPONENT_EXTENSION))
  787. {
  788. INFCONTEXT context;
  789. // read the screened extensions from MIGWIZ.INF and
  790. // don't add it if it's there
  791. if (!SetupFindFirstLine (g_hMigWizInf, TEXT("Screened Extensions"), szKeyName+1, &context)) {
  792. _ListView_InsertItem(hwndList, szKeyName+1);
  793. }
  794. }
  795. }
  796. }
  797. // 2. remove all the extensions already in the engine
  798. MIG_COMPONENT_ENUM mce;
  799. int iFoundItem;
  800. LVFINDINFO findinfo;
  801. findinfo.flags = LVFI_STRING;
  802. findinfo.vkDirection = VK_DOWN;
  803. if (IsmEnumFirstComponent (&mce, COMPONENTENUM_ALIASES|COMPONENTENUM_ENABLED, COMPONENT_EXTENSION))
  804. {
  805. do
  806. {
  807. findinfo.psz = mce.LocalizedAlias;
  808. iFoundItem = ListView_FindItem(hwndList, -1, &findinfo);
  809. if (-1 != iFoundItem)
  810. {
  811. ListView_DeleteItem(hwndList, iFoundItem);
  812. }
  813. mce.SkipToNextComponent = TRUE;
  814. } while (IsmEnumNextComponent (&mce));
  815. }
  816. // 3. add the extensions in the engine, but removed, yet not in the registry
  817. if (IsmEnumFirstComponent (&mce, COMPONENTENUM_ALIASES|COMPONENTENUM_DISABLED, COMPONENT_EXTENSION))
  818. {
  819. do
  820. {
  821. findinfo.psz = mce.LocalizedAlias;
  822. iFoundItem = ListView_FindItem(hwndList, -1, &findinfo);
  823. if (-1 == iFoundItem)
  824. {
  825. _ListView_InsertItem(hwndList, (LPTSTR)mce.LocalizedAlias);
  826. }
  827. mce.SkipToNextComponent = TRUE;
  828. } while (IsmEnumNextComponent (&mce));
  829. }
  830. // 3. add in the *. and the pretty names
  831. TCHAR szName[MAX_PATH];
  832. TCHAR szPrettyName[MAX_PATH];
  833. LVITEM lvitem = {0};
  834. lvitem.mask = LVIF_TEXT;
  835. lvitem.pszText = szName;
  836. lvitem.cchTextMax = ARRAYSIZE(szName);
  837. int cListView = ListView_GetItemCount(hwndList);
  838. for (int j = 0; j < cListView; j++)
  839. {
  840. lvitem.iItem = j;
  841. ListView_GetItem(hwndList, &lvitem);
  842. memmove(szName + 2, szName, sizeof(szName) - (2 * sizeof(TCHAR)));
  843. szName[0] = '*';
  844. szName[1] = '.';
  845. ListView_SetItemText(hwndList, j, 0, szName);
  846. if (SUCCEEDED(_GetPrettyTypeName(szName, szPrettyName, ARRAYSIZE(szPrettyName))))
  847. {
  848. ListView_SetItemText(hwndList, j, 1, szPrettyName);
  849. }
  850. }
  851. ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT);
  852. Edit_LimitText(GetDlgItem(hwndDlg, IDC_FILETYPEEDIT), MAX_PATH - 4);
  853. fDoneInit = TRUE;
  854. }
  855. return TRUE;
  856. break;
  857. case WM_COMMAND:
  858. if (HIWORD(wParam) == EN_CHANGE)
  859. {
  860. Button_Enable(GetDlgItem(hwndDlg, IDOK), TRUE);
  861. break;
  862. }
  863. switch (LOWORD(wParam))
  864. {
  865. case IDOK:
  866. {
  867. HWND hwndTree = GetDlgItem(hwndParent, IDC_CUSTOMIZE_TREE);
  868. HWND hwndList = GetDlgItem(hwndDlg, IDC_FILETYPE_LIST);
  869. UINT cSelCount = ListView_GetSelectedCount(hwndList);
  870. INT iIndex = -1;
  871. TCHAR szFileType[MAX_PATH];
  872. TCHAR szFileTypePretty[MAX_PATH];
  873. for (UINT x=0; x < cSelCount; x++)
  874. {
  875. iIndex = ListView_GetNextItem(hwndList, iIndex, LVNI_SELECTED);
  876. if (iIndex == -1)
  877. {
  878. break;
  879. }
  880. // add "doc", not "*.doc"
  881. ListView_GetItemText(hwndList, iIndex, 0, szFileType, ARRAYSIZE(szFileType));
  882. memmove(szFileType, szFileType + 2, sizeof(szFileType) - (2 * sizeof(TCHAR)));
  883. ListView_GetItemText(hwndList, iIndex, 1, szFileTypePretty, ARRAYSIZE(szFileTypePretty));
  884. _AddType(hwndTree, szFileType, szFileTypePretty);
  885. }
  886. // Now check the edit box
  887. SendMessage(GetDlgItem(hwndDlg, IDC_FILETYPEEDIT), WM_GETTEXT,
  888. (WPARAM)ARRAYSIZE(szFileType), (LPARAM)szFileType);
  889. if (*szFileType)
  890. {
  891. szFileTypePretty [0] = 0;
  892. _RemoveSpaces (szFileType, ARRAYSIZE (szFileType));
  893. _GetPrettyTypeName(szFileType, szFileTypePretty, ARRAYSIZE(szFileTypePretty));
  894. if (szFileType[0] == TEXT('*') && szFileType[1] == TEXT('.'))
  895. {
  896. _AddType(hwndTree, szFileType + 2, szFileTypePretty);
  897. }
  898. else
  899. {
  900. _AddType(hwndTree, szFileType, szFileTypePretty);
  901. }
  902. }
  903. EndDialog(hwndDlg, 1);
  904. return TRUE;
  905. }
  906. break;
  907. case IDCANCEL:
  908. EndDialog(hwndDlg, 0);
  909. return TRUE;
  910. break;
  911. }
  912. break;
  913. }
  914. return FALSE;
  915. }
  916. ///////////////////////////////////////////////////////////////
  917. INT_PTR CALLBACK _SettingDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  918. {
  919. static HWND hwndParent;
  920. switch (uMsg)
  921. {
  922. case WM_NOTIFY :
  923. switch (((LPNMHDR)lParam)->code)
  924. {
  925. case NM_DBLCLK:
  926. // On this dialog, this message can only come from the listview.
  927. // If there is something selected, that means the user doubleclicked on an item
  928. // On a doubleclick we will trigger the OK button
  929. if (ListView_GetSelectedCount(GetDlgItem(hwndDlg, IDC_SETTINGPICKER_LIST)) > 0)
  930. {
  931. SendMessage (GetDlgItem(hwndDlg, IDOK), BM_CLICK, 0, 0);
  932. }
  933. break;
  934. case LVN_ITEMCHANGED:
  935. if (ListView_GetSelectedCount(GetDlgItem(hwndDlg, IDC_SETTINGPICKER_LIST)) > 0)
  936. {
  937. Button_Enable(GetDlgItem(hwndDlg, IDOK), TRUE);
  938. }
  939. else
  940. {
  941. Button_Enable(GetDlgItem(hwndDlg, IDOK), FALSE);
  942. }
  943. break;
  944. }
  945. break;
  946. case WM_INITDIALOG :
  947. {
  948. BOOL fListEmpty = TRUE;
  949. hwndParent = (HWND)lParam;
  950. HWND hwndList = GetDlgItem(hwndDlg, IDC_SETTINGPICKER_LIST);
  951. ListView_DeleteAllItems(hwndList);
  952. LVCOLUMN lvcolumn;
  953. lvcolumn.mask = LVCF_WIDTH;
  954. lvcolumn.cx = 250; // BUGBUG: should read width from box
  955. ListView_InsertColumn(hwndList, 0, &lvcolumn);
  956. Button_Enable(GetDlgItem(hwndDlg, IDOK), FALSE);
  957. MIG_COMPONENT_ENUM mce;
  958. if (IsmEnumFirstComponent (&mce, COMPONENTENUM_ALIASES | COMPONENTENUM_DISABLED |
  959. COMPONENTENUM_PREFERRED_ONLY, COMPONENT_NAME))
  960. {
  961. do
  962. {
  963. if (MASTERGROUP_SYSTEM == mce.MasterGroup || MASTERGROUP_APP == mce.MasterGroup)
  964. {
  965. _ListView_InsertItem(hwndList, (PTSTR) mce.LocalizedAlias);
  966. fListEmpty = FALSE;
  967. }
  968. }
  969. while (IsmEnumNextComponent (&mce));
  970. }
  971. if (fListEmpty) {
  972. TCHAR szNothingToAdd[MAX_LOADSTRING];
  973. LoadString(g_migwiz->GetInstance(), IDS_NOMORE_SETTINGS, szNothingToAdd, ARRAYSIZE(szNothingToAdd));
  974. _ListView_InsertItem(hwndList, szNothingToAdd);
  975. EnableWindow (hwndList, FALSE);
  976. }
  977. }
  978. return TRUE;
  979. break;
  980. case WM_COMMAND:
  981. switch (LOWORD(wParam))
  982. {
  983. case IDOK:
  984. {
  985. HWND hwndTree = GetDlgItem(hwndParent, IDC_CUSTOMIZE_TREE);
  986. HWND hwndList = GetDlgItem(hwndDlg, IDC_SETTINGPICKER_LIST);
  987. TCHAR szSetting[MAX_PATH];
  988. INT iIndex = -1;
  989. UINT cSelCount = ListView_GetSelectedCount(hwndList);
  990. for (UINT x=0; x < cSelCount; x++)
  991. {
  992. iIndex = ListView_GetNextItem(hwndList, iIndex, LVNI_SELECTED);
  993. if (iIndex == -1)
  994. {
  995. break;
  996. }
  997. ListView_GetItemText(hwndList, iIndex, 0, szSetting, ARRAYSIZE(szSetting));
  998. _AddSetting(hwndTree, szSetting);
  999. }
  1000. EndDialog(hwndDlg, TRUE);
  1001. return TRUE;
  1002. }
  1003. break;
  1004. case IDCANCEL:
  1005. EndDialog(hwndDlg, FALSE);
  1006. return TRUE;
  1007. break;
  1008. }
  1009. break;
  1010. }
  1011. return 0;
  1012. }
  1013. ///////////////////////////////////////////////////////////////
  1014. VOID _SetIcons (HWND hwnd)
  1015. {
  1016. HICON hIcon;
  1017. HINSTANCE hInstance = g_migwiz->GetInstance();
  1018. if (!hwnd || !hInstance)
  1019. {
  1020. return;
  1021. }
  1022. hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (2000));
  1023. if (hIcon) {
  1024. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
  1025. SendMessage (hwnd, WM_SETICON, ICON_SMALL, NULL);
  1026. }
  1027. SetWindowLong (hwnd, GWL_STYLE, WS_BORDER | WS_CAPTION);
  1028. RedrawWindow (hwnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT | RDW_ERASE);
  1029. }
  1030. VOID _SetPageHandles (HWND hwndPage)
  1031. {
  1032. g_hwndDlg = hwndPage;
  1033. g_hwndWizard = g_hwndDlg ? GetParent (hwndPage) : NULL;
  1034. }
  1035. VOID _NextWizardPage (HWND hwndCurrentPage)
  1036. {
  1037. //
  1038. // We only want to advance the page in the UI thread context
  1039. //
  1040. if (!g_NextPressed && g_hwndWizard) {
  1041. if (PropSheet_GetCurrentPageHwnd (g_hwndWizard) == hwndCurrentPage) {
  1042. PropSheet_PressButton(g_hwndWizard, PSBTN_NEXT);
  1043. g_NextPressed = TRUE;
  1044. }
  1045. }
  1046. }
  1047. VOID _PrevWizardPage (VOID)
  1048. {
  1049. //
  1050. // We only want to advance the page in the UI thread context
  1051. //
  1052. if (g_hwndWizard) {
  1053. PropSheet_PressButton(g_hwndWizard, PSBTN_BACK);
  1054. }
  1055. }
  1056. INT_PTR CALLBACK _RootDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, DWORD dwEnabled, BOOL fTitle, UINT uiTitleID)
  1057. {
  1058. switch (uMsg)
  1059. {
  1060. case WM_INITDIALOG :
  1061. {
  1062. g_migwiz = (MigrationWizard*) ((LPPROPSHEETPAGE) lParam) -> lParam;
  1063. if (fTitle)
  1064. {
  1065. HWND hwndControl = GetDlgItem(hwndDlg, uiTitleID);
  1066. SetWindowFont(hwndControl, g_migwiz->GetTitleFont(), TRUE);
  1067. }
  1068. break;
  1069. }
  1070. case WM_NOTIFY :
  1071. {
  1072. switch (((LPNMHDR)lParam)->code)
  1073. {
  1074. case PSN_SETACTIVE : //Enable the Back and/or Next button
  1075. g_hwndCurrent = hwndDlg;
  1076. g_NextPressed = FALSE;
  1077. PropSheet_SetWizButtons(GetParent(hwndDlg), dwEnabled);
  1078. _SetPageHandles (hwndDlg);
  1079. break;
  1080. default :
  1081. break;
  1082. }
  1083. }
  1084. break;
  1085. default:
  1086. break;
  1087. }
  1088. return 0;
  1089. }
  1090. ///////////////////////////////////////////////////////////////
  1091. VOID
  1092. pSetEvent (
  1093. IN HANDLE *Event
  1094. )
  1095. {
  1096. if (!*Event) {
  1097. *Event = CreateEvent (NULL, TRUE, TRUE, NULL);
  1098. } else {
  1099. SetEvent (*Event);
  1100. }
  1101. }
  1102. VOID
  1103. pResetEvent (
  1104. IN HANDLE *Event
  1105. )
  1106. {
  1107. if (!*Event) {
  1108. *Event = CreateEvent (NULL, TRUE, FALSE, NULL);
  1109. } else {
  1110. ResetEvent (*Event);
  1111. }
  1112. }
  1113. BOOL
  1114. pIsEventSet (
  1115. IN HANDLE *Event
  1116. )
  1117. {
  1118. DWORD result;
  1119. if (!*Event) {
  1120. *Event = CreateEvent (NULL, TRUE, TRUE, NULL);
  1121. return TRUE;
  1122. }
  1123. result = WaitForSingleObject (*Event, 0);
  1124. return (result == WAIT_OBJECT_0);
  1125. }
  1126. BOOL _HandleCancel (HWND hwndDlg, BOOL fStopNow, BOOL fConfirm)
  1127. {
  1128. if (fConfirm)
  1129. {
  1130. TCHAR szConfirm[MAX_LOADSTRING];
  1131. TCHAR szTitle[MAX_LOADSTRING];
  1132. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  1133. LoadString(g_migwiz->GetInstance(), IDS_CONFIRMCANCEL, szConfirm, ARRAYSIZE(szConfirm));
  1134. if (IDNO == _ExclusiveMessageBox(hwndDlg, szConfirm, szTitle, MB_YESNO | MB_DEFBUTTON2))
  1135. {
  1136. // Do not exit
  1137. SetWindowLong(hwndDlg, DWLP_MSGRESULT, TRUE);
  1138. return TRUE;
  1139. }
  1140. }
  1141. g_fUberCancel = TRUE;
  1142. g_fCancelPressed = TRUE;
  1143. Engine_Cancel();
  1144. if (fStopNow)
  1145. {
  1146. // Exit now
  1147. SetWindowLong(hwndDlg, DWLP_MSGRESULT, FALSE);
  1148. return FALSE;
  1149. }
  1150. SendMessage (g_hwndCurrent, WM_USER_CANCEL_PENDING, 0, (LPARAM) E_ABORT);
  1151. // Do not exit
  1152. SetWindowLong(hwndDlg, DWLP_MSGRESULT, TRUE);
  1153. return TRUE;
  1154. }
  1155. ///////////////////////////////////////////////////////////////
  1156. INT_PTR CALLBACK _IntroDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1157. {
  1158. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_NEXT, TRUE, IDC_INTRO_TITLE);
  1159. switch (uMsg)
  1160. {
  1161. case WM_NOTIFY:
  1162. switch (((LPNMHDR)lParam)->code)
  1163. {
  1164. case PSN_SETACTIVE:
  1165. {
  1166. static BOOL fInit = FALSE;
  1167. if (!fInit)
  1168. {
  1169. _SetIcons (g_hwndWizard);
  1170. fInit = TRUE;
  1171. }
  1172. break;
  1173. }
  1174. case PSN_QUERYCANCEL:
  1175. return _HandleCancel(hwndDlg, TRUE, FALSE);
  1176. break;
  1177. case PSN_WIZNEXT:
  1178. if (g_fUberCancel)
  1179. {
  1180. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ENDCOLLECTFAIL);
  1181. }
  1182. else
  1183. {
  1184. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_GETSTARTED);
  1185. }
  1186. return TRUE;
  1187. break;
  1188. }
  1189. case NM_CLICK:
  1190. if (wParam == IDC_INTRO_TEXT3) {
  1191. TCHAR szAppPath[MAX_PATH] = TEXT("");
  1192. LONG appPathSize;
  1193. TCHAR szHtmlPath[MAX_PATH] = TEXT("");
  1194. TCHAR szCmdLine[MAX_PATH * 3] = TEXT("");
  1195. BOOL bResult;
  1196. LONG lResult;
  1197. STARTUPINFO si;
  1198. PROCESS_INFORMATION pi;
  1199. PNMLINK nmLink = (PNMLINK) lParam;
  1200. if (_wcsicmp (nmLink->item.szID, L"StartHelp") == 0) {
  1201. if (GetWindowsDirectory (szHtmlPath, ARRAYSIZE(szHtmlPath))) {
  1202. // let's get the path to iexplore.exe
  1203. appPathSize = MAX_PATH;
  1204. lResult = RegQueryValue (
  1205. HKEY_LOCAL_MACHINE,
  1206. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE"),
  1207. szAppPath,
  1208. &appPathSize
  1209. );
  1210. if (lResult == ERROR_SUCCESS) {
  1211. _tcscat (szHtmlPath, TEXT("\\Help\\migwiz.htm"));
  1212. if (_tcsnextc (szAppPath) != TEXT('\"')) {
  1213. _tcscpy (szCmdLine, TEXT("\""));
  1214. _tcscat (szCmdLine, szAppPath);
  1215. _tcscat (szCmdLine, TEXT("\" "));
  1216. } else {
  1217. _tcscpy (szCmdLine, szAppPath);
  1218. _tcscat (szCmdLine, TEXT(" "));
  1219. }
  1220. _tcscat (szCmdLine, szHtmlPath);
  1221. ZeroMemory( &si, sizeof(STARTUPINFO) );
  1222. si.cb = sizeof(STARTUPINFO);
  1223. bResult = CreateProcess(
  1224. NULL,
  1225. szCmdLine,
  1226. NULL,
  1227. NULL,
  1228. FALSE,
  1229. 0,
  1230. NULL,
  1231. NULL,
  1232. &si,
  1233. &pi
  1234. );
  1235. if (bResult) {
  1236. CloseHandle (pi.hProcess);
  1237. CloseHandle (pi.hThread);
  1238. }
  1239. }
  1240. }
  1241. }
  1242. }
  1243. break;
  1244. break;
  1245. }
  1246. return 0;
  1247. }
  1248. ///////////////////////////////////////////////////////////////
  1249. INT_PTR CALLBACK _IntroLegacyDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1250. {
  1251. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_NEXT, TRUE, IDC_INTROLEGACY_TITLE);
  1252. switch (uMsg)
  1253. {
  1254. case WM_NOTIFY:
  1255. switch (((LPNMHDR)lParam)->code)
  1256. {
  1257. case PSN_SETACTIVE:
  1258. {
  1259. static BOOL fInit = FALSE;
  1260. g_fOldComputer = TRUE; // we are on the old machine
  1261. if (!fInit)
  1262. {
  1263. _SetIcons (g_hwndWizard);
  1264. fInit = TRUE;
  1265. }
  1266. break;
  1267. }
  1268. case PSN_QUERYCANCEL:
  1269. return _HandleCancel(hwndDlg, TRUE, FALSE);
  1270. break;
  1271. case PSN_WIZNEXT:
  1272. if (g_fUberCancel)
  1273. {
  1274. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ENDCOLLECTFAIL);
  1275. }
  1276. else
  1277. {
  1278. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_WAIT);
  1279. }
  1280. return TRUE;
  1281. break;
  1282. }
  1283. break;
  1284. }
  1285. return 0;
  1286. }
  1287. ///////////////////////////////////////////////////////////////
  1288. INT_PTR CALLBACK _IntroOOBEDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1289. {
  1290. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_NEXT, TRUE, IDC_INTROOOBE_TITLE);
  1291. switch (uMsg)
  1292. {
  1293. case WM_NOTIFY:
  1294. switch (((LPNMHDR)lParam)->code)
  1295. {
  1296. case PSN_SETACTIVE:
  1297. break;
  1298. case PSN_QUERYCANCEL:
  1299. return _HandleCancel(hwndDlg, TRUE, FALSE);
  1300. break;
  1301. case PSN_WIZNEXT:
  1302. if (g_fUberCancel)
  1303. {
  1304. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ENDCOLLECTFAIL);
  1305. }
  1306. else
  1307. {
  1308. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKMETHOD); // go on with prepare
  1309. }
  1310. return TRUE;
  1311. break;
  1312. }
  1313. break;
  1314. }
  1315. return 0;
  1316. }
  1317. ///////////////////////////////////////////////////////////////
  1318. VOID DisableCancel (VOID)
  1319. {
  1320. if (g_hwndWizard) {
  1321. SetFocus (GetDlgItem (g_hwndWizard, IDOK));
  1322. EnableWindow (GetDlgItem (g_hwndWizard, IDCANCEL), FALSE);
  1323. }
  1324. }
  1325. VOID EnableCancel (VOID)
  1326. {
  1327. if (g_hwndWizard) {
  1328. EnableWindow (GetDlgItem (g_hwndWizard, IDCANCEL), TRUE);
  1329. }
  1330. }
  1331. VOID PostMessageForWizard (
  1332. UINT Msg,
  1333. WPARAM wParam,
  1334. LPARAM lParam
  1335. )
  1336. {
  1337. if (g_hwndCurrent) {
  1338. PostMessage (g_hwndCurrent, Msg, wParam, lParam);
  1339. }
  1340. }
  1341. BOOL
  1342. pWriteStrResToFile (
  1343. IN HANDLE FileHandle,
  1344. IN DWORD StrId
  1345. )
  1346. {
  1347. TCHAR strFromRes[MAX_LOADSTRING] = TEXT("");
  1348. INT strLen = 0;
  1349. DWORD written;
  1350. strLen = LoadString (g_migwiz->GetInstance(), StrId, strFromRes, ARRAYSIZE(strFromRes));
  1351. if (strLen) {
  1352. WriteFile (FileHandle, strFromRes, (_tcslen (strFromRes) + 1) * sizeof (TCHAR), &written, NULL);
  1353. return TRUE;
  1354. }
  1355. return FALSE;
  1356. }
  1357. BOOL
  1358. pGenerateHTMLWarnings (
  1359. IN HANDLE FileHandle,
  1360. IN DWORD BeginId,
  1361. IN DWORD EndId,
  1362. IN DWORD AreaId,
  1363. IN DWORD InstrId,
  1364. IN DWORD WrnId,
  1365. IN DWORD WrnFileId1,
  1366. IN DWORD WrnFileId2,
  1367. IN DWORD WrnAltFileId1,
  1368. IN DWORD WrnAltFileId2,
  1369. IN DWORD WrnRasId1,
  1370. IN DWORD WrnRasId2,
  1371. IN DWORD WrnNetId1,
  1372. IN DWORD WrnNetId2,
  1373. IN DWORD WrnPrnId1,
  1374. IN DWORD WrnPrnId2,
  1375. IN DWORD WrnGeneralId1,
  1376. IN DWORD WrnGeneralId2
  1377. )
  1378. {
  1379. TCHAR szLoadStr[MAX_LOADSTRING];
  1380. DWORD objTypes = 0;
  1381. POBJLIST objList = NULL;
  1382. DWORD written;
  1383. #ifdef UNICODE
  1384. ((PBYTE)szLoadStr) [0] = 0xFF;
  1385. ((PBYTE)szLoadStr) [1] = 0xFE;
  1386. WriteFile (FileHandle, szLoadStr, 2, &written, NULL);
  1387. #endif
  1388. pWriteStrResToFile (FileHandle, BeginId);
  1389. if (AreaId) {
  1390. pWriteStrResToFile (FileHandle, AreaId);
  1391. if (InstrId) {
  1392. pWriteStrResToFile (FileHandle, InstrId);
  1393. }
  1394. }
  1395. // let's see if we have some object that could not be restored
  1396. objTypes = 0;
  1397. if (g_HTMLWrnFile) {
  1398. objTypes ++;
  1399. }
  1400. if (g_HTMLWrnAltFile) {
  1401. objTypes ++;
  1402. }
  1403. if (g_HTMLWrnRas) {
  1404. objTypes ++;
  1405. }
  1406. if (g_HTMLWrnNet) {
  1407. objTypes ++;
  1408. }
  1409. if (g_HTMLWrnPrn) {
  1410. objTypes ++;
  1411. }
  1412. if (g_HTMLWrnGeneral) {
  1413. objTypes ++;
  1414. }
  1415. if (objTypes) {
  1416. if (objTypes > 1) {
  1417. if (WrnId) {
  1418. pWriteStrResToFile (FileHandle, WrnId);
  1419. }
  1420. }
  1421. if (g_HTMLWrnFile) {
  1422. if (objTypes > 1) {
  1423. pWriteStrResToFile (FileHandle, WrnFileId1);
  1424. } else {
  1425. pWriteStrResToFile (FileHandle, WrnFileId2);
  1426. }
  1427. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  1428. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1429. objList = g_HTMLWrnFile;
  1430. while (objList) {
  1431. if (objList->ObjectName) {
  1432. _tcscpy (szLoadStr, TEXT("<LI>"));
  1433. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1434. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  1435. }
  1436. objList = objList->Next;
  1437. }
  1438. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  1439. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1440. }
  1441. if (g_HTMLWrnAltFile) {
  1442. if (objTypes > 1) {
  1443. pWriteStrResToFile (FileHandle, WrnAltFileId1);
  1444. } else {
  1445. pWriteStrResToFile (FileHandle, WrnAltFileId2);
  1446. }
  1447. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  1448. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1449. objList = g_HTMLWrnAltFile;
  1450. while (objList) {
  1451. if (objList->ObjectName) {
  1452. _tcscpy (szLoadStr, TEXT("<LI>"));
  1453. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1454. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  1455. }
  1456. objList = objList->Next;
  1457. }
  1458. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  1459. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1460. }
  1461. if (g_HTMLWrnRas) {
  1462. if (objTypes > 1) {
  1463. pWriteStrResToFile (FileHandle, WrnRasId1);
  1464. } else {
  1465. pWriteStrResToFile (FileHandle, WrnRasId2);
  1466. }
  1467. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  1468. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1469. objList = g_HTMLWrnRas;
  1470. while (objList) {
  1471. if (objList->ObjectName) {
  1472. _tcscpy (szLoadStr, TEXT("<LI>"));
  1473. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1474. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  1475. }
  1476. objList = objList->Next;
  1477. }
  1478. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  1479. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1480. }
  1481. if (g_HTMLWrnNet) {
  1482. if (objTypes > 1) {
  1483. pWriteStrResToFile (FileHandle, WrnNetId1);
  1484. } else {
  1485. pWriteStrResToFile (FileHandle, WrnNetId2);
  1486. }
  1487. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  1488. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1489. objList = g_HTMLWrnNet;
  1490. while (objList) {
  1491. if (objList->ObjectName) {
  1492. _tcscpy (szLoadStr, TEXT("<LI>"));
  1493. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1494. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  1495. }
  1496. objList = objList->Next;
  1497. }
  1498. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  1499. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1500. }
  1501. if (g_HTMLWrnPrn) {
  1502. if (objTypes > 1) {
  1503. pWriteStrResToFile (FileHandle, WrnPrnId1);
  1504. } else {
  1505. pWriteStrResToFile (FileHandle, WrnPrnId2);
  1506. }
  1507. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  1508. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1509. objList = g_HTMLWrnPrn;
  1510. while (objList) {
  1511. if (objList->ObjectName) {
  1512. _tcscpy (szLoadStr, TEXT("<LI>"));
  1513. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1514. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  1515. }
  1516. objList = objList->Next;
  1517. }
  1518. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  1519. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1520. }
  1521. if (g_HTMLWrnGeneral) {
  1522. if (objTypes > 1) {
  1523. pWriteStrResToFile (FileHandle, WrnGeneralId1);
  1524. } else {
  1525. pWriteStrResToFile (FileHandle, WrnGeneralId2);
  1526. }
  1527. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  1528. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1529. objList = g_HTMLWrnGeneral;
  1530. while (objList) {
  1531. if (objList->ObjectName) {
  1532. _tcscpy (szLoadStr, TEXT("<LI>"));
  1533. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1534. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  1535. }
  1536. objList = objList->Next;
  1537. }
  1538. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  1539. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  1540. }
  1541. }
  1542. pWriteStrResToFile (FileHandle, EndId);
  1543. return TRUE;
  1544. }
  1545. INT_PTR CALLBACK _EndCollectDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1546. {
  1547. IWebBrowser2 *m_pweb = NULL; // IE4 IWebBrowser interface pointer
  1548. IUnknown *punk = NULL;
  1549. HWND webHostWnd = NULL;
  1550. HANDLE hHTMLLog = INVALID_HANDLE_VALUE;
  1551. PWSTR szTarget;
  1552. switch (uMsg)
  1553. {
  1554. case WM_INITDIALOG:
  1555. // If Wiz95 layout...
  1556. if (g_migwiz->GetOldStyle())
  1557. {
  1558. _OldStylifyTitle(hwndDlg);
  1559. }
  1560. if (!g_fCancelPressed) {
  1561. webHostWnd = GetDlgItem (hwndDlg, IDC_WEBHOST);
  1562. if (webHostWnd) {
  1563. // Now let's generate the failure HTML file.
  1564. if (*g_HTMLLog) {
  1565. hHTMLLog = CreateFile (g_HTMLLog, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
  1566. if (hHTMLLog != INVALID_HANDLE_VALUE) {
  1567. pGenerateHTMLWarnings (
  1568. hHTMLLog,
  1569. IDS_COLLECT_BEGIN,
  1570. IDS_COLLECT_END,
  1571. 0,
  1572. 0,
  1573. IDS_WARNING_SAVE,
  1574. IDS_WARNING_SAVEFILE1,
  1575. IDS_WARNING_SAVEFILE2,
  1576. IDS_WARNING_SAVEFILE1,
  1577. IDS_WARNING_SAVEFILE2,
  1578. IDS_WARNING_SAVERAS1,
  1579. IDS_WARNING_SAVERAS2,
  1580. IDS_WARNING_SAVENET1,
  1581. IDS_WARNING_SAVENET2,
  1582. IDS_WARNING_SAVEPRN1,
  1583. IDS_WARNING_SAVEPRN2,
  1584. 0,
  1585. 0
  1586. );
  1587. g_WebContainer = new Container();
  1588. if (g_WebContainer)
  1589. {
  1590. g_WebContainer->setParent(webHostWnd);
  1591. g_WebContainer->add(L"Shell.Explorer");
  1592. g_WebContainer->setVisible(TRUE);
  1593. g_WebContainer->setFocus(TRUE);
  1594. //
  1595. // get the IWebBrowser2 interface and cache it.
  1596. //
  1597. punk = g_WebContainer->getUnknown();
  1598. if (punk)
  1599. {
  1600. punk->QueryInterface(IID_IWebBrowser2, (PVOID *)&m_pweb);
  1601. if (m_pweb) {
  1602. #ifdef UNICODE
  1603. m_pweb->Navigate(g_HTMLLog, NULL, NULL, NULL, NULL);
  1604. #else
  1605. szTarget = _ConvertToUnicode (CP_ACP, g_HTMLLog);
  1606. if (szTarget) {
  1607. m_pweb->Navigate(szTarget, NULL, NULL, NULL, NULL);
  1608. LocalFree ((HLOCAL)szTarget);
  1609. szTarget = NULL;
  1610. }
  1611. #endif
  1612. }
  1613. punk->Release();
  1614. punk = NULL;
  1615. }
  1616. }
  1617. // We intentionally want to keep this file open for the life of the wizard.
  1618. // With this we eliminate the possibility for someone to overwrite the
  1619. // content of the HTML file therefore forcing us to show something else
  1620. // maybe even run some malicious script.
  1621. // CloseHandle (hHTMLLog);
  1622. }
  1623. } else {
  1624. ShowWindow(webHostWnd, SW_HIDE);
  1625. }
  1626. }
  1627. }
  1628. break;
  1629. case WM_DESTROY:
  1630. if (m_pweb)
  1631. m_pweb->Release();
  1632. m_pweb = NULL;
  1633. //
  1634. // tell the container to remove IE4 and then
  1635. // release our reference to the container.
  1636. //
  1637. if (g_WebContainer)
  1638. {
  1639. g_WebContainer->remove();
  1640. g_WebContainer->Release();
  1641. g_WebContainer = NULL;
  1642. }
  1643. break;
  1644. case WM_NOTIFY:
  1645. switch (((LPNMHDR)lParam)->code)
  1646. {
  1647. case PSN_SETACTIVE:
  1648. DisableCancel();
  1649. break;
  1650. }
  1651. break;
  1652. }
  1653. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_FINISH, TRUE, IDC_ENDCOLLECT_TITLE);
  1654. return 0;
  1655. }
  1656. INT_PTR CALLBACK _EndCollectNetDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1657. {
  1658. static IWebBrowser2 *m_pweb = NULL; // IE4 IWebBrowser interface pointer
  1659. IUnknown *punk = NULL;
  1660. HWND webHostWnd = NULL;
  1661. HANDLE hHTMLLog = INVALID_HANDLE_VALUE;
  1662. PWSTR szTarget;
  1663. switch (uMsg)
  1664. {
  1665. case WM_INITDIALOG:
  1666. // If Wiz95 layout...
  1667. if (g_migwiz->GetOldStyle())
  1668. {
  1669. _OldStylifyTitle(hwndDlg);
  1670. }
  1671. if (!g_fCancelPressed) {
  1672. webHostWnd = GetDlgItem (hwndDlg, IDC_WEBHOST);
  1673. if (webHostWnd) {
  1674. // Now let's generate the failure HTML file.
  1675. if (*g_HTMLLog) {
  1676. hHTMLLog = CreateFile (g_HTMLLog, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
  1677. if (hHTMLLog != INVALID_HANDLE_VALUE) {
  1678. pGenerateHTMLWarnings (
  1679. hHTMLLog,
  1680. IDS_COLLECTNET_BEGIN,
  1681. IDS_COLLECTNET_END,
  1682. 0,
  1683. 0,
  1684. IDS_WARNING_SAVE,
  1685. IDS_WARNING_SAVEFILE1,
  1686. IDS_WARNING_SAVEFILE2,
  1687. IDS_WARNING_SAVEFILE1,
  1688. IDS_WARNING_SAVEFILE2,
  1689. IDS_WARNING_SAVERAS1,
  1690. IDS_WARNING_SAVERAS2,
  1691. IDS_WARNING_SAVENET1,
  1692. IDS_WARNING_SAVENET2,
  1693. IDS_WARNING_SAVEPRN1,
  1694. IDS_WARNING_SAVEPRN2,
  1695. 0,
  1696. 0
  1697. );
  1698. g_WebContainer = new Container();
  1699. if (g_WebContainer)
  1700. {
  1701. g_WebContainer->setParent(webHostWnd);
  1702. g_WebContainer->add(L"Shell.Explorer");
  1703. g_WebContainer->setVisible(TRUE);
  1704. g_WebContainer->setFocus(TRUE);
  1705. //
  1706. // get the IWebBrowser2 interface and cache it.
  1707. //
  1708. punk = g_WebContainer->getUnknown();
  1709. if (punk)
  1710. {
  1711. punk->QueryInterface(IID_IWebBrowser2, (PVOID *)&m_pweb);
  1712. if (m_pweb) {
  1713. #ifdef UNICODE
  1714. m_pweb->Navigate(g_HTMLLog, NULL, NULL, NULL, NULL);
  1715. #else
  1716. szTarget = _ConvertToUnicode (CP_ACP, g_HTMLLog);
  1717. if (szTarget) {
  1718. m_pweb->Navigate(szTarget, NULL, NULL, NULL, NULL);
  1719. LocalFree ((HLOCAL)szTarget);
  1720. szTarget = NULL;
  1721. }
  1722. #endif
  1723. }
  1724. punk->Release();
  1725. punk = NULL;
  1726. }
  1727. }
  1728. // We intentionally want to keep this file open for the life of the wizard.
  1729. // With this we eliminate the possibility for someone to overwrite the
  1730. // content of the HTML file therefore forcing us to show something else
  1731. // maybe even run some malicious script.
  1732. // CloseHandle (hHTMLLog);
  1733. }
  1734. } else {
  1735. ShowWindow(webHostWnd, SW_HIDE);
  1736. }
  1737. }
  1738. }
  1739. break;
  1740. case WM_DESTROY:
  1741. if (m_pweb)
  1742. m_pweb->Release();
  1743. m_pweb = NULL;
  1744. //
  1745. // tell the container to remove IE4 and then
  1746. // release our reference to the container.
  1747. //
  1748. if (g_WebContainer)
  1749. {
  1750. g_WebContainer->remove();
  1751. g_WebContainer->Release();
  1752. g_WebContainer = NULL;
  1753. }
  1754. break;
  1755. case WM_NOTIFY:
  1756. switch (((LPNMHDR)lParam)->code)
  1757. {
  1758. case PSN_SETACTIVE:
  1759. DisableCancel();
  1760. break;
  1761. }
  1762. break;
  1763. }
  1764. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_FINISH, TRUE, IDC_ENDCOLLECT_TITLE);
  1765. return 0;
  1766. }
  1767. ///////////////////////////////////////////////////////////////
  1768. INT_PTR CALLBACK _EndOOBEDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1769. {
  1770. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_FINISH, TRUE, IDC_ENDOOBE_TITLE);
  1771. return 0;
  1772. }
  1773. ///////////////////////////////////////////////////////////////
  1774. INT_PTR CALLBACK _EndApplyDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1775. {
  1776. IWebBrowser2 *m_pweb = NULL; // IE4 IWebBrowser interface pointer
  1777. IUnknown *punk = NULL;
  1778. HWND webHostWnd = NULL;
  1779. HANDLE hHTMLLog = INVALID_HANDLE_VALUE;
  1780. PWSTR szTarget;
  1781. TCHAR szAskForLogOff[MAX_LOADSTRING] = TEXT("");
  1782. TCHAR szAskForReboot[MAX_LOADSTRING] = TEXT("");
  1783. TCHAR szTitle[MAX_LOADSTRING] = TEXT("");
  1784. switch (uMsg)
  1785. {
  1786. case WM_INITDIALOG:
  1787. if (!g_fCancelPressed) {
  1788. webHostWnd = GetDlgItem (hwndDlg, IDC_WEBHOST);
  1789. if (webHostWnd) {
  1790. // Now let's generate the failure HTML file.
  1791. if (*g_HTMLLog) {
  1792. hHTMLLog = CreateFile (g_HTMLLog, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
  1793. if (hHTMLLog != INVALID_HANDLE_VALUE) {
  1794. pGenerateHTMLWarnings (
  1795. hHTMLLog,
  1796. IDS_APPLY_BEGIN,
  1797. IDS_APPLY_END,
  1798. 0,
  1799. 0,
  1800. IDS_WARNING_RESTORE,
  1801. IDS_WARNING_RESTOREFILE1,
  1802. IDS_WARNING_RESTOREFILE2,
  1803. IDS_WARNING_RESTOREALTFILE1,
  1804. IDS_WARNING_RESTOREALTFILE2,
  1805. IDS_WARNING_RESTORERAS1,
  1806. IDS_WARNING_RESTORERAS2,
  1807. IDS_WARNING_RESTORENET1,
  1808. IDS_WARNING_RESTORENET2,
  1809. IDS_WARNING_RESTOREPRN1,
  1810. IDS_WARNING_RESTOREPRN2,
  1811. IDS_WARNING_RESTOREGENERAL1,
  1812. IDS_WARNING_RESTOREGENERAL2
  1813. );
  1814. g_WebContainer = new Container();
  1815. if (g_WebContainer)
  1816. {
  1817. g_WebContainer->setParent(webHostWnd);
  1818. g_WebContainer->add(L"Shell.Explorer");
  1819. g_WebContainer->setVisible(TRUE);
  1820. g_WebContainer->setFocus(TRUE);
  1821. //
  1822. // get the IWebBrowser2 interface and cache it.
  1823. //
  1824. punk = g_WebContainer->getUnknown();
  1825. if (punk)
  1826. {
  1827. punk->QueryInterface(IID_IWebBrowser2, (PVOID *)&m_pweb);
  1828. if (m_pweb) {
  1829. #ifdef UNICODE
  1830. m_pweb->Navigate(g_HTMLLog, NULL, NULL, NULL, NULL);
  1831. #else
  1832. szTarget = _ConvertToUnicode (CP_ACP, g_HTMLLog);
  1833. if (szTarget) {
  1834. m_pweb->Navigate(szTarget, NULL, NULL, NULL, NULL);
  1835. LocalFree ((HLOCAL)szTarget);
  1836. szTarget = NULL;
  1837. }
  1838. #endif
  1839. }
  1840. punk->Release();
  1841. punk = NULL;
  1842. }
  1843. }
  1844. // We intentionally want to keep this file open for the life of the wizard.
  1845. // With this we eliminate the possibility for someone to overwrite the
  1846. // content of the HTML file therefore forcing us to show something else
  1847. // maybe even run some malicious script.
  1848. // CloseHandle (hHTMLLog);
  1849. }
  1850. } else {
  1851. ShowWindow(webHostWnd, SW_HIDE);
  1852. }
  1853. }
  1854. }
  1855. break;
  1856. case WM_DESTROY:
  1857. if (m_pweb)
  1858. m_pweb->Release();
  1859. m_pweb = NULL;
  1860. //
  1861. // tell the container to remove IE4 and then
  1862. // release our reference to the container.
  1863. //
  1864. if (g_WebContainer)
  1865. {
  1866. g_WebContainer->remove();
  1867. g_WebContainer->Release();
  1868. g_WebContainer = NULL;
  1869. }
  1870. break;
  1871. case WM_NOTIFY:
  1872. switch (((LPNMHDR)lParam)->code)
  1873. {
  1874. case PSN_SETACTIVE:
  1875. DisableCancel();
  1876. break;
  1877. case PSN_WIZFINISH:
  1878. ShowWindow(g_hwndWizard, SW_HIDE);
  1879. if (g_CompleteReboot) {
  1880. g_CompleteReboot = FALSE;
  1881. g_CompleteLogOff = FALSE;
  1882. if (LoadString(g_migwiz->GetInstance(),
  1883. IDS_MIGWIZTITLE,
  1884. szTitle,
  1885. ARRAYSIZE(szTitle))) {
  1886. if (LoadString(g_migwiz->GetInstance(),
  1887. IDS_ASKFORREBOOT,
  1888. szAskForReboot,
  1889. ARRAYSIZE(szAskForReboot))) {
  1890. if (_ExclusiveMessageBox(g_hwndWizard, szAskForReboot, szTitle, MB_YESNO) == IDYES) {
  1891. g_ConfirmedReboot = TRUE;
  1892. }
  1893. }
  1894. }
  1895. } else if (g_CompleteLogOff) {
  1896. g_CompleteLogOff = FALSE;
  1897. if (LoadString(g_migwiz->GetInstance(),
  1898. IDS_MIGWIZTITLE,
  1899. szTitle,
  1900. ARRAYSIZE(szTitle))) {
  1901. if (LoadString(g_migwiz->GetInstance(),
  1902. IDS_ASKFORLOGOFF,
  1903. szAskForLogOff,
  1904. ARRAYSIZE(szAskForLogOff))) {
  1905. if (_ExclusiveMessageBox(g_hwndWizard, szAskForLogOff, szTitle, MB_YESNO) == IDYES) {
  1906. g_ConfirmedLogOff = TRUE;
  1907. }
  1908. }
  1909. }
  1910. }
  1911. }
  1912. break;
  1913. }
  1914. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_FINISH, TRUE, IDC_ENDAPPLY_TITLE);
  1915. return 0;
  1916. }
  1917. ///////////////////////////////////////////////////////////////
  1918. typedef struct {
  1919. BOOL fSource;
  1920. HWND hwndDlg;
  1921. } CLEANUPSTRUCT;
  1922. DWORD WINAPI _FailureCleanUpThread (LPVOID lpParam)
  1923. {
  1924. CLEANUPSTRUCT* pcsStruct = (CLEANUPSTRUCT*)lpParam;
  1925. DWORD result = WAIT_OBJECT_0;
  1926. HRESULT hResult = ERROR_SUCCESS;
  1927. //
  1928. // Wait for the current thread to finish
  1929. //
  1930. if (g_TerminateEvent)
  1931. {
  1932. result = WaitForSingleObject (g_TerminateEvent, ENGINE_TIMEOUT);
  1933. }
  1934. //
  1935. // Terminate the engine
  1936. //
  1937. if (result == WAIT_OBJECT_0) {
  1938. hResult = Engine_Terminate ();
  1939. }
  1940. SendMessage (pcsStruct->hwndDlg, WM_USER_THREAD_COMPLETE, 0, (LPARAM) hResult);
  1941. LocalFree(pcsStruct);
  1942. return 0;
  1943. }
  1944. INT_PTR CALLBACK _CleanUpDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1945. {
  1946. HRESULT hResult;
  1947. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, 0, FALSE, 0);
  1948. switch (uMsg)
  1949. {
  1950. case WM_INITDIALOG:
  1951. // If Wiz95 layout...
  1952. if (g_migwiz->GetOldStyle())
  1953. {
  1954. _OldStylify(hwndDlg, IDS_FAILCLEANUPTITLE);
  1955. }
  1956. break;
  1957. case WM_NOTIFY :
  1958. switch (((LPNMHDR)lParam)->code)
  1959. {
  1960. case PSN_SETACTIVE:
  1961. DisableCancel();
  1962. {
  1963. ANIMATE_OPEN(hwndDlg,IDC_WAIT_ANIMATE2,IDA_STARTUP);
  1964. ANIMATE_PLAY(hwndDlg,IDC_WAIT_ANIMATE2);
  1965. CLEANUPSTRUCT* pcsStruct = (CLEANUPSTRUCT*)LocalAlloc(LPTR, sizeof(CLEANUPSTRUCT));
  1966. if (pcsStruct)
  1967. {
  1968. pcsStruct->fSource = g_fOldComputer;
  1969. pcsStruct->hwndDlg = hwndDlg;
  1970. SHCreateThread(_FailureCleanUpThread, pcsStruct, 0, NULL);
  1971. }
  1972. else
  1973. {
  1974. SetWindowLong(hwndDlg, DWLP_MSGRESULT, g_fOldComputer?IDD_ENDCOLLECTFAIL:IDD_ENDAPPLYFAIL);
  1975. }
  1976. }
  1977. return TRUE;
  1978. break;
  1979. case PSN_WIZBACK:
  1980. case PSN_WIZNEXT:
  1981. ANIMATE_STOP(hwndDlg,IDC_WAIT_ANIMATE2);
  1982. ANIMATE_CLOSE(hwndDlg,IDC_WAIT_ANIMATE2);
  1983. if (g_fCancelPressed)
  1984. {
  1985. // User aborted
  1986. PostQuitMessage( 0 );
  1987. }
  1988. else
  1989. {
  1990. // Error condition
  1991. SetWindowLong(hwndDlg, DWLP_MSGRESULT, g_fOldComputer?IDD_ENDCOLLECTFAIL:IDD_ENDAPPLYFAIL);
  1992. }
  1993. return TRUE;
  1994. break;
  1995. }
  1996. break;
  1997. case WM_USER_THREAD_COMPLETE:
  1998. hResult = (HRESULT) lParam;
  1999. if (FAILED(hResult))
  2000. {
  2001. g_fUberCancel = TRUE;
  2002. }
  2003. _NextWizardPage (hwndDlg);
  2004. break;
  2005. default:
  2006. break;
  2007. }
  2008. return 0;
  2009. }
  2010. INT_PTR CALLBACK _EndFailDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2011. {
  2012. IWebBrowser2 *m_pweb = NULL; // IE4 IWebBrowser interface pointer
  2013. IUnknown *punk = NULL;
  2014. HWND webHostWnd = NULL;
  2015. HANDLE hHTMLLog = INVALID_HANDLE_VALUE;
  2016. TCHAR szLoadStr[MAX_LOADSTRING];
  2017. DWORD written;
  2018. PWSTR szTarget;
  2019. switch (uMsg)
  2020. {
  2021. case WM_INITDIALOG:
  2022. // If Wiz95 layout...
  2023. if (g_migwiz->GetOldStyle())
  2024. {
  2025. _OldStylifyTitle(hwndDlg);
  2026. }
  2027. if (!g_fCancelPressed) {
  2028. webHostWnd = GetDlgItem (hwndDlg, IDC_WEBHOST);
  2029. if (webHostWnd) {
  2030. // Now let's generate the failure HTML file.
  2031. if (*g_HTMLLog) {
  2032. hHTMLLog = CreateFile (g_HTMLLog, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
  2033. if (hHTMLLog != INVALID_HANDLE_VALUE) {
  2034. pGenerateHTMLWarnings (
  2035. hHTMLLog,
  2036. IDS_ERRORHTML_BEGIN,
  2037. IDS_ERRORHTML_END,
  2038. g_HTMLErrArea?g_HTMLErrArea:IDS_ERRORAREA_UNKNOWN,
  2039. g_HTMLErrInstr,
  2040. 0,
  2041. IDS_ERRORHTML_SAVEFILE1,
  2042. IDS_ERRORHTML_SAVEFILE2,
  2043. IDS_ERRORHTML_SAVEFILE1,
  2044. IDS_ERRORHTML_SAVEFILE2,
  2045. IDS_ERRORHTML_SAVERAS1,
  2046. IDS_ERRORHTML_SAVERAS2,
  2047. IDS_ERRORHTML_SAVENET1,
  2048. IDS_ERRORHTML_SAVENET2,
  2049. IDS_ERRORHTML_SAVEPRN1,
  2050. IDS_ERRORHTML_SAVEPRN2,
  2051. 0,
  2052. 0
  2053. );
  2054. g_WebContainer = new Container();
  2055. if (g_WebContainer)
  2056. {
  2057. g_WebContainer->setParent(webHostWnd);
  2058. g_WebContainer->add(L"Shell.Explorer");
  2059. g_WebContainer->setVisible(TRUE);
  2060. g_WebContainer->setFocus(TRUE);
  2061. //
  2062. // get the IWebBrowser2 interface and cache it.
  2063. //
  2064. punk = g_WebContainer->getUnknown();
  2065. if (punk)
  2066. {
  2067. punk->QueryInterface(IID_IWebBrowser2, (PVOID *)&m_pweb);
  2068. if (m_pweb) {
  2069. #ifdef UNICODE
  2070. m_pweb->Navigate(g_HTMLLog, NULL, NULL, NULL, NULL);
  2071. #else
  2072. szTarget = _ConvertToUnicode (CP_ACP, g_HTMLLog);
  2073. if (szTarget) {
  2074. m_pweb->Navigate(szTarget, NULL, NULL, NULL, NULL);
  2075. LocalFree ((HLOCAL)szTarget);
  2076. szTarget = NULL;
  2077. }
  2078. #endif
  2079. }
  2080. punk->Release();
  2081. punk = NULL;
  2082. }
  2083. }
  2084. // We intentionally want to keep this file open for the life of the wizard.
  2085. // With this we eliminate the possibility for someone to overwrite the
  2086. // content of the HTML file therefore forcing us to show something else
  2087. // maybe even run some malicious script.
  2088. // CloseHandle (hHTMLLog);
  2089. }
  2090. } else {
  2091. ShowWindow(webHostWnd, SW_HIDE);
  2092. }
  2093. }
  2094. }
  2095. break;
  2096. case WM_DESTROY:
  2097. if (m_pweb)
  2098. m_pweb->Release();
  2099. m_pweb = NULL;
  2100. //
  2101. // tell the container to remove IE4 and then
  2102. // release our reference to the container.
  2103. //
  2104. if (g_WebContainer)
  2105. {
  2106. g_WebContainer->remove();
  2107. g_WebContainer->Release();
  2108. g_WebContainer = NULL;
  2109. }
  2110. break;
  2111. case WM_NOTIFY:
  2112. switch (((LPNMHDR)lParam)->code)
  2113. {
  2114. case PSN_SETACTIVE:
  2115. DisableCancel();
  2116. break;
  2117. }
  2118. break;
  2119. }
  2120. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_FINISH, TRUE, IDC_ENDFAIL_TITLE);
  2121. return 0;
  2122. }
  2123. ///////////////////////////////////////////////////////////////
  2124. typedef struct {
  2125. PBOOL pfHaveNet;
  2126. BOOL fSource;
  2127. HWND hwndDlg;
  2128. } STARTENGINESTRUCT;
  2129. DWORD WINAPI _StartEngineDlgProcThread (LPVOID lpParam)
  2130. {
  2131. STARTENGINESTRUCT* pseStruct = (STARTENGINESTRUCT*)lpParam;
  2132. HRESULT hResult;
  2133. hResult = g_migwiz->_InitEngine(pseStruct->fSource, pseStruct->pfHaveNet);
  2134. SendMessage (pseStruct->hwndDlg, WM_USER_THREAD_COMPLETE, 0, (LPARAM) hResult);
  2135. pSetEvent (&g_TerminateEvent);
  2136. LocalFree(pseStruct);
  2137. return 0;
  2138. }
  2139. INT_PTR CALLBACK _StartEngineDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2140. {
  2141. HRESULT hResult;
  2142. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, 0, FALSE, 0);
  2143. switch (uMsg)
  2144. {
  2145. case WM_INITDIALOG:
  2146. // If Wiz95 layout...
  2147. if (g_migwiz->GetOldStyle())
  2148. {
  2149. _OldStylify(hwndDlg, IDS_WAITTITLE);
  2150. }
  2151. break;
  2152. case WM_NOTIFY:
  2153. switch (((LPNMHDR)lParam)->code)
  2154. {
  2155. case PSN_QUERYCANCEL:
  2156. return _HandleCancel(hwndDlg, FALSE, TRUE);
  2157. break;
  2158. case PSN_SETACTIVE:
  2159. if ((ENGINE_INITGATHER == g_iEngineInit && g_fOldComputer) ||
  2160. (ENGINE_INITAPPLY == g_iEngineInit && !g_fOldComputer))
  2161. {
  2162. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_NEXT);
  2163. }
  2164. else
  2165. {
  2166. ANIMATE_OPEN(hwndDlg,IDC_WAIT_ANIMATE1,IDA_STARTUP);
  2167. ANIMATE_PLAY(hwndDlg,IDC_WAIT_ANIMATE1);
  2168. STARTENGINESTRUCT* pseStruct = (STARTENGINESTRUCT*)LocalAlloc(LPTR, sizeof(STARTENGINESTRUCT));
  2169. if (pseStruct)
  2170. {
  2171. pseStruct->fSource = g_fOldComputer;
  2172. pseStruct->pfHaveNet = &g_fHaveNet;
  2173. pseStruct->hwndDlg = hwndDlg;
  2174. SHCreateThread(_StartEngineDlgProcThread, pseStruct, 0, NULL);
  2175. }
  2176. else
  2177. {
  2178. SetWindowLong(hwndDlg, DWLP_MSGRESULT, g_fOldComputer?IDD_ENDCOLLECTFAIL:IDD_ENDAPPLYFAIL);
  2179. }
  2180. }
  2181. return TRUE;
  2182. break;
  2183. case PSN_WIZNEXT:
  2184. ANIMATE_STOP(hwndDlg,IDC_WAIT_ANIMATE1);
  2185. ANIMATE_CLOSE(hwndDlg,IDC_WAIT_ANIMATE1);
  2186. if (g_fUberCancel)
  2187. {
  2188. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  2189. }
  2190. else if (g_fOldComputer)
  2191. {
  2192. g_iEngineInit = ENGINE_INITGATHER;
  2193. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKCOLLECTSTORE); // go on with prepare
  2194. }
  2195. else
  2196. {
  2197. g_iEngineInit = ENGINE_INITAPPLY;
  2198. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ASKCD); // go on with apply
  2199. }
  2200. return TRUE;
  2201. break;
  2202. case PSN_WIZBACK:
  2203. // ISSUE: we should assert here or something, this should never happen
  2204. ANIMATE_STOP(hwndDlg,IDC_WAIT_ANIMATE1);
  2205. ANIMATE_CLOSE(hwndDlg,IDC_WAIT_ANIMATE1);
  2206. if (g_fOldComputer)
  2207. {
  2208. SetWindowLong(hwndDlg, DWLP_MSGRESULT, g_migwiz->GetLegacy() ? IDD_INTROLEGACY : IDD_GETSTARTED);
  2209. }
  2210. else
  2211. {
  2212. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_GETSTARTED);
  2213. }
  2214. return TRUE;
  2215. break;
  2216. }
  2217. break;
  2218. case WM_USER_CANCEL_PENDING:
  2219. g_fUberCancel = TRUE;
  2220. pResetEvent (&g_TerminateEvent);
  2221. _NextWizardPage (hwndDlg);
  2222. break;
  2223. case WM_USER_THREAD_COMPLETE:
  2224. hResult = (HRESULT) lParam;
  2225. if (FAILED(hResult))
  2226. {
  2227. g_fUberCancel = TRUE;
  2228. }
  2229. EnableCancel ();
  2230. _NextWizardPage (hwndDlg);
  2231. break;
  2232. case WM_USER_ROLLBACK:
  2233. // Hide IDC_WAIT_TEXT1 and show IDC_WAIT_TEXT2
  2234. ShowWindow(GetDlgItem(hwndDlg, IDC_WAIT_TEXT1), SW_HIDE);
  2235. ShowWindow(GetDlgItem(hwndDlg, IDC_WAIT_TEXT2), SW_SHOW);
  2236. break;
  2237. default:
  2238. break;
  2239. }
  2240. return 0;
  2241. }
  2242. ///////////////////////////////////////////////////////////////
  2243. INT_PTR CALLBACK _GetStartedDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2244. {
  2245. static UINT uiSelectedStart = 2; // 1=old, 2=new
  2246. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  2247. switch (uMsg)
  2248. {
  2249. case WM_INITDIALOG:
  2250. Button_SetCheck(GetDlgItem(hwndDlg,IDC_GETSTARTED_RADIONEW), BST_CHECKED);
  2251. Button_SetCheck(GetDlgItem(hwndDlg,IDC_GETSTARTED_RADIOOLD), BST_UNCHECKED);
  2252. break;
  2253. case WM_COMMAND:
  2254. switch (LOWORD(wParam))
  2255. {
  2256. case IDC_GETSTARTED_RADIOOLD:
  2257. uiSelectedStart = 1;
  2258. break;
  2259. case IDC_GETSTARTED_RADIONEW:
  2260. uiSelectedStart = 2;
  2261. break;
  2262. }
  2263. break;
  2264. case WM_NOTIFY :
  2265. switch (((LPNMHDR)lParam)->code)
  2266. {
  2267. case PSN_QUERYCANCEL:
  2268. return _HandleCancel(hwndDlg, TRUE, FALSE);
  2269. break;
  2270. case PSN_WIZNEXT:
  2271. if (g_fUberCancel)
  2272. {
  2273. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ENDAPPLYFAIL);
  2274. }
  2275. else
  2276. {
  2277. g_fOldComputer = (uiSelectedStart == 1);
  2278. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_WAIT); // go on with prepare
  2279. }
  2280. return TRUE;
  2281. break;
  2282. case PSN_WIZBACK:
  2283. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_INTRO);
  2284. return TRUE;
  2285. break;
  2286. }
  2287. break;
  2288. default:
  2289. break;
  2290. }
  2291. return 0;
  2292. }
  2293. ///////////////////////////////////////////////////////////////
  2294. VOID _CleanTreeView(HWND hwndTree)
  2295. {
  2296. if (hwndTree)
  2297. {
  2298. HTREEITEM rghti[4] = { g_htiFolders, g_htiFiles, g_htiSettings, g_htiTypes };
  2299. HTREEITEM hti;
  2300. TVITEM item = {0};
  2301. item.mask = TVIF_PARAM | TVIF_HANDLE;
  2302. for (int i = 0; i < ARRAYSIZE(rghti); i++)
  2303. {
  2304. hti = rghti[i];
  2305. if (hti)
  2306. {
  2307. hti = TreeView_GetChild(hwndTree, hti);
  2308. while (hti)
  2309. {
  2310. item.hItem = hti;
  2311. if (TreeView_GetItem(hwndTree, &item))
  2312. {
  2313. if (item.lParam)
  2314. {
  2315. if (((LV_DATASTRUCT*)item.lParam)->pszPureName)
  2316. {
  2317. LocalFree(((LV_DATASTRUCT*)item.lParam)->pszPureName);
  2318. }
  2319. LocalFree((HLOCAL)item.lParam);
  2320. }
  2321. }
  2322. hti = TreeView_GetNextItem(hwndTree, hti, TVGN_NEXT);
  2323. }
  2324. }
  2325. }
  2326. TreeView_DeleteAllItems(hwndTree);
  2327. }
  2328. }
  2329. VOID __PopulateFilesDocumentsCollected (HWND hwndTree, UINT uiRadio)
  2330. {
  2331. MIG_COMPONENT_ENUM mce;
  2332. _CleanTreeView(hwndTree); // ISSUE: we should free the memory of all elements in this tree
  2333. g_htiFolders = NULL;
  2334. g_htiFiles = NULL;
  2335. g_htiTypes = NULL;
  2336. g_htiSettings = NULL;
  2337. if (IsmEnumFirstComponent (&mce, COMPONENTENUM_ALIASES|COMPONENTENUM_ENABLED|
  2338. COMPONENTENUM_PREFERRED_ONLY, 0))
  2339. {
  2340. do {
  2341. switch (mce.GroupId)
  2342. {
  2343. case COMPONENT_FOLDER:
  2344. _PopulateTree (
  2345. hwndTree,
  2346. __GetRootFolder (hwndTree),
  2347. (PTSTR) mce.LocalizedAlias,
  2348. lstrlen (mce.LocalizedAlias) + 1,
  2349. _GetPrettyFolderName,
  2350. POPULATETREE_FLAGS_FOLDERS,
  2351. g_migwiz->GetInstance(),
  2352. g_migwiz->GetWinNT4()
  2353. );
  2354. mce.SkipToNextComponent = TRUE;
  2355. break;
  2356. case COMPONENT_FILE:
  2357. _PopulateTree (
  2358. hwndTree,
  2359. __GetRootFile (hwndTree),
  2360. (PTSTR) mce.LocalizedAlias,
  2361. lstrlen (mce.LocalizedAlias) + 1,
  2362. NULL,
  2363. POPULATETREE_FLAGS_FILES,
  2364. g_migwiz->GetInstance(),
  2365. g_migwiz->GetWinNT4()
  2366. );
  2367. mce.SkipToNextComponent = TRUE;
  2368. break;
  2369. case COMPONENT_EXTENSION:
  2370. _PopulateTree (
  2371. hwndTree,
  2372. __GetRootType (hwndTree),
  2373. (PTSTR) mce.LocalizedAlias,
  2374. lstrlen (mce.LocalizedAlias) + 1,
  2375. NULL,
  2376. POPULATETREE_FLAGS_FILETYPES,
  2377. g_migwiz->GetInstance(),
  2378. g_migwiz->GetWinNT4()
  2379. );
  2380. mce.SkipToNextComponent = TRUE;
  2381. break;
  2382. case COMPONENT_NAME:
  2383. _PopulateTree (
  2384. hwndTree,
  2385. __GetRootSetting (hwndTree),
  2386. (PTSTR) mce.LocalizedAlias,
  2387. lstrlen (mce.LocalizedAlias) + 1,
  2388. NULL,
  2389. POPULATETREE_FLAGS_SETTINGS,
  2390. g_migwiz->GetInstance(),
  2391. g_migwiz->GetWinNT4()
  2392. );
  2393. mce.SkipToNextComponent = TRUE;
  2394. break;
  2395. }
  2396. } while (IsmEnumNextComponent (&mce));
  2397. }
  2398. }
  2399. ///////////////////////////////////////////////////////////////
  2400. typedef struct {
  2401. BOOL Valid;
  2402. PCTSTR PortName;
  2403. DWORD PortSpeed;
  2404. HANDLE Event;
  2405. HANDLE Thread;
  2406. } DIRECTCABLE_DATA, *PDIRECTCABLE_DATA;
  2407. typedef struct {
  2408. DWORD Signature;
  2409. DWORD MaxSpeed;
  2410. } DIRECTSEND_DATA, *PDIRECTSEND_DATA;
  2411. typedef struct {
  2412. HWND hwndCombo;
  2413. PDIRECTCABLE_DATA DirectCableData;
  2414. } AUTODETECT_DATA, *PAUTODETECT_DATA;
  2415. HANDLE
  2416. UIOpenAndSetPort (
  2417. IN PCTSTR ComPort,
  2418. OUT PDWORD MaxSpeed
  2419. )
  2420. {
  2421. HANDLE result = INVALID_HANDLE_VALUE;
  2422. COMMTIMEOUTS commTimeouts;
  2423. DCB dcb;
  2424. UINT index;
  2425. // let's open the port. If we can't we just exit with error;
  2426. result = CreateFile (ComPort, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  2427. if (result == INVALID_HANDLE_VALUE) {
  2428. return result;
  2429. }
  2430. // we want 10 sec timeout for both read and write
  2431. commTimeouts.ReadIntervalTimeout = 0;
  2432. commTimeouts.ReadTotalTimeoutMultiplier = 0;
  2433. commTimeouts.ReadTotalTimeoutConstant = 3000;
  2434. commTimeouts.WriteTotalTimeoutMultiplier = 0;
  2435. commTimeouts.WriteTotalTimeoutConstant = 3000;
  2436. SetCommTimeouts (result, &commTimeouts);
  2437. // let's set some comm state data
  2438. if (GetCommState (result, &dcb)) {
  2439. dcb.fBinary = 1;
  2440. dcb.fParity = 1;
  2441. dcb.ByteSize = 8;
  2442. dcb.fOutxCtsFlow = 1;
  2443. dcb.fTXContinueOnXoff = 1;
  2444. dcb.fRtsControl = 2;
  2445. dcb.fAbortOnError = 1;
  2446. dcb.Parity = 0;
  2447. // let's first see the max speed
  2448. if (MaxSpeed) {
  2449. *MaxSpeed = 0;
  2450. index = 0;
  2451. while (TRUE) {
  2452. dcb.BaudRate = g_BaudRate [index];
  2453. if (dcb.BaudRate == 0) {
  2454. break;
  2455. }
  2456. if (!SetCommState (result, &dcb)) {
  2457. break;
  2458. }
  2459. *MaxSpeed = g_BaudRate [index];
  2460. index ++;
  2461. }
  2462. }
  2463. dcb.BaudRate = CBR_110;
  2464. if (!SetCommState (result, &dcb)) {
  2465. CloseHandle (result);
  2466. result = INVALID_HANDLE_VALUE;
  2467. return result;
  2468. }
  2469. } else {
  2470. CloseHandle (result);
  2471. result = INVALID_HANDLE_VALUE;
  2472. return result;
  2473. }
  2474. return result;
  2475. }
  2476. #define ACK 0x16
  2477. #define NAK 0x15
  2478. #define SOH 0x01
  2479. #define EOT 0x04
  2480. #define BLOCKSIZE (sizeof (DIRECTSEND_DATA))
  2481. #define DIRECTTR_SIG 0x55534D33 //USM2
  2482. BOOL
  2483. UISendBlockToHandle (
  2484. IN HANDLE DeviceHandle,
  2485. IN PCBYTE Buffer,
  2486. IN HANDLE Event
  2487. )
  2488. {
  2489. BOOL result = TRUE;
  2490. BYTE buffer [4 + BLOCKSIZE];
  2491. BYTE signal;
  2492. BYTE currBlock = 0;
  2493. DWORD numRead;
  2494. DWORD numWritten;
  2495. BOOL repeat = FALSE;
  2496. UINT index;
  2497. // let's start the protocol
  2498. // We are going to listen for the NAK(15h) signal.
  2499. // As soon as we get it we are going to send a 4 + BLOCKSIZE bytes block having:
  2500. // 1 byte - SOH (01H)
  2501. // 1 byte - block number
  2502. // 1 byte - FF - block number
  2503. // BLOCKSIZE bytes of data
  2504. // 1 byte - checksum - sum of all BLOCKSIZE bytes of data
  2505. // After the block is sent, we are going to wait for ACK(16h). If we don't get
  2506. // it after timeout or if we get something else we are going to send the block again.
  2507. // wait for NAK
  2508. while ((!ReadFile (DeviceHandle, &signal, sizeof (signal), &numRead, NULL) ||
  2509. (numRead != 1) ||
  2510. (signal != NAK)
  2511. ) &&
  2512. (!pIsEventSet (&Event))
  2513. );
  2514. repeat = FALSE;
  2515. while (TRUE) {
  2516. if (pIsEventSet (&Event)) {
  2517. result = FALSE;
  2518. break;
  2519. }
  2520. if (!repeat) {
  2521. // prepare the next block
  2522. currBlock ++;
  2523. if (currBlock == 0) {
  2524. result = TRUE;
  2525. }
  2526. buffer [0] = SOH;
  2527. buffer [1] = currBlock;
  2528. buffer [2] = 0xFF - currBlock;
  2529. CopyMemory (buffer + 3, Buffer, BLOCKSIZE);
  2530. // compute the checksum
  2531. buffer [sizeof (buffer) - 1] = 0;
  2532. signal = 0;
  2533. for (index = 0; index < sizeof (buffer) - 1; index ++) {
  2534. signal += buffer [index];
  2535. }
  2536. buffer [sizeof (buffer) - 1] = signal;
  2537. }
  2538. // now send the block to the other side
  2539. if (!WriteFile (DeviceHandle, buffer, sizeof (buffer), &numWritten, NULL) ||
  2540. (numWritten != sizeof (buffer))
  2541. ) {
  2542. repeat = TRUE;
  2543. } else {
  2544. repeat = FALSE;
  2545. }
  2546. if (pIsEventSet (&Event)) {
  2547. result = FALSE;
  2548. break;
  2549. }
  2550. if (repeat) {
  2551. // we could not send the data last time
  2552. // let's just wait for a NAK for 10 sec and then send it again
  2553. ReadFile (DeviceHandle, &signal, sizeof (signal), &numRead, NULL);
  2554. } else {
  2555. // we sent it OK. We need to wait for an ACK to come. If we timeout
  2556. // or we get something else, we will repeat the block.
  2557. if (!ReadFile (DeviceHandle, &signal, sizeof (signal), &numRead, NULL) ||
  2558. (numRead != sizeof (signal)) ||
  2559. (signal != ACK)
  2560. ) {
  2561. repeat = TRUE;
  2562. } else {
  2563. // we are done with data, send the EOT signal
  2564. signal = EOT;
  2565. WriteFile (DeviceHandle, &signal, sizeof (signal), &numWritten, NULL);
  2566. break;
  2567. }
  2568. }
  2569. }
  2570. if (result) {
  2571. // we are done here. However, let's listen one more timeout for a
  2572. // potential NAK. If we get it, we'll repeat the EOT signal
  2573. while (ReadFile (DeviceHandle, &signal, sizeof (signal), &numRead, NULL) &&
  2574. (numRead == 1)
  2575. ) {
  2576. if (signal == NAK) {
  2577. signal = EOT;
  2578. WriteFile (DeviceHandle, &signal, sizeof (signal), &numWritten, NULL);
  2579. }
  2580. }
  2581. }
  2582. return result;
  2583. }
  2584. BOOL
  2585. UIReceiveBlockFromHandle (
  2586. IN HANDLE DeviceHandle,
  2587. OUT PBYTE Buffer,
  2588. IN HANDLE Event
  2589. )
  2590. {
  2591. BOOL result = TRUE;
  2592. BYTE buffer [4 + BLOCKSIZE];
  2593. BYTE signal;
  2594. BYTE currBlock = 1;
  2595. DWORD numRead;
  2596. DWORD numWritten;
  2597. BOOL repeat = TRUE;
  2598. UINT index;
  2599. // finally let's start the protocol
  2600. // We are going to send an NAK(15h) signal.
  2601. // After that we are going to listen for a block.
  2602. // If we don't get the block in time, or the block is wrong size
  2603. // or it has a wrong checksum we are going to send a NAK signal,
  2604. // otherwise we are going to send an ACK signal
  2605. // One exception. If the block size is 1 and the block is actually the
  2606. // EOT signal it means we are done.
  2607. ZeroMemory (Buffer, BLOCKSIZE);
  2608. while (TRUE) {
  2609. if (pIsEventSet (&Event)) {
  2610. result = FALSE;
  2611. break;
  2612. }
  2613. if (repeat) {
  2614. // send the NAK
  2615. signal = NAK;
  2616. WriteFile (DeviceHandle, &signal, sizeof (signal), &numWritten, NULL);
  2617. } else {
  2618. // send the ACK
  2619. signal = ACK;
  2620. WriteFile (DeviceHandle, &signal, sizeof (signal), &numWritten, NULL);
  2621. }
  2622. if (pIsEventSet (&Event)) {
  2623. result = FALSE;
  2624. break;
  2625. }
  2626. repeat = TRUE;
  2627. // let's read the data block
  2628. if (ReadFile (DeviceHandle, buffer, sizeof (buffer), &numRead, NULL)) {
  2629. if ((numRead == 1) &&
  2630. (buffer [0] == EOT)
  2631. ) {
  2632. // we are done
  2633. break;
  2634. }
  2635. if (numRead == sizeof (buffer)) {
  2636. // compute the checksum
  2637. signal = 0;
  2638. for (index = 0; index < sizeof (buffer) - 1; index ++) {
  2639. signal += buffer [index];
  2640. }
  2641. if (buffer [sizeof (buffer) - 1] == signal) {
  2642. repeat = FALSE;
  2643. // checksum is correct, let's see if this is the right block
  2644. if (currBlock < buffer [1]) {
  2645. // this is a major error, the sender is ahead of us,
  2646. // we have to fail
  2647. result = FALSE;
  2648. break;
  2649. }
  2650. if (currBlock == buffer [1]) {
  2651. CopyMemory (Buffer, buffer + 3, BLOCKSIZE);
  2652. currBlock ++;
  2653. }
  2654. }
  2655. }
  2656. }
  2657. }
  2658. return result;
  2659. }
  2660. DWORD WINAPI _DirectCableConnectThread (LPVOID lpParam)
  2661. {
  2662. PDIRECTCABLE_DATA directCableData;
  2663. HANDLE comHandle = INVALID_HANDLE_VALUE;
  2664. DIRECTSEND_DATA sendData;
  2665. DIRECTSEND_DATA receiveData;
  2666. directCableData = (PDIRECTCABLE_DATA) lpParam;
  2667. if (directCableData) {
  2668. sendData.Signature = DIRECTTR_SIG;
  2669. // open the COM port and set the timeout and speed
  2670. comHandle = UIOpenAndSetPort (directCableData->PortName, &(sendData.MaxSpeed));
  2671. if (comHandle) {
  2672. // send the message to the COM port
  2673. if (g_fOldComputer) {
  2674. if (UISendBlockToHandle (comHandle, (PCBYTE)(&sendData), directCableData->Event)) {
  2675. if (UIReceiveBlockFromHandle (comHandle, (PBYTE)(&receiveData), directCableData->Event)) {
  2676. if (sendData.Signature == receiveData.Signature) {
  2677. directCableData->Valid = TRUE;
  2678. directCableData->PortSpeed = min (sendData.MaxSpeed, receiveData.MaxSpeed);
  2679. }
  2680. }
  2681. }
  2682. } else {
  2683. if (UIReceiveBlockFromHandle (comHandle, (PBYTE)(&receiveData), directCableData->Event)) {
  2684. if (UISendBlockToHandle (comHandle, (PCBYTE)(&sendData), directCableData->Event)) {
  2685. if (sendData.Signature == receiveData.Signature) {
  2686. directCableData->Valid = TRUE;
  2687. directCableData->PortSpeed = min (sendData.MaxSpeed, receiveData.MaxSpeed);
  2688. }
  2689. }
  2690. }
  2691. }
  2692. CloseHandle (comHandle);
  2693. comHandle = INVALID_HANDLE_VALUE;
  2694. }
  2695. }
  2696. pSetEvent (&(directCableData->Event));
  2697. ExitThread (0);
  2698. }
  2699. INT_PTR CALLBACK _DirectCableWaitDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2700. {
  2701. static PDIRECTCABLE_DATA directCableData = NULL;
  2702. DWORD waitResult;
  2703. switch (uMsg)
  2704. {
  2705. case WM_INITDIALOG :
  2706. directCableData = (PDIRECTCABLE_DATA) lParam;
  2707. SetTimer (hwndDlg, NULL, 100, NULL);
  2708. ANIMATE_OPEN(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE,IDA_STARTUP);
  2709. ANIMATE_PLAY(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2710. return TRUE;
  2711. case WM_COMMAND:
  2712. switch (LOWORD(wParam))
  2713. {
  2714. case IDCANCEL:
  2715. if (directCableData) {
  2716. pSetEvent (&(directCableData->Event));
  2717. waitResult = WaitForSingleObject (directCableData->Thread, 0);
  2718. if (waitResult == WAIT_OBJECT_0) {
  2719. // the thread is done
  2720. ANIMATE_STOP(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2721. ANIMATE_CLOSE(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2722. EndDialog(hwndDlg, FALSE);
  2723. } else {
  2724. // Let's change the static text
  2725. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_WAIT_TEXT1), SW_HIDE);
  2726. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_WAIT_TEXT2), SW_SHOW);
  2727. }
  2728. } else {
  2729. ANIMATE_STOP(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2730. ANIMATE_CLOSE(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2731. EndDialog(hwndDlg, FALSE);
  2732. }
  2733. return TRUE;
  2734. }
  2735. break;
  2736. case WM_TIMER:
  2737. if (directCableData) {
  2738. if (pIsEventSet (&(directCableData->Event))) {
  2739. waitResult = WaitForSingleObject (directCableData->Thread, 0);
  2740. if (waitResult == WAIT_OBJECT_0) {
  2741. // the thread is done
  2742. ANIMATE_STOP(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2743. ANIMATE_CLOSE(hwndDlg,IDC_DIRECTCABLE_WAIT_ANIMATE);
  2744. EndDialog(hwndDlg, FALSE);
  2745. }
  2746. break;
  2747. }
  2748. }
  2749. }
  2750. return 0;
  2751. }
  2752. DWORD WINAPI _DetectPortThread (LPVOID lpParam)
  2753. {
  2754. PDIRECTCABLE_DATA directCableData;
  2755. HANDLE comHandle = INVALID_HANDLE_VALUE;
  2756. DIRECTSEND_DATA sendData;
  2757. DIRECTSEND_DATA receiveData;
  2758. HANDLE event = NULL;
  2759. BOOL result = FALSE;
  2760. directCableData = (PDIRECTCABLE_DATA) lpParam;
  2761. if (directCableData) {
  2762. // let's set the termination event
  2763. event = directCableData->Event;
  2764. sendData.Signature = DIRECTTR_SIG;
  2765. // open the COM port and set the timeout and speed
  2766. comHandle = UIOpenAndSetPort (directCableData->PortName, &(sendData.MaxSpeed));
  2767. if (comHandle) {
  2768. // send the message to the COM port
  2769. if (g_fOldComputer) {
  2770. if (UISendBlockToHandle (comHandle, (PCBYTE)(&sendData), directCableData->Event)) {
  2771. if (UIReceiveBlockFromHandle (comHandle, (PBYTE)(&receiveData), directCableData->Event)) {
  2772. if (sendData.Signature == receiveData.Signature) {
  2773. result = TRUE;
  2774. directCableData->Valid = TRUE;
  2775. directCableData->PortSpeed = min (sendData.MaxSpeed, receiveData.MaxSpeed);
  2776. }
  2777. }
  2778. }
  2779. } else {
  2780. if (UIReceiveBlockFromHandle (comHandle, (PBYTE)(&receiveData), directCableData->Event)) {
  2781. if (UISendBlockToHandle (comHandle, (PCBYTE)(&sendData), directCableData->Event)) {
  2782. if (sendData.Signature == receiveData.Signature) {
  2783. result = TRUE;
  2784. directCableData->Valid = TRUE;
  2785. directCableData->PortSpeed = min (sendData.MaxSpeed, receiveData.MaxSpeed);
  2786. }
  2787. }
  2788. }
  2789. }
  2790. CloseHandle (comHandle);
  2791. comHandle = INVALID_HANDLE_VALUE;
  2792. }
  2793. }
  2794. if ((!result) && event) {
  2795. // we failed, let's wait until the master tells us to quit
  2796. WaitForSingleObject (event, INFINITE);
  2797. }
  2798. ExitThread (0);
  2799. }
  2800. DWORD WINAPI _AutoDetectThread (LPVOID lpParam)
  2801. {
  2802. PAUTODETECT_DATA autoDetectData = NULL;
  2803. PCTSTR comPort = NULL;
  2804. UINT numPorts = 0;
  2805. PHANDLE threadArray;
  2806. PDIRECTCABLE_DATA directCableArray;
  2807. UINT index = 0;
  2808. DWORD threadId;
  2809. DWORD waitResult;
  2810. autoDetectData = (PAUTODETECT_DATA) lpParam;
  2811. if (!autoDetectData) {
  2812. return FALSE;
  2813. }
  2814. if (!autoDetectData->DirectCableData) {
  2815. return FALSE;
  2816. }
  2817. autoDetectData->DirectCableData->Valid = FALSE;
  2818. if (!autoDetectData->hwndCombo) {
  2819. return FALSE;
  2820. }
  2821. numPorts = SendMessage (autoDetectData->hwndCombo, CB_GETCOUNT, 0, 0);
  2822. if (numPorts) {
  2823. threadArray = (PHANDLE)LocalAlloc(LPTR, numPorts * sizeof(HANDLE));
  2824. if (threadArray) {
  2825. directCableArray = (PDIRECTCABLE_DATA)LocalAlloc(LPTR, numPorts * sizeof(DIRECTCABLE_DATA));
  2826. if (directCableArray) {
  2827. // let's start the threads, one for every port.
  2828. index = 0;
  2829. while (index < numPorts) {
  2830. comPort = NULL;
  2831. comPort = (PCTSTR)SendMessage (autoDetectData->hwndCombo, CB_GETITEMDATA, (WPARAM)index, 0);
  2832. directCableArray [index].Valid = FALSE;
  2833. directCableArray [index].PortName = comPort;
  2834. directCableArray [index].PortSpeed = 0;
  2835. directCableArray [index].Event = autoDetectData->DirectCableData->Event;
  2836. threadArray [index] = CreateThread (
  2837. NULL,
  2838. 0,
  2839. _DetectPortThread,
  2840. &(directCableArray [index]),
  2841. 0,
  2842. &threadId
  2843. );
  2844. index ++;
  2845. }
  2846. // let's wait for at least one thread to finish
  2847. waitResult = WaitForMultipleObjects (numPorts, threadArray, FALSE, INFINITE);
  2848. index = waitResult - WAIT_OBJECT_0;
  2849. if ((index < numPorts) && (!pIsEventSet (&(autoDetectData->DirectCableData->Event)))) {
  2850. // probably a good com port
  2851. autoDetectData->DirectCableData->Valid = directCableArray [index].Valid;
  2852. autoDetectData->DirectCableData->PortName = directCableArray [index].PortName;
  2853. autoDetectData->DirectCableData->PortSpeed = directCableArray [index].PortSpeed;
  2854. }
  2855. // we found the thread, now let's signal the event and wait for all threads to finish
  2856. pSetEvent (&(autoDetectData->DirectCableData->Event));
  2857. WaitForMultipleObjects (numPorts, threadArray, TRUE, INFINITE);
  2858. // let's close all thread handles
  2859. index = 0;
  2860. while (index < numPorts) {
  2861. CloseHandle (threadArray [index]);
  2862. index ++;
  2863. }
  2864. LocalFree (directCableArray);
  2865. } else {
  2866. LocalFree (threadArray);
  2867. return FALSE;
  2868. }
  2869. LocalFree (threadArray);
  2870. } else {
  2871. return FALSE;
  2872. }
  2873. }
  2874. return TRUE;
  2875. }
  2876. INT_PTR CALLBACK _DirectCableDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2877. {
  2878. static INT iSelectedPort = -1; // Which COM port is selected
  2879. INT lastPort;
  2880. HWND hwndCombo;
  2881. DIRECTCABLE_DATA directCableData;
  2882. AUTODETECT_DATA autoDetectData;
  2883. HANDLE threadHandle;
  2884. DWORD threadId;
  2885. DWORD waitResult;
  2886. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK, FALSE, 0);
  2887. switch (uMsg)
  2888. {
  2889. case WM_INITDIALOG:
  2890. // If Wiz95 layout...
  2891. if (g_migwiz->GetOldStyle())
  2892. {
  2893. _OldStylify(hwndDlg, IDS_DIRECTCABLETITLE);
  2894. }
  2895. break;
  2896. case WM_COMMAND:
  2897. switch (LOWORD(wParam))
  2898. {
  2899. case IDC_DIRECTC_COMSELECT:
  2900. if (HIWORD(wParam) == CBN_SELCHANGE) {
  2901. // clear the error or success area
  2902. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_HIDE);
  2903. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_HIDE);
  2904. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_HIDE);
  2905. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_HIDE);
  2906. // see if the combo box has a real COM port selected. If yes, enable the Next Button
  2907. hwndCombo = GetDlgItem(hwndDlg, IDC_DIRECTC_COMSELECT);
  2908. lastPort = iSelectedPort;
  2909. iSelectedPort = ComboBox_GetCurSel (hwndCombo);
  2910. if (iSelectedPort >= 0) {
  2911. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  2912. }
  2913. if (lastPort != iSelectedPort) {
  2914. // clear the store, we need to revalidate the COM port
  2915. g_szStore [0] = 0;
  2916. }
  2917. }
  2918. break;
  2919. case IDC_DIRECTC_AUTO:
  2920. // clear the error or success area
  2921. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_HIDE);
  2922. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_HIDE);
  2923. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_HIDE);
  2924. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_HIDE);
  2925. hwndCombo = GetDlgItem(hwndDlg, IDC_DIRECTC_COMSELECT);
  2926. ZeroMemory (&directCableData, sizeof (DIRECTCABLE_DATA));
  2927. directCableData.Event = CreateEvent (NULL, TRUE, FALSE, NULL);
  2928. autoDetectData.hwndCombo = hwndCombo;
  2929. autoDetectData.DirectCableData = &directCableData;
  2930. // Start the connection thread
  2931. threadHandle = CreateThread (NULL, 0, _AutoDetectThread, &autoDetectData, 0, &threadId);
  2932. directCableData.Thread = threadHandle;
  2933. // Start the Please wait dialog
  2934. DialogBoxParam (
  2935. g_migwiz->GetInstance(),
  2936. MAKEINTRESOURCE(IDD_DIRECTCABLE_WAIT),
  2937. g_hwndCurrent,
  2938. _DirectCableWaitDlgProc,
  2939. (LPARAM)(&directCableData)
  2940. );
  2941. pSetEvent (&(directCableData.Event));
  2942. // wait for the thread to finish
  2943. waitResult = WaitForSingleObject (threadHandle, INFINITE);
  2944. // Close thread handle
  2945. CloseHandle (threadHandle);
  2946. // Verify that the connection worked
  2947. if (directCableData.Valid && directCableData.PortName) {
  2948. // select the appropriate com port in the drop-down list
  2949. UINT numPorts;
  2950. UINT index = 0;
  2951. PCTSTR comPort = NULL;
  2952. numPorts = SendMessage (hwndCombo, CB_GETCOUNT, 0, 0);
  2953. if (numPorts) {
  2954. while (index < numPorts) {
  2955. comPort = (LPTSTR)ComboBox_GetItemData (hwndCombo, index);
  2956. if (_tcsicmp (comPort, directCableData.PortName) == 0) {
  2957. break;
  2958. }
  2959. index ++;
  2960. }
  2961. }
  2962. ComboBox_SetCurSel (hwndCombo, index);
  2963. iSelectedPort = index;
  2964. // build the transport string
  2965. if (directCableData.PortSpeed) {
  2966. wsprintf (g_szStore, TEXT("%s:%u"), directCableData.PortName, directCableData.PortSpeed);
  2967. } else {
  2968. wsprintf (g_szStore, TEXT("%s"), directCableData.PortName);
  2969. }
  2970. // write the success in the error/success area
  2971. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_SHOW);
  2972. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_SHOW);
  2973. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_HIDE);
  2974. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_HIDE);
  2975. // enable the Next button
  2976. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  2977. } else {
  2978. // clear the transport string
  2979. g_szStore [0] = 0;
  2980. // write the failure in the error/success area
  2981. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_HIDE);
  2982. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_HIDE);
  2983. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_SHOW);
  2984. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_SHOW);
  2985. // preserve the state of the Next button
  2986. }
  2987. break;
  2988. }
  2989. break;
  2990. case WM_NOTIFY :
  2991. {
  2992. switch (((LPNMHDR)lParam)->code)
  2993. {
  2994. case PSN_QUERYCANCEL:
  2995. return _HandleCancel(hwndDlg, FALSE, FALSE);
  2996. break;
  2997. case PSN_WIZBACK:
  2998. if (g_fOldComputer) {
  2999. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKCOLLECTSTORE);
  3000. } else {
  3001. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKAPPLYSTORE);
  3002. }
  3003. return TRUE;
  3004. break;
  3005. case PSN_WIZNEXT:
  3006. if (g_fUberCancel)
  3007. {
  3008. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  3009. }
  3010. else {
  3011. // run the COM port test, if we haven't done it already
  3012. if (!g_szStore [0]) {
  3013. // clear the error or success area
  3014. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_HIDE);
  3015. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_HIDE);
  3016. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_HIDE);
  3017. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_HIDE);
  3018. // Get the COM port from the IDC_DIRECTC_COMSELECT
  3019. hwndCombo = GetDlgItem(hwndDlg, IDC_DIRECTC_COMSELECT);
  3020. iSelectedPort = ComboBox_GetCurSel (hwndCombo);
  3021. directCableData.Valid = FALSE;
  3022. directCableData.PortName = (LPTSTR)ComboBox_GetItemData (hwndCombo, iSelectedPort);
  3023. directCableData.PortSpeed = 0;
  3024. directCableData.Event = CreateEvent (NULL, TRUE, FALSE, NULL);
  3025. // Start the connection thread
  3026. threadHandle = CreateThread (NULL, 0, _DirectCableConnectThread, &directCableData, 0, &threadId);
  3027. directCableData.Thread = threadHandle;
  3028. // Start the Please wait dialog
  3029. DialogBoxParam (
  3030. g_migwiz->GetInstance(),
  3031. MAKEINTRESOURCE(IDD_DIRECTCABLE_WAIT),
  3032. g_hwndCurrent,
  3033. _DirectCableWaitDlgProc,
  3034. (LPARAM)(&directCableData)
  3035. );
  3036. pSetEvent (&(directCableData.Event));
  3037. // wait for the thread to finish
  3038. waitResult = WaitForSingleObject (threadHandle, INFINITE);
  3039. // Close thread handle
  3040. CloseHandle (threadHandle);
  3041. // Verify that the connection worked
  3042. if (directCableData.Valid) {
  3043. // build the transport string
  3044. if (directCableData.PortSpeed) {
  3045. wsprintf (g_szStore, TEXT("%s:%u"), directCableData.PortName, directCableData.PortSpeed);
  3046. } else {
  3047. wsprintf (g_szStore, TEXT("%s"), directCableData.PortName);
  3048. }
  3049. // write the success in the error/success area
  3050. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_SHOW);
  3051. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_SHOW);
  3052. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_HIDE);
  3053. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_HIDE);
  3054. // enable the Next button
  3055. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  3056. } else {
  3057. // clear the transport string
  3058. g_szStore [0] = 0;
  3059. // write the failure in the error/success area
  3060. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_SUCCESSTEXT), SW_HIDE);
  3061. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONYES), SW_HIDE);
  3062. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_FAILURETEXT), SW_SHOW);
  3063. ShowWindow(GetDlgItem(hwndDlg, IDC_DIRECTCABLE_ICONNO), SW_SHOW);
  3064. // preserve the state of the Next button
  3065. // refuse the Next advance
  3066. SetWindowLong(hwndDlg, DWLP_MSGRESULT, -1);
  3067. return -1;
  3068. }
  3069. }
  3070. if (g_fOldComputer) {
  3071. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKMETHOD);
  3072. } else {
  3073. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS);
  3074. }
  3075. }
  3076. return TRUE;
  3077. break;
  3078. case PSN_SETACTIVE:
  3079. g_fCustomize = FALSE;
  3080. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
  3081. // let's build the list of COM ports
  3082. iSelectedPort = _ComboBoxEx_AddCOMPorts (GetDlgItem(hwndDlg, IDC_DIRECTC_COMSELECT), iSelectedPort);
  3083. Button_Enable (GetDlgItem (hwndDlg, IDC_DIRECTC_COMSELECT), (-1 != iSelectedPort));
  3084. Button_Enable (GetDlgItem (hwndDlg, IDC_DIRECTC_AUTO), (-1 != iSelectedPort));
  3085. // see if the combo box has a real COM port selected. If yes, enable the Next Button
  3086. if (ComboBox_GetCurSel (GetDlgItem(hwndDlg, IDC_DIRECTC_COMSELECT)) >= 0) {
  3087. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  3088. } else {
  3089. iSelectedPort = -1;
  3090. }
  3091. break;
  3092. }
  3093. }
  3094. break;
  3095. case WM_USER_CANCEL_PENDING:
  3096. g_fUberCancel = TRUE;
  3097. pSetEvent (&g_TerminateEvent);
  3098. _NextWizardPage (hwndDlg);
  3099. break;
  3100. }
  3101. return 0;
  3102. }
  3103. ///////////////////////////////////////////////////////////////
  3104. void _PickMethodDlgProc_Prepare(HWND hwndTree, UINT uiRadio, UINT uiSel, PUINT puiLast, PUINT pselLast)
  3105. {
  3106. if ((uiSel != -1) && (*pselLast == uiSel) && (*puiLast == uiRadio)) {
  3107. return;
  3108. }
  3109. switch (uiSel)
  3110. {
  3111. case 0:
  3112. g_migwiz->SelectComponentSet(MIGINF_SELECT_SETTINGS);
  3113. break;
  3114. case 1:
  3115. g_migwiz->SelectComponentSet(MIGINF_SELECT_FILES);
  3116. break;
  3117. case 2:
  3118. g_migwiz->SelectComponentSet(MIGINF_SELECT_BOTH);
  3119. break;
  3120. }
  3121. __PopulateFilesDocumentsCollected(hwndTree, uiRadio);
  3122. *puiLast = uiRadio;
  3123. *pselLast = uiSel;
  3124. g_uChosenComponent = uiRadio;
  3125. }
  3126. INT_PTR CALLBACK _PickMethodDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3127. {
  3128. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  3129. static UINT uiLast = (UINT) -1;
  3130. static UINT selLast = (UINT) -1;
  3131. UINT uiSet;
  3132. switch (uMsg)
  3133. {
  3134. case WM_INITDIALOG:
  3135. HANDLE hBitmap;
  3136. // If Wiz95 layout...
  3137. if (g_migwiz->GetOldStyle())
  3138. {
  3139. _OldStylify(hwndDlg, IDS_PICKMETHODTITLE);
  3140. }
  3141. // Display the mini exclamation mark
  3142. hBitmap = LoadImage(g_migwiz->GetInstance(),
  3143. MAKEINTRESOURCE(IDB_SMEXCLAMATION),
  3144. IMAGE_BITMAP,
  3145. 0, 0,
  3146. LR_LOADTRANSPARENT | LR_SHARED | LR_LOADMAP3DCOLORS);
  3147. SendDlgItemMessage(hwndDlg, IDC_PICKMETHOD_WARNINGICON, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);
  3148. TreeView_SetBkColor(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TREE), GetSysColor(COLOR_3DFACE));
  3149. break;
  3150. case WM_COMMAND:
  3151. switch (LOWORD(wParam))
  3152. {
  3153. case IDC_PICKMETHOD_RADIO1:
  3154. _PickMethodDlgProc_Prepare(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TREE), 0, 0, &uiLast, &selLast);
  3155. break;
  3156. case IDC_PICKMETHOD_RADIO2:
  3157. _PickMethodDlgProc_Prepare(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TREE), 1, 1, &uiLast, &selLast);
  3158. break;
  3159. case IDC_PICKMETHOD_RADIO3:
  3160. _PickMethodDlgProc_Prepare(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TREE), 2, 2, &uiLast, &selLast);
  3161. break;
  3162. case IDC_PICKMETHOD_CUSTOMIZE:
  3163. if (!Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_CUSTOMIZE))) {
  3164. _PickMethodDlgProc_Prepare(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TREE), uiLast, uiLast, &uiLast, &selLast);
  3165. }
  3166. break;
  3167. }
  3168. break;
  3169. case WM_NOTIFY :
  3170. {
  3171. switch (((LPNMHDR)lParam)->code)
  3172. {
  3173. case PSN_QUERYCANCEL:
  3174. return _HandleCancel(hwndDlg, FALSE, FALSE);
  3175. break;
  3176. case PSN_WIZBACK:
  3177. if (g_fStoreToCable) {
  3178. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DIRECTCABLE);
  3179. } else {
  3180. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKCOLLECTSTORE);
  3181. }
  3182. return TRUE;
  3183. break;
  3184. case PSN_WIZNEXT:
  3185. if (g_fUberCancel)
  3186. {
  3187. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  3188. }
  3189. else if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_CUSTOMIZE)))
  3190. {
  3191. g_fCustomize = TRUE;
  3192. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_CUSTOMIZE);
  3193. }
  3194. else if (GetAppsToInstall() == TRUE)
  3195. {
  3196. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPINSTALL);
  3197. }
  3198. else
  3199. {
  3200. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_COLLECTPROGRESS);
  3201. }
  3202. return TRUE;
  3203. break;
  3204. case PSN_SETACTIVE:
  3205. g_fCustomize = FALSE;
  3206. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  3207. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_RADIO1), BST_UNCHECKED);
  3208. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_RADIO2), BST_UNCHECKED);
  3209. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_RADIO3), BST_UNCHECKED);
  3210. ShowWindow(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TEXT2), (g_fStoreToFloppy ? SW_SHOW : SW_HIDE));
  3211. ShowWindow(GetDlgItem(hwndDlg, IDC_PICKMETHOD_WARNINGICON), (g_fStoreToFloppy ? SW_SHOW : SW_HIDE));
  3212. if (g_fPickMethodReset == TRUE || uiLast == (UINT) -1)
  3213. {
  3214. // Always refresh the tree
  3215. uiLast = -1;
  3216. uiSet = g_fStoreToFloppy ? 0 : 2;
  3217. g_fPickMethodReset = FALSE;
  3218. }
  3219. else
  3220. {
  3221. uiSet = uiLast;
  3222. }
  3223. switch (uiSet)
  3224. {
  3225. case 0:
  3226. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_RADIO1), BST_CHECKED);
  3227. break;
  3228. case 1:
  3229. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_RADIO2), BST_CHECKED);
  3230. break;
  3231. case 2:
  3232. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKMETHOD_RADIO3), BST_CHECKED);
  3233. break;
  3234. }
  3235. _PickMethodDlgProc_Prepare(GetDlgItem(hwndDlg, IDC_PICKMETHOD_TREE), uiSet, g_fCustomizeComp?-1:uiSet, &uiLast, &selLast);
  3236. break;
  3237. case TVN_ITEMEXPANDINGA:
  3238. case TVN_ITEMEXPANDINGW:
  3239. // Disable selecting and expand/compress
  3240. SetWindowLong(hwndDlg, DWLP_MSGRESULT, TRUE);
  3241. return TRUE;
  3242. break;
  3243. case NM_CUSTOMDRAW:
  3244. {
  3245. LPNMTVCUSTOMDRAW lpNMCustomDraw = (LPNMTVCUSTOMDRAW) lParam;
  3246. // Do not allow highlighting of anything in this treeview
  3247. switch (lpNMCustomDraw->nmcd.dwDrawStage)
  3248. {
  3249. case CDDS_PREPAINT:
  3250. SetWindowLong(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
  3251. return CDRF_NOTIFYITEMDRAW;
  3252. break;
  3253. case CDDS_ITEMPREPAINT:
  3254. lpNMCustomDraw->clrText = GetSysColor(COLOR_WINDOWTEXT);
  3255. lpNMCustomDraw->clrTextBk = GetSysColor(COLOR_3DFACE);
  3256. SetWindowLong(hwndDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
  3257. return CDRF_NEWFONT;
  3258. break;
  3259. }
  3260. }
  3261. break;
  3262. }
  3263. }
  3264. break;
  3265. case WM_USER_CANCEL_PENDING:
  3266. g_fUberCancel = TRUE;
  3267. pSetEvent (&g_TerminateEvent);
  3268. _NextWizardPage (hwndDlg);
  3269. break;
  3270. }
  3271. return 0;
  3272. }
  3273. /////////////////////////////////////////////////////////////////////////////////////////////////
  3274. INT_PTR CALLBACK _CustomizeDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3275. {
  3276. static HTREEITEM htiSelected = NULL;
  3277. UINT treeCount = 0;
  3278. UINT rootCount = 0;
  3279. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  3280. HWND hwndTree = GetDlgItem(hwndDlg, IDC_CUSTOMIZE_TREE);
  3281. switch (uMsg)
  3282. {
  3283. case WM_INITDIALOG:
  3284. // If Wiz95 layout...
  3285. if (g_migwiz->GetOldStyle())
  3286. {
  3287. _OldStylify(hwndDlg, IDS_CUSTOMIZETITLE);
  3288. }
  3289. break;
  3290. case WM_COMMAND:
  3291. switch (LOWORD(wParam))
  3292. {
  3293. case IDC_CUSTOMIZE_ADDFOLDERS:
  3294. _AddFolder(hwndDlg, hwndTree);
  3295. // Hack to hide shell bug#309872
  3296. RedrawWindow(hwndTree, NULL, NULL, RDW_INVALIDATE | RDW_ERASENOW);
  3297. break;
  3298. case IDC_CUSTOMIZE_ADDTYPES:
  3299. _ExclusiveDialogBox(g_migwiz->GetInstance(),
  3300. MAKEINTRESOURCE(IDD_FILETYPEPICKER),
  3301. hwndDlg,
  3302. _FileTypeDlgProc);
  3303. // Hack to hide shell bug#309872
  3304. RedrawWindow(hwndTree, NULL, NULL, RDW_INVALIDATE | RDW_ERASENOW);
  3305. break;
  3306. case IDC_CUSTOMIZE_ADDSETTING:
  3307. _ExclusiveDialogBox(g_migwiz->GetInstance(),
  3308. MAKEINTRESOURCE(IDD_SETTINGPICKER),
  3309. hwndDlg,
  3310. _SettingDlgProc);
  3311. // Hack to hide shell bug#309872
  3312. RedrawWindow(hwndTree, NULL, NULL, RDW_INVALIDATE | RDW_ERASENOW);
  3313. break;
  3314. case IDC_CUSTOMIZE_ADDFILE:
  3315. _AddFile(hwndDlg, hwndTree);
  3316. // Hack to hide shell bug#309872
  3317. RedrawWindow(hwndTree, NULL, NULL, RDW_INVALIDATE | RDW_ERASENOW);
  3318. break;
  3319. case IDC_CUSTOMIZE_REMOVE:
  3320. if (htiSelected != g_htiFiles &&
  3321. htiSelected != g_htiFolders &&
  3322. htiSelected != g_htiTypes &&
  3323. htiSelected != g_htiSettings)
  3324. {
  3325. TVITEM item = {0};
  3326. HTREEITEM htiParent;
  3327. item.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
  3328. item.hItem = htiSelected;
  3329. TCHAR szText[MAX_PATH];
  3330. item.pszText = szText;
  3331. item.cchTextMax = ARRAYSIZE(szText);
  3332. if (TreeView_GetItem(hwndTree, &item))
  3333. {
  3334. if (item.lParam)
  3335. {
  3336. LV_DATASTRUCT* plvds = (LV_DATASTRUCT*)item.lParam;
  3337. // first disable the ISM component
  3338. htiParent = TreeView_GetParent(hwndTree, htiSelected);
  3339. if (htiParent == g_htiFiles) {
  3340. IsmSelectComponent (item.pszText, COMPONENT_FILE, FALSE);
  3341. } else if (htiParent == g_htiFolders) {
  3342. IsmSelectComponent (
  3343. plvds->pszPureName ? plvds->pszPureName : item.pszText,
  3344. COMPONENT_FOLDER,
  3345. FALSE
  3346. );
  3347. } else if (htiParent == g_htiTypes) {
  3348. IsmSelectComponent (
  3349. plvds->pszPureName ? plvds->pszPureName : item.pszText,
  3350. COMPONENT_EXTENSION,
  3351. FALSE
  3352. );
  3353. } else if (htiParent == g_htiSettings) {
  3354. IsmSelectComponent (item.pszText, COMPONENT_NAME, FALSE);
  3355. }
  3356. // second delete the memory associated with the item
  3357. if (plvds->pszPureName)
  3358. {
  3359. LocalFree(plvds->pszPureName);
  3360. }
  3361. LocalFree(plvds);
  3362. // if the user hits BACK we will remember that the user customized stuff
  3363. g_fCustomizeComp = TRUE;
  3364. }
  3365. }
  3366. // third, delete the item itself
  3367. TreeView_DeleteItem(hwndTree, htiSelected);
  3368. }
  3369. break;
  3370. }
  3371. rootCount = 0;
  3372. if (g_htiFolders)
  3373. {
  3374. rootCount ++;
  3375. }
  3376. if (g_htiFiles)
  3377. {
  3378. rootCount ++;
  3379. }
  3380. if (g_htiSettings)
  3381. {
  3382. rootCount ++;
  3383. }
  3384. if (g_htiTypes)
  3385. {
  3386. rootCount ++;
  3387. }
  3388. treeCount = TreeView_GetCount (hwndTree);
  3389. if (treeCount <= rootCount)
  3390. {
  3391. // Disable the NEXT button
  3392. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
  3393. }
  3394. else
  3395. {
  3396. // Enable the NEXT button
  3397. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  3398. }
  3399. break;
  3400. case WM_NOTIFY :
  3401. {
  3402. switch (((LPNMHDR)lParam)->code)
  3403. {
  3404. case PSN_SETACTIVE:
  3405. {
  3406. __PopulateFilesDocumentsCollected(hwndTree, g_uChosenComponent);
  3407. rootCount = 0;
  3408. if (g_htiFolders)
  3409. {
  3410. rootCount ++;
  3411. }
  3412. if (g_htiFiles)
  3413. {
  3414. rootCount ++;
  3415. }
  3416. if (g_htiSettings)
  3417. {
  3418. rootCount ++;
  3419. }
  3420. if (g_htiTypes)
  3421. {
  3422. rootCount ++;
  3423. }
  3424. if (TreeView_GetCount (hwndTree) <= rootCount)
  3425. {
  3426. // Disable the NEXT button
  3427. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
  3428. }
  3429. else
  3430. {
  3431. // Enable the NEXT button
  3432. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  3433. }
  3434. break;
  3435. }
  3436. case PSN_QUERYCANCEL:
  3437. return _HandleCancel(hwndDlg, FALSE, FALSE);
  3438. break;
  3439. case PSN_WIZBACK:
  3440. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKMETHOD);
  3441. return TRUE;
  3442. break;
  3443. case PSN_WIZNEXT:
  3444. if (g_fUberCancel)
  3445. {
  3446. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  3447. }
  3448. else if (GetAppsToInstall() == TRUE)
  3449. {
  3450. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPINSTALL);
  3451. }
  3452. else
  3453. {
  3454. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_COLLECTPROGRESS);
  3455. }
  3456. return TRUE;
  3457. break;
  3458. case TVN_ITEMEXPANDINGA:
  3459. case TVN_ITEMEXPANDINGW:
  3460. return TRUE;
  3461. break;
  3462. case TVN_SELCHANGED:
  3463. {
  3464. htiSelected = ((NM_TREEVIEW*)lParam)->itemNew.hItem;
  3465. if (htiSelected == NULL ||
  3466. htiSelected == g_htiFiles ||
  3467. htiSelected == g_htiFolders ||
  3468. htiSelected == g_htiTypes ||
  3469. htiSelected == g_htiSettings)
  3470. {
  3471. // Disable the REMOVE key
  3472. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOMIZE_REMOVE), FALSE);
  3473. }
  3474. else
  3475. {
  3476. // Enable the REMOVE key
  3477. Button_Enable(GetDlgItem(hwndDlg, IDC_CUSTOMIZE_REMOVE), TRUE);
  3478. }
  3479. }
  3480. break;
  3481. }
  3482. break;
  3483. }
  3484. case WM_USER_CANCEL_PENDING:
  3485. g_fUberCancel = TRUE;
  3486. pSetEvent (&g_TerminateEvent);
  3487. _NextWizardPage (hwndDlg);
  3488. break;
  3489. }
  3490. return 0;
  3491. }
  3492. ///////////////////////////////////////////////////////////////
  3493. int CALLBACK
  3494. PickCollectCallback (
  3495. HWND hwnd,
  3496. UINT uMsg,
  3497. LPARAM lParam,
  3498. LPARAM lpData
  3499. )
  3500. {
  3501. HRESULT hr = S_OK;
  3502. TCHAR tszFolderName[MAX_PATH];
  3503. IMalloc *mallocFn = NULL;
  3504. IShellFolder *psfParent = NULL;
  3505. IShellLink *pslLink = NULL;
  3506. LPCITEMIDLIST pidl;
  3507. LPCITEMIDLIST pidlRelative = NULL;
  3508. LPITEMIDLIST pidlReal = NULL;
  3509. if (uMsg == BFFM_SELCHANGED) {
  3510. hr = SHGetMalloc (&mallocFn);
  3511. if (!SUCCEEDED (hr)) {
  3512. mallocFn = NULL;
  3513. }
  3514. pidl = (LPCITEMIDLIST) lParam;
  3515. pidlReal = NULL;
  3516. if (pidl) {
  3517. hr = OurSHBindToParent (pidl, IID_IShellFolder, (void **)&psfParent, &pidlRelative);
  3518. if (SUCCEEDED(hr)) {
  3519. hr = psfParent->GetUIObjectOf (hwnd, 1, &pidlRelative, IID_IShellLink, NULL, (void **)&pslLink);
  3520. if (SUCCEEDED(hr)) {
  3521. hr = pslLink->GetIDList (&pidlReal);
  3522. if (!SUCCEEDED(hr)) {
  3523. pidlReal = NULL;
  3524. }
  3525. pslLink->Release ();
  3526. }
  3527. pidlRelative = NULL;
  3528. psfParent->Release ();
  3529. }
  3530. if (SHGetPathFromIDList(pidlReal?pidlReal:pidl, tszFolderName))
  3531. {
  3532. if (tszFolderName[0] == 0) {
  3533. SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
  3534. }
  3535. } else {
  3536. SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
  3537. }
  3538. if (pidlReal) {
  3539. if (mallocFn) {
  3540. mallocFn->Free ((void *)pidlReal);
  3541. }
  3542. pidlReal = NULL;
  3543. }
  3544. }
  3545. if (mallocFn) {
  3546. mallocFn->Release ();
  3547. mallocFn = NULL;
  3548. }
  3549. }
  3550. return 0;
  3551. }
  3552. INT_PTR CALLBACK _PickCollectStoreDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3553. {
  3554. static UINT uiSelected = 0;
  3555. static INT iSelectedDrive = -1; // Which removeable media drive is selected
  3556. BOOL imageIsValid;
  3557. BOOL imageExists;
  3558. TCHAR szTitle[MAX_LOADSTRING];
  3559. TCHAR szLoadString[MAX_LOADSTRING];
  3560. HRESULT hr = E_FAIL;
  3561. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_NEXT, FALSE, 0);
  3562. switch (uMsg)
  3563. {
  3564. case WM_INITDIALOG:
  3565. // If Wiz95 layout...
  3566. if (g_migwiz->GetOldStyle())
  3567. {
  3568. _OldStylify(hwndDlg, IDS_PICKCOLLECTSTORETITLE);
  3569. }
  3570. break;
  3571. case WM_COMMAND:
  3572. switch (LOWORD(wParam))
  3573. {
  3574. case IDC_PICKCOLLECTSTORE_RADIO1:
  3575. // Direct cable
  3576. case IDC_PICKCOLLECTSTORE_RADIO2:
  3577. // Network
  3578. // Disable Browse button
  3579. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), FALSE);
  3580. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), FALSE);
  3581. // Disable the edit box
  3582. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), FALSE);
  3583. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), TRUE);
  3584. // Disable the drive selector
  3585. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), FALSE);
  3586. break;
  3587. case IDC_PICKCOLLECTSTORE_RADIO3:
  3588. // Floppy
  3589. // Disable Browse button
  3590. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), FALSE);
  3591. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), FALSE);
  3592. // Disable the edit box
  3593. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), FALSE);
  3594. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), TRUE);
  3595. // Enable the drive selector
  3596. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), TRUE);
  3597. break;
  3598. case IDC_PICKCOLLECTSTORE_RADIO4:
  3599. {
  3600. // Other
  3601. // Enable the Browse button
  3602. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), TRUE);
  3603. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), TRUE);
  3604. // Enable the edit box
  3605. HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT);
  3606. Edit_Enable(hwndEdit, TRUE);
  3607. Edit_SetReadOnly(hwndEdit, FALSE);
  3608. Edit_LimitText(hwndEdit, MAX_PATH - PATH_SAFETY_CHARS);
  3609. // Disable the drive selector
  3610. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), FALSE);
  3611. break;
  3612. }
  3613. case IDC_PICKCOLLECTSTORE_BROWSE:
  3614. {
  3615. HRESULT hr = S_OK;
  3616. IMalloc *mallocFn = NULL;
  3617. IShellFolder *psfParent = NULL;
  3618. IShellLink *pslLink = NULL;
  3619. LPCITEMIDLIST pidl;
  3620. LPCITEMIDLIST pidlRelative = NULL;
  3621. LPITEMIDLIST pidlReal = NULL;
  3622. TCHAR szFolder[MAX_PATH];
  3623. TCHAR szPick[MAX_LOADSTRING];
  3624. hr = SHGetMalloc (&mallocFn);
  3625. if (!SUCCEEDED (hr)) {
  3626. mallocFn = NULL;
  3627. }
  3628. LoadString(g_migwiz->GetInstance(), IDS_PICKAFOLDER, szPick, ARRAYSIZE(szPick));
  3629. BROWSEINFO brwsinf = { hwndDlg, NULL, NULL, szPick, BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE, PickCollectCallback, 0, 0 };
  3630. pidl = SHBrowseForFolder(&brwsinf);
  3631. if (pidl)
  3632. {
  3633. hr = OurSHBindToParent (pidl, IID_IShellFolder, (void **)&psfParent, &pidlRelative);
  3634. if (SUCCEEDED(hr)) {
  3635. hr = psfParent->GetUIObjectOf (hwndDlg, 1, &pidlRelative, IID_IShellLink, NULL, (void **)&pslLink);
  3636. if (SUCCEEDED(hr)) {
  3637. hr = pslLink->GetIDList (&pidlReal);
  3638. if (SUCCEEDED(hr)) {
  3639. if (mallocFn) {
  3640. mallocFn->Free ((void *)pidl);
  3641. }
  3642. pidl = pidlReal;
  3643. pidlReal = NULL;
  3644. }
  3645. pslLink->Release ();
  3646. }
  3647. pidlRelative = NULL;
  3648. psfParent->Release ();
  3649. }
  3650. if (SHGetPathFromIDList(pidl, szFolder))
  3651. {
  3652. if (_tcslen(szFolder) > MAX_PATH - PATH_SAFETY_CHARS) {
  3653. TCHAR szTitle[MAX_LOADSTRING];
  3654. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  3655. TCHAR szMsg[MAX_LOADSTRING];
  3656. LoadString(g_migwiz->GetInstance(), IDS_ERROR_PATHTOOLONG, szMsg, ARRAYSIZE(szMsg));
  3657. _ExclusiveMessageBox(hwndDlg, szMsg, szTitle, MB_OK);
  3658. } else {
  3659. SendMessage(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), WM_SETTEXT, 0, (LPARAM)szFolder);
  3660. }
  3661. }
  3662. if (mallocFn) {
  3663. mallocFn->Free ((void *)pidl);
  3664. }
  3665. pidl = NULL;
  3666. }
  3667. if (mallocFn) {
  3668. mallocFn->Release ();
  3669. mallocFn = NULL;
  3670. }
  3671. }
  3672. break;
  3673. }
  3674. break;
  3675. case WM_NOTIFY :
  3676. {
  3677. switch (((LPNMHDR)lParam)->code)
  3678. {
  3679. case PSN_SETACTIVE:
  3680. INT currDrive;
  3681. INT comPort;
  3682. // enable direct cable transport if available
  3683. comPort = _ComboBoxEx_AddCOMPorts (NULL, 0);
  3684. Button_Enable (GetDlgItem (hwndDlg, IDC_PICKCOLLECTSTORE_RADIO1), (-1 != comPort));
  3685. // enable network if present
  3686. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO2), g_fHaveNet);
  3687. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT3), g_fHaveNet);
  3688. // get removable drives list and enable radio if any
  3689. SendMessage(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), CBEM_SETIMAGELIST, 0, (LPARAM)g_migwiz->GetImageList());
  3690. currDrive = _ComboBoxEx_AddDrives (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO));
  3691. Button_Enable (GetDlgItem (hwndDlg, IDC_PICKCOLLECTSTORE_RADIO3), (-1 != currDrive));
  3692. Static_Enable (GetDlgItem (hwndDlg, IDC_PICKCOLLECTSTORE_TEXT2), (-1 != currDrive));
  3693. // set the selected drive if any
  3694. if ((currDrive != -1) && (iSelectedDrive != -1)) {
  3695. ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), iSelectedDrive);
  3696. currDrive = iSelectedDrive;
  3697. }
  3698. if ((uiSelected == 0 || uiSelected == 2) && g_fHaveNet)
  3699. {
  3700. // Home Network
  3701. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO1), BST_UNCHECKED);
  3702. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO2), BST_CHECKED);
  3703. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO3), BST_UNCHECKED);
  3704. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO4), BST_UNCHECKED);
  3705. // disable folder box, browse button
  3706. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), FALSE);
  3707. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), FALSE);
  3708. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), FALSE);
  3709. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), TRUE);
  3710. // Disable the drive selector
  3711. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), FALSE);
  3712. } else if ((uiSelected == 0 || uiSelected == 1) && (-1 != comPort)) {
  3713. // Direct cable
  3714. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO1), BST_CHECKED);
  3715. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO2), BST_UNCHECKED);
  3716. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO3), BST_UNCHECKED);
  3717. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO4), BST_UNCHECKED);
  3718. // disable folder box, browse button
  3719. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), FALSE);
  3720. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), FALSE);
  3721. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), FALSE);
  3722. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), TRUE);
  3723. // Disable the drive selector
  3724. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), FALSE);
  3725. }
  3726. else if ((uiSelected == 0 || uiSelected == 3) && (-1 != currDrive))
  3727. {
  3728. // Floppy
  3729. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO1), BST_UNCHECKED);
  3730. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO2), BST_UNCHECKED);
  3731. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO3), BST_CHECKED);
  3732. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO4), BST_UNCHECKED);
  3733. // disable folder box, browse button
  3734. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), FALSE);
  3735. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), FALSE);
  3736. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), FALSE);
  3737. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), TRUE);
  3738. // Enable the drive selector
  3739. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), TRUE);
  3740. }
  3741. else
  3742. {
  3743. // Other
  3744. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO1), BST_UNCHECKED);
  3745. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO2), BST_UNCHECKED);
  3746. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO3), BST_UNCHECKED);
  3747. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO4), BST_CHECKED);
  3748. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), TRUE);
  3749. // Disable the drive selector
  3750. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO), FALSE);
  3751. // Enable folder box, browse button
  3752. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_BROWSE), TRUE);
  3753. Static_Enable(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_TEXT5), TRUE);
  3754. HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT);
  3755. Edit_Enable(hwndEdit, TRUE);
  3756. Edit_SetReadOnly(hwndEdit, FALSE);
  3757. Edit_LimitText(hwndEdit, MAX_PATH - PATH_SAFETY_CHARS);
  3758. }
  3759. // Reset my globals
  3760. g_szStore[0] = 0;
  3761. break;
  3762. case PSN_QUERYCANCEL:
  3763. return _HandleCancel(hwndDlg, FALSE, FALSE);
  3764. break;
  3765. case PSN_WIZNEXT:
  3766. if (g_fUberCancel)
  3767. {
  3768. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  3769. }
  3770. else
  3771. {
  3772. if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO1))) // direct cable
  3773. {
  3774. g_fStoreToNetwork = FALSE;
  3775. g_fStoreToCable = TRUE;
  3776. if (uiSelected != 1)
  3777. {
  3778. g_fCustomizeComp = FALSE;
  3779. uiSelected = 1;
  3780. }
  3781. }
  3782. else if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO2))) // network
  3783. {
  3784. g_fStoreToNetwork = TRUE;
  3785. g_fStoreToCable = FALSE;
  3786. if (uiSelected != 2)
  3787. {
  3788. g_fCustomizeComp = FALSE;
  3789. uiSelected = 2;
  3790. }
  3791. }
  3792. else if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_RADIO3))) // floppy
  3793. {
  3794. LPTSTR pszDrive;
  3795. TCHAR szFloppyPath[4] = TEXT("A:\\");
  3796. g_fStoreToNetwork = FALSE;
  3797. g_fStoreToCable = FALSE;
  3798. HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_COMBO);
  3799. iSelectedDrive = ComboBox_GetCurSel(hwndCombo);
  3800. pszDrive = (LPTSTR)ComboBox_GetItemData(hwndCombo, iSelectedDrive);
  3801. szFloppyPath[0] = pszDrive[0];
  3802. lstrcpy(g_szStore, szFloppyPath);
  3803. if (uiSelected != 3)
  3804. {
  3805. g_fCustomizeComp = FALSE;
  3806. uiSelected = 3;
  3807. }
  3808. }
  3809. else // other
  3810. {
  3811. TCHAR tsTemp[MAX_PATH + 1];
  3812. g_fStoreToNetwork = FALSE;
  3813. g_fStoreToCable = FALSE;
  3814. SendMessage(GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT), WM_GETTEXT,
  3815. (WPARAM)ARRAYSIZE(tsTemp), (LPARAM)tsTemp);
  3816. if (uiSelected != 4)
  3817. {
  3818. g_fCustomizeComp = FALSE;
  3819. uiSelected = 4;
  3820. }
  3821. CopyStorePath(tsTemp, g_szStore);
  3822. }
  3823. if (g_fStoreToNetwork)
  3824. {
  3825. if (g_fStoreToFloppy) {
  3826. g_fStoreToFloppy = FALSE;
  3827. g_fPickMethodReset = TRUE;
  3828. }
  3829. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKMETHOD);
  3830. return TRUE;
  3831. }
  3832. if (g_fStoreToCable) {
  3833. if (g_fStoreToFloppy) {
  3834. g_fStoreToFloppy = FALSE;
  3835. g_fPickMethodReset = TRUE;
  3836. }
  3837. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DIRECTCABLE);
  3838. return TRUE;
  3839. }
  3840. if (!_IsValidStore(g_szStore, TRUE, g_migwiz->GetInstance(), hwndDlg)) // not a valid directory! stay right here.
  3841. {
  3842. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  3843. LoadString(g_migwiz->GetInstance(), IDS_ENTERDEST, szLoadString, ARRAYSIZE(szLoadString));
  3844. _ExclusiveMessageBox(hwndDlg, szLoadString, szTitle, MB_OK);
  3845. HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT);
  3846. SetFocus(hwndEdit);
  3847. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  3848. SetWindowLong(hwndDlg, DWLP_MSGRESULT, -1);
  3849. return -1;
  3850. }
  3851. hr = Engine_StartTransport (TRUE, g_szStore, &imageIsValid, &imageExists);
  3852. if ((!SUCCEEDED (hr)) || (!imageIsValid)) {
  3853. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  3854. LoadString(g_migwiz->GetInstance(), IDS_ENTERDEST, szLoadString, ARRAYSIZE(szLoadString));
  3855. _ExclusiveMessageBox (hwndDlg, szLoadString, szTitle, MB_OK);
  3856. HWND hwndEdit = GetDlgItem(hwndDlg, IDC_PICKCOLLECTSTORE_EDIT);
  3857. SetFocus(hwndEdit);
  3858. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  3859. SetWindowLong(hwndDlg, DWLP_MSGRESULT, -1);
  3860. return -1;
  3861. }
  3862. BOOL oldFloppy = g_fStoreToFloppy;
  3863. g_fStoreToFloppy = _DriveStrIsFloppy(!g_migwiz->GetWin9X(), g_szStore);
  3864. if (oldFloppy != g_fStoreToFloppy) {
  3865. g_fPickMethodReset = TRUE;
  3866. }
  3867. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKMETHOD);
  3868. }
  3869. return TRUE;
  3870. break;
  3871. }
  3872. break;
  3873. }
  3874. case WM_USER_CANCEL_PENDING:
  3875. g_fUberCancel = TRUE;
  3876. pSetEvent (&g_TerminateEvent);
  3877. _NextWizardPage (hwndDlg);
  3878. break;
  3879. default:
  3880. break;
  3881. }
  3882. return 0;
  3883. }
  3884. ///////////////////////////////////////////////////////////////
  3885. typedef struct {
  3886. HWND hwndProgressBar;
  3887. HWND hwndPropPage;
  3888. } COLLECTPROGRESSSTRUCT;
  3889. DWORD WINAPI _CollectProgressDlgProcThread (LPVOID lpParam)
  3890. {
  3891. COLLECTPROGRESSSTRUCT* pcps = (COLLECTPROGRESSSTRUCT*)lpParam;
  3892. HRESULT hResult;
  3893. BOOL fHasUserCancelled = FALSE;
  3894. hResult = _DoCopy(g_fStoreToNetwork ? NULL : g_szStore, pcps->hwndProgressBar, pcps->hwndPropPage, &fHasUserCancelled);
  3895. if (fHasUserCancelled) {
  3896. hResult = E_FAIL;
  3897. }
  3898. SendMessage (pcps->hwndPropPage, WM_USER_THREAD_COMPLETE, 0, (LPARAM) hResult);
  3899. pSetEvent (&g_TerminateEvent);
  3900. CoTaskMemFree(pcps);
  3901. return 0;
  3902. }
  3903. INT_PTR CALLBACK _CollectProgressDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3904. {
  3905. HRESULT hResult;
  3906. LONG lExStyles;
  3907. HWND hwnd;
  3908. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, 0, FALSE, 0);
  3909. switch (uMsg)
  3910. {
  3911. case WM_INITDIALOG:
  3912. // If Wiz95 layout...
  3913. if (g_migwiz->GetOldStyle())
  3914. {
  3915. _OldStylify(hwndDlg, IDS_COLLECTPROGRESSTITLE);
  3916. }
  3917. // RTL progress bar for RTL dialogs
  3918. lExStyles = GetWindowLong (hwndDlg, GWL_EXSTYLE);
  3919. if (lExStyles & WS_EX_LAYOUTRTL)
  3920. {
  3921. hwnd = GetDlgItem(hwndDlg, IDC_COLLECTPROGRESS_PROGRESS);
  3922. lExStyles = GetWindowLongA(hwnd, GWL_EXSTYLE);
  3923. lExStyles |= WS_EX_LAYOUTRTL; // toggle layout
  3924. SetWindowLongA(hwnd, GWL_EXSTYLE, lExStyles);
  3925. InvalidateRect(hwnd, NULL, TRUE); // redraw
  3926. }
  3927. // Let's set an update timer to 3 sec.
  3928. SetTimer (hwndDlg, 0, 3000, NULL);
  3929. break;
  3930. case WM_USER_FINISHED:
  3931. if (g_migwiz->GetLastResponse() == TRUE) // we didn't cancel to get here
  3932. {
  3933. _NextWizardPage (hwndDlg);
  3934. }
  3935. return TRUE;
  3936. break;
  3937. case WM_USER_CANCELLED:
  3938. g_fUberCancel = TRUE;
  3939. _NextWizardPage (hwndDlg);
  3940. return TRUE;
  3941. break;
  3942. case WM_NOTIFY :
  3943. switch (((LPNMHDR)lParam)->code)
  3944. {
  3945. case PSN_SETACTIVE:
  3946. {
  3947. // blank progress bar
  3948. SendMessage(GetDlgItem(hwndDlg, IDC_COLLECTPROGRESS_PROGRESS), PBM_SETRANGE, 0, 100);
  3949. SendMessage(GetDlgItem(hwndDlg, IDC_COLLECTPROGRESS_PROGRESS), PBM_SETPOS, 0, 0);
  3950. ANIMATE_OPEN(hwndDlg,IDC_PROGRESS_ANIMATE2,IDA_FILECOPY);
  3951. ANIMATE_PLAY(hwndDlg,IDC_PROGRESS_ANIMATE2);
  3952. g_migwiz->ResetLastResponse();
  3953. COLLECTPROGRESSSTRUCT* pcps = (COLLECTPROGRESSSTRUCT*)CoTaskMemAlloc(sizeof(COLLECTPROGRESSSTRUCT));
  3954. if (pcps)
  3955. {
  3956. pcps->hwndProgressBar = GetDlgItem(hwndDlg, IDC_COLLECTPROGRESS_PROGRESS);
  3957. pcps->hwndPropPage = hwndDlg;
  3958. SHCreateThread(_CollectProgressDlgProcThread, pcps, 0, NULL);
  3959. }
  3960. }
  3961. break;
  3962. case PSN_QUERYCANCEL:
  3963. return _HandleCancel(hwndDlg, FALSE, TRUE);
  3964. break;
  3965. case PSN_WIZBACK:
  3966. // ISSUE: we should NEVER get here
  3967. ANIMATE_STOP(hwndDlg,IDC_PROGRESS_ANIMATE2);
  3968. ANIMATE_CLOSE(hwndDlg,IDC_PROGRESS_ANIMATE2);
  3969. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  3970. return TRUE;
  3971. break;
  3972. case PSN_WIZNEXT:
  3973. ANIMATE_STOP(hwndDlg,IDC_PROGRESS_ANIMATE2);
  3974. ANIMATE_CLOSE(hwndDlg,IDC_PROGRESS_ANIMATE2);
  3975. if (g_fUberCancel)
  3976. {
  3977. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  3978. }
  3979. else if (g_migwiz->GetOOBEMode())
  3980. {
  3981. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ENDOOBE);
  3982. }
  3983. else
  3984. {
  3985. SetWindowLong(hwndDlg, DWLP_MSGRESULT, (g_fStoreToNetwork || g_fStoreToCable) ? IDD_ENDCOLLECTNET : IDD_ENDCOLLECT);
  3986. }
  3987. return TRUE;
  3988. break;
  3989. }
  3990. break;
  3991. case WM_USER_CANCEL_PENDING:
  3992. g_fUberCancel = TRUE;
  3993. pResetEvent (&g_TerminateEvent);
  3994. _NextWizardPage (hwndDlg);
  3995. break;
  3996. case WM_USER_THREAD_COMPLETE:
  3997. hResult = (HRESULT) lParam;
  3998. if (FAILED(hResult))
  3999. {
  4000. g_fUberCancel = TRUE;
  4001. }
  4002. _NextWizardPage (hwndDlg);
  4003. break;
  4004. case WM_USER_STATUS:
  4005. case WM_TIMER:
  4006. INT nResult = 0;
  4007. PTSTR szStatusString = NULL;
  4008. TCHAR szTmpStatus[MAX_LOADSTRING];
  4009. PCTSTR nativeObjectName;
  4010. HWND hwndText = GetDlgItem(hwndDlg, IDC_PROGRESS_STATUS);
  4011. // Let's update the status
  4012. EnterCriticalSection(&g_AppInfoCritSection);
  4013. switch (g_AppInfoPhase) {
  4014. case MIG_HIGHPRIORITYQUEUE_PHASE:
  4015. case MIG_HIGHPRIORITYESTIMATE_PHASE:
  4016. case MIG_GATHERQUEUE_PHASE:
  4017. case MIG_GATHERESTIMATE_PHASE:
  4018. case MIG_ANALYSIS_PHASE:
  4019. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_QUEUE, szTmpStatus, MAX_LOADSTRING);
  4020. _UpdateText (hwndText, szTmpStatus);
  4021. break;
  4022. case MIG_HIGHPRIORITYGATHER_PHASE:
  4023. case MIG_GATHER_PHASE:
  4024. if (g_AppInfoObjectTypeId != MIG_FILE_TYPE) {
  4025. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_GATHER1, szTmpStatus, MAX_LOADSTRING);
  4026. _UpdateText (hwndText, szTmpStatus);
  4027. } else {
  4028. nativeObjectName = IsmGetNativeObjectName (g_AppInfoObjectTypeId, g_AppInfoObjectName);
  4029. if (nativeObjectName) {
  4030. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_GATHER2, szTmpStatus, MAX_LOADSTRING);
  4031. if (nResult) {
  4032. FormatMessage (
  4033. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  4034. szTmpStatus,
  4035. 0,
  4036. 0,
  4037. (LPTSTR)&szStatusString,
  4038. 0,
  4039. (va_list *)&nativeObjectName);
  4040. }
  4041. if (szStatusString) {
  4042. _UpdateText (hwndText, szStatusString);
  4043. LocalFree (szStatusString);
  4044. }
  4045. IsmReleaseMemory (nativeObjectName);
  4046. }
  4047. }
  4048. break;
  4049. case MIG_TRANSPORT_PHASE:
  4050. switch (g_AppInfoSubPhase) {
  4051. case SUBPHASE_CONNECTING1:
  4052. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_CONNECTING1, szTmpStatus, MAX_LOADSTRING);
  4053. _UpdateText (hwndText, szTmpStatus);
  4054. break;
  4055. case SUBPHASE_CONNECTING2:
  4056. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_CONNECTING2, szTmpStatus, MAX_LOADSTRING);
  4057. _UpdateText (hwndText, szTmpStatus);
  4058. break;
  4059. case SUBPHASE_NETPREPARING:
  4060. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_NETPREPARING, szTmpStatus, MAX_LOADSTRING);
  4061. _UpdateText (hwndText, szTmpStatus);
  4062. break;
  4063. case SUBPHASE_PREPARING:
  4064. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_PREPARING, szTmpStatus, MAX_LOADSTRING);
  4065. _UpdateText (hwndText, szTmpStatus);
  4066. break;
  4067. case SUBPHASE_COMPRESSING:
  4068. if (g_AppInfoObjectTypeId != MIG_FILE_TYPE) {
  4069. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_PREPARING, szTmpStatus, MAX_LOADSTRING);
  4070. _UpdateText (hwndText, szTmpStatus);
  4071. } else {
  4072. nativeObjectName = IsmGetNativeObjectName (g_AppInfoObjectTypeId, g_AppInfoObjectName);
  4073. if (nativeObjectName) {
  4074. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_COMPRESSING, szTmpStatus, MAX_LOADSTRING);
  4075. if (nResult) {
  4076. FormatMessage (
  4077. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  4078. szTmpStatus,
  4079. 0,
  4080. 0,
  4081. (LPTSTR)&szStatusString,
  4082. 0,
  4083. (va_list *)&nativeObjectName);
  4084. }
  4085. if (szStatusString) {
  4086. _UpdateText (hwndText, szStatusString);
  4087. LocalFree (szStatusString);
  4088. }
  4089. IsmReleaseMemory (nativeObjectName);
  4090. }
  4091. }
  4092. break;
  4093. case SUBPHASE_TRANSPORTING:
  4094. if (g_AppInfoObjectTypeId != MIG_FILE_TYPE) {
  4095. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_PREPARING, szTmpStatus, MAX_LOADSTRING);
  4096. _UpdateText (hwndText, szTmpStatus);
  4097. } else {
  4098. nativeObjectName = IsmGetNativeObjectName (g_AppInfoObjectTypeId, g_AppInfoObjectName);
  4099. if (nativeObjectName) {
  4100. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_TRANSPORTING, szTmpStatus, MAX_LOADSTRING);
  4101. if (nResult) {
  4102. FormatMessage (
  4103. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  4104. szTmpStatus,
  4105. 0,
  4106. 0,
  4107. (LPTSTR)&szStatusString,
  4108. 0,
  4109. (va_list *)&nativeObjectName);
  4110. }
  4111. if (szStatusString) {
  4112. _UpdateText (hwndText, szStatusString);
  4113. LocalFree (szStatusString);
  4114. }
  4115. IsmReleaseMemory (nativeObjectName);
  4116. }
  4117. }
  4118. break;
  4119. case SUBPHASE_MEDIAWRITING:
  4120. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_MEDIAWRITING, szTmpStatus, MAX_LOADSTRING);
  4121. _UpdateText (hwndText, szTmpStatus);
  4122. break;
  4123. case SUBPHASE_FINISHING:
  4124. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_FINISHING, szTmpStatus, MAX_LOADSTRING);
  4125. _UpdateText (hwndText, szTmpStatus);
  4126. break;
  4127. case SUBPHASE_CABLETRANS:
  4128. if (g_AppInfoText) {
  4129. _UpdateText (hwndText, g_AppInfoText);
  4130. }
  4131. break;
  4132. default:
  4133. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_PREPARING, szTmpStatus, MAX_LOADSTRING);
  4134. _UpdateText (hwndText, szTmpStatus);
  4135. break;
  4136. }
  4137. break;
  4138. default:
  4139. break;
  4140. }
  4141. LeaveCriticalSection(&g_AppInfoCritSection);
  4142. break;
  4143. }
  4144. return 0;
  4145. }
  4146. ///////////////////////////////////////////////////////////////
  4147. typedef struct {
  4148. HWND hwndProgressBar;
  4149. HWND hwndPropPage;
  4150. HINSTANCE hInstance;
  4151. LPTSTR pszDrive;
  4152. LPTSTR pszCurrDir;
  4153. LPTSTR pszInf;
  4154. BOOL *pfHasUserCancelled;
  4155. DWORD pfError;
  4156. } DISKPROGRESSSTRUCT;
  4157. DWORD WINAPI _DiskProgressDlgProcThread (LPVOID lpParam)
  4158. {
  4159. DISKPROGRESSSTRUCT* pdps = (DISKPROGRESSSTRUCT*)lpParam;
  4160. UtInitialize( NULL );
  4161. _CopyInfToDisk (
  4162. pdps->pszDrive,
  4163. pdps->pszCurrDir,
  4164. pdps->pszInf,
  4165. NULL,
  4166. NULL,
  4167. pdps->hwndProgressBar,
  4168. pdps->hwndPropPage,
  4169. pdps->hInstance,
  4170. pdps->pfHasUserCancelled,
  4171. &pdps->pfError
  4172. );
  4173. UtTerminate();
  4174. return 0;
  4175. }
  4176. BOOL
  4177. pReallyCancel (
  4178. HWND hwndParent,
  4179. HINSTANCE hInstance
  4180. )
  4181. {
  4182. TCHAR szMigrationWizardTitle[MAX_LOADSTRING];
  4183. BOOL result = FALSE;
  4184. LoadString(hInstance, IDS_MIGWIZTITLE, szMigrationWizardTitle, ARRAYSIZE(szMigrationWizardTitle));
  4185. if (hwndParent) // Stand-alone wizard mode
  4186. {
  4187. TCHAR szStopDisk[MAX_LOADSTRING];
  4188. LoadString(hInstance, IDS_STOPDISK, szStopDisk, ARRAYSIZE(szStopDisk));
  4189. if (IDYES == _ExclusiveMessageBox(hwndParent, szStopDisk, szMigrationWizardTitle, MB_YESNO | MB_DEFBUTTON2))
  4190. {
  4191. result = TRUE;
  4192. }
  4193. }
  4194. return result;
  4195. }
  4196. INT_PTR CALLBACK _DiskProgressDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4197. {
  4198. static BOOL fHasUserCancelled = FALSE;
  4199. static DWORD fError = ERROR_SUCCESS;
  4200. HWND hwnd;
  4201. LONG lExStyles;
  4202. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, 0, FALSE, 0);
  4203. switch (uMsg)
  4204. {
  4205. case WM_INITDIALOG:
  4206. // RTL progress bar for RTL dialogs
  4207. lExStyles = GetWindowLong (hwndDlg, GWL_EXSTYLE);
  4208. if (lExStyles & WS_EX_LAYOUTRTL)
  4209. {
  4210. hwnd = GetDlgItem(hwndDlg, IDC_COLLECTPROGRESS_PROGRESS);
  4211. lExStyles = GetWindowLongA(hwnd, GWL_EXSTYLE);
  4212. lExStyles |= WS_EX_LAYOUTRTL; // toggle layout
  4213. SetWindowLongA(hwnd, GWL_EXSTYLE, lExStyles);
  4214. InvalidateRect(hwnd, NULL, TRUE); // redraw
  4215. }
  4216. break;
  4217. case WM_USER_FINISHED:
  4218. if (fHasUserCancelled) {
  4219. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_BACK);
  4220. } else {
  4221. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_NEXT);
  4222. }
  4223. return TRUE;
  4224. break;
  4225. case WM_USER_CANCELLED:
  4226. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_BACK);
  4227. return TRUE;
  4228. break;
  4229. case WM_NOTIFY :
  4230. {
  4231. switch (((LPNMHDR)lParam)->code)
  4232. {
  4233. case PSN_SETACTIVE:
  4234. {
  4235. // blank progress bar
  4236. SendMessage(GetDlgItem(hwndDlg, IDC_DISKPROGRESS_PROGRESS), PBM_SETRANGE, 0, 100);
  4237. SendMessage(GetDlgItem(hwndDlg, IDC_DISKPROGRESS_PROGRESS), PBM_SETPOS, 0, 0);
  4238. ANIMATE_OPEN(hwndDlg,IDC_PROGRESS_ANIMATE1,IDA_FILECOPY);
  4239. ANIMATE_PLAY(hwndDlg,IDC_PROGRESS_ANIMATE1);
  4240. TCHAR szCurrDir[MAX_PATH];
  4241. if (GetCurrentDirectory(ARRAYSIZE(szCurrDir), szCurrDir))
  4242. {
  4243. DISKPROGRESSSTRUCT* pdps = (DISKPROGRESSSTRUCT*)CoTaskMemAlloc(sizeof(DISKPROGRESSSTRUCT));
  4244. fHasUserCancelled = FALSE;
  4245. pdps->hwndProgressBar = GetDlgItem(hwndDlg, IDC_DISKPROGRESS_PROGRESS);
  4246. pdps->hwndPropPage = hwndDlg;
  4247. pdps->hInstance = g_migwiz->GetInstance();
  4248. pdps->pszDrive = (LPTSTR)CoTaskMemAlloc(sizeof(TCHAR) * (1 + lstrlen(g_szToolDiskDrive)));
  4249. StrCpy(pdps->pszDrive, g_szToolDiskDrive);
  4250. pdps->pszCurrDir = (LPTSTR)CoTaskMemAlloc(sizeof(TCHAR) * (1 + lstrlen(szCurrDir)));
  4251. StrCpy(pdps->pszCurrDir, szCurrDir);
  4252. pdps->pszInf = NULL; // means choose default
  4253. pdps->pfHasUserCancelled = &fHasUserCancelled;
  4254. SHCreateThread(_DiskProgressDlgProcThread, pdps, 0, NULL);
  4255. fError = pdps->pfError;
  4256. }
  4257. }
  4258. break;
  4259. case PSN_QUERYCANCEL:
  4260. fHasUserCancelled = pReallyCancel (hwndDlg, g_migwiz->GetInstance());
  4261. SetWindowLong(hwndDlg, DWLP_MSGRESULT, TRUE);
  4262. return TRUE;
  4263. break;
  4264. case PSN_WIZBACK:
  4265. ANIMATE_STOP(hwndDlg,IDC_PROGRESS_ANIMATE1);
  4266. ANIMATE_CLOSE(hwndDlg,IDC_PROGRESS_ANIMATE1);
  4267. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ASKCD);
  4268. return TRUE;
  4269. break;
  4270. case PSN_WIZNEXT:
  4271. ANIMATE_STOP(hwndDlg,IDC_PROGRESS_ANIMATE1);
  4272. ANIMATE_CLOSE(hwndDlg,IDC_PROGRESS_ANIMATE1);
  4273. if (g_fUberCancel)
  4274. {
  4275. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  4276. }
  4277. else if (g_fReadFromNetwork)
  4278. {
  4279. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS); // just got a net connect, skip ahead
  4280. }
  4281. else
  4282. {
  4283. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DISKINSTRUCTIONS);
  4284. }
  4285. return TRUE;
  4286. break;
  4287. default :
  4288. break;
  4289. }
  4290. }
  4291. break;
  4292. }
  4293. return 0;
  4294. }
  4295. ///////////////////////////////////////////////////////////////
  4296. INT_PTR CALLBACK _InstructionsDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4297. {
  4298. // just highlight the title
  4299. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  4300. switch (uMsg)
  4301. {
  4302. case WM_NOTIFY:
  4303. {
  4304. switch (((LPNMHDR)lParam)->code)
  4305. {
  4306. case PSN_QUERYCANCEL:
  4307. return _HandleCancel(hwndDlg, FALSE, FALSE);
  4308. break;
  4309. case PSN_WIZBACK:
  4310. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ASKCD);
  4311. return TRUE;
  4312. break;
  4313. case PSN_WIZNEXT:
  4314. if (g_fUberCancel)
  4315. {
  4316. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  4317. }
  4318. else if (g_fReadFromNetwork)
  4319. {
  4320. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS);
  4321. }
  4322. else
  4323. {
  4324. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKAPPLYSTORE);
  4325. }
  4326. return TRUE;
  4327. break;
  4328. }
  4329. }
  4330. break;
  4331. case WM_USER_CANCEL_PENDING:
  4332. g_fUberCancel = TRUE;
  4333. pSetEvent (&g_TerminateEvent);
  4334. _NextWizardPage (hwndDlg);
  4335. break;
  4336. }
  4337. return 0;
  4338. }
  4339. ///////////////////////////////////////////////////////////////
  4340. int CALLBACK
  4341. PickApplyCallback (
  4342. HWND hwnd,
  4343. UINT uMsg,
  4344. LPARAM lParam,
  4345. LPARAM lpData
  4346. )
  4347. {
  4348. HRESULT hr = S_OK;
  4349. TCHAR tszFolderName[MAX_PATH];
  4350. IMalloc *mallocFn = NULL;
  4351. IShellFolder *psfParent = NULL;
  4352. IShellLink *pslLink = NULL;
  4353. LPCITEMIDLIST pidl;
  4354. LPCITEMIDLIST pidlRelative = NULL;
  4355. LPITEMIDLIST pidlReal = NULL;
  4356. if (uMsg == BFFM_SELCHANGED) {
  4357. hr = SHGetMalloc (&mallocFn);
  4358. if (!SUCCEEDED (hr)) {
  4359. mallocFn = NULL;
  4360. }
  4361. pidl = (LPCITEMIDLIST) lParam;
  4362. pidlReal = NULL;
  4363. if (pidl) {
  4364. hr = OurSHBindToParent (pidl, IID_IShellFolder, (void **)&psfParent, &pidlRelative);
  4365. if (SUCCEEDED(hr)) {
  4366. hr = psfParent->GetUIObjectOf (hwnd, 1, &pidlRelative, IID_IShellLink, NULL, (void **)&pslLink);
  4367. if (SUCCEEDED(hr)) {
  4368. hr = pslLink->GetIDList (&pidlReal);
  4369. if (!SUCCEEDED(hr)) {
  4370. pidlReal = NULL;
  4371. }
  4372. pslLink->Release ();
  4373. }
  4374. pidlRelative = NULL;
  4375. psfParent->Release ();
  4376. }
  4377. if (SHGetPathFromIDList(pidlReal?pidlReal:pidl, tszFolderName))
  4378. {
  4379. if (tszFolderName[0] == 0) {
  4380. SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
  4381. }
  4382. } else {
  4383. SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
  4384. }
  4385. if (pidlReal) {
  4386. if (mallocFn) {
  4387. mallocFn->Free ((void *)pidlReal);
  4388. }
  4389. pidlReal = NULL;
  4390. }
  4391. }
  4392. if (mallocFn) {
  4393. mallocFn->Release ();
  4394. mallocFn = NULL;
  4395. }
  4396. }
  4397. return 0;
  4398. }
  4399. INT_PTR CALLBACK _PickApplyStoreDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4400. {
  4401. BOOL imageIsValid;
  4402. BOOL imageExists;
  4403. TCHAR szTitle[MAX_LOADSTRING];
  4404. TCHAR szLoadString[MAX_LOADSTRING];
  4405. HWND hwndEdit;
  4406. HRESULT hr = E_FAIL;
  4407. static INT iSelectedDrive = -1; // Which removeable media drive is selected
  4408. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  4409. static UINT uiSelected = 0;
  4410. switch (uMsg)
  4411. {
  4412. case WM_COMMAND:
  4413. switch (LOWORD(wParam))
  4414. {
  4415. case IDC_PICKAPPLYSTORE_RADIO1: // Direct cable
  4416. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_BROWSE), FALSE);
  4417. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), FALSE);
  4418. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), TRUE);
  4419. uiSelected = 1;
  4420. // Disable the drive selector
  4421. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), FALSE);
  4422. break;
  4423. case IDC_PICKAPPLYSTORE_RADIO2: // Floppy
  4424. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_BROWSE), FALSE);
  4425. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), FALSE);
  4426. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), TRUE);
  4427. uiSelected = 2;
  4428. // Enable the drive selector
  4429. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), TRUE);
  4430. break;
  4431. case IDC_PICKAPPLYSTORE_RADIO3: // Other
  4432. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_BROWSE), TRUE);
  4433. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), TRUE);
  4434. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), FALSE);
  4435. Edit_LimitText(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), MAX_PATH - PATH_SAFETY_CHARS);
  4436. uiSelected = 3;
  4437. // Disable the drive selector
  4438. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), FALSE);
  4439. break;
  4440. case IDC_PICKAPPLYSTORE_BROWSE:
  4441. {
  4442. HRESULT hr = S_OK;
  4443. IMalloc *mallocFn = NULL;
  4444. IShellFolder *psfParent = NULL;
  4445. IShellLink *pslLink = NULL;
  4446. LPCITEMIDLIST pidl;
  4447. LPCITEMIDLIST pidlRelative = NULL;
  4448. LPITEMIDLIST pidlReal = NULL;
  4449. TCHAR szFolder[MAX_PATH];
  4450. TCHAR szPick[MAX_LOADSTRING];
  4451. hr = SHGetMalloc (&mallocFn);
  4452. if (!SUCCEEDED (hr)) {
  4453. mallocFn = NULL;
  4454. }
  4455. LoadString(g_migwiz->GetInstance(), IDS_PICKAFOLDER, szPick, ARRAYSIZE(szPick));
  4456. BROWSEINFO brwsinf = { hwndDlg, NULL, NULL, szPick, BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE, PickApplyCallback, 0, 0 };
  4457. pidl = SHBrowseForFolder(&brwsinf);
  4458. if (pidl)
  4459. {
  4460. hr = OurSHBindToParent (pidl, IID_IShellFolder, (void **)&psfParent, &pidlRelative);
  4461. if (SUCCEEDED(hr)) {
  4462. hr = psfParent->GetUIObjectOf (hwndDlg, 1, &pidlRelative, IID_IShellLink, NULL, (void **)&pslLink);
  4463. if (SUCCEEDED(hr)) {
  4464. hr = pslLink->GetIDList (&pidlReal);
  4465. if (SUCCEEDED(hr)) {
  4466. if (mallocFn) {
  4467. mallocFn->Free ((void *)pidl);
  4468. }
  4469. pidl = pidlReal;
  4470. pidlReal = NULL;
  4471. }
  4472. pslLink->Release ();
  4473. }
  4474. pidlRelative = NULL;
  4475. psfParent->Release ();
  4476. }
  4477. if (SHGetPathFromIDList(pidl, szFolder))
  4478. {
  4479. SendMessage(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), WM_SETTEXT, 0, (LPARAM)szFolder);
  4480. }
  4481. if (mallocFn) {
  4482. mallocFn->Free ((void *)pidl);
  4483. }
  4484. pidl = NULL;
  4485. }
  4486. if (mallocFn) {
  4487. mallocFn->Release ();
  4488. mallocFn = NULL;
  4489. }
  4490. }
  4491. break;
  4492. }
  4493. break;
  4494. case WM_NOTIFY :
  4495. {
  4496. switch (((LPNMHDR)lParam)->code)
  4497. {
  4498. case PSN_SETACTIVE:
  4499. if (g_fReadFromNetwork)
  4500. {
  4501. PropSheet_PressButton(GetParent(hwndDlg), PSWIZB_NEXT);
  4502. }
  4503. else
  4504. {
  4505. BOOL fFloppyDetected;
  4506. INT currDrive;
  4507. INT comPort;
  4508. // enable direct cable transport if available
  4509. comPort = _ComboBoxEx_AddCOMPorts (NULL, 0);
  4510. Button_Enable (GetDlgItem (hwndDlg, IDC_PICKAPPLYSTORE_RADIO1), (-1 != comPort));
  4511. SendMessage(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), CBEM_SETIMAGELIST, 0, (LPARAM)g_migwiz->GetImageList());
  4512. currDrive = _ComboBoxEx_AddDrives (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO));
  4513. Button_Enable (GetDlgItem (hwndDlg, IDC_PICKAPPLYSTORE_RADIO2), (-1 != currDrive));
  4514. fFloppyDetected = (-1 != currDrive);
  4515. // set the selected drive if any
  4516. if ((currDrive != -1) && (iSelectedDrive != -1)) {
  4517. ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), iSelectedDrive);
  4518. currDrive = iSelectedDrive;
  4519. }
  4520. if ((uiSelected == 0 || uiSelected == 1) && (-1 != comPort))
  4521. {
  4522. // check Direct cable button
  4523. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO1), BST_CHECKED);
  4524. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO2), BST_UNCHECKED);
  4525. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO3), BST_UNCHECKED);
  4526. // disable folder box, browse button
  4527. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_BROWSE), FALSE);
  4528. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), FALSE);
  4529. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), TRUE);
  4530. // disable the drive selector
  4531. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), FALSE);
  4532. }
  4533. else if ((uiSelected == 0 || uiSelected == 2) && fFloppyDetected)
  4534. {
  4535. // check Floppy button
  4536. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO1), BST_UNCHECKED);
  4537. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO2), BST_CHECKED);
  4538. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO3), BST_UNCHECKED);
  4539. // disable folder box, browse button
  4540. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_BROWSE), FALSE);
  4541. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), FALSE);
  4542. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), TRUE);
  4543. // Enable the drive selector
  4544. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), TRUE);
  4545. }
  4546. else // Other
  4547. {
  4548. // check Other button
  4549. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO1), BST_UNCHECKED);
  4550. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO2), BST_UNCHECKED);
  4551. Button_SetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO3), BST_CHECKED);
  4552. // enable folder box, browse button
  4553. Button_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_BROWSE), TRUE);
  4554. Edit_Enable(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), TRUE);
  4555. Edit_SetReadOnly(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), FALSE);
  4556. Edit_LimitText(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), MAX_PATH - PATH_SAFETY_CHARS);
  4557. // disable the drive selector
  4558. EnableWindow (GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO), FALSE);
  4559. }
  4560. }
  4561. break;
  4562. case PSN_QUERYCANCEL:
  4563. return _HandleCancel(hwndDlg, FALSE, FALSE);
  4564. break;
  4565. case PSN_WIZBACK:
  4566. if (g_fUberCancel)
  4567. {
  4568. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  4569. }
  4570. else
  4571. {
  4572. if (g_fHaveWhistlerCD)
  4573. {
  4574. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_CDINSTRUCTIONS);
  4575. }
  4576. else if (g_fAlreadyCollected)
  4577. {
  4578. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ASKCD);
  4579. }
  4580. else
  4581. {
  4582. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DISKINSTRUCTIONS);
  4583. }
  4584. }
  4585. return TRUE;
  4586. break;
  4587. case PSN_WIZNEXT:
  4588. if (g_fUberCancel)
  4589. {
  4590. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  4591. }
  4592. else if (g_fReadFromNetwork)
  4593. {
  4594. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS);
  4595. }
  4596. else
  4597. {
  4598. if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO1))) // direct cable
  4599. {
  4600. g_fStoreToCable = TRUE;
  4601. if (uiSelected != 1)
  4602. {
  4603. uiSelected = 1;
  4604. }
  4605. }
  4606. else if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_RADIO2))) // floppy
  4607. {
  4608. LPTSTR pszDrive;
  4609. g_fStoreToCable = FALSE;
  4610. HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_COMBO);
  4611. iSelectedDrive = ComboBox_GetCurSel(hwndCombo);
  4612. pszDrive = (LPTSTR)ComboBox_GetItemData(hwndCombo, iSelectedDrive);
  4613. lstrcpy(g_szStore, pszDrive);
  4614. if (uiSelected != 2)
  4615. {
  4616. uiSelected = 2;
  4617. }
  4618. }
  4619. else // other
  4620. {
  4621. TCHAR tsTemp[MAX_PATH + 1];
  4622. g_fStoreToCable = FALSE;
  4623. SendMessage(GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT), WM_GETTEXT,
  4624. (WPARAM)ARRAYSIZE(tsTemp), (LPARAM)tsTemp);
  4625. CopyStorePath(tsTemp, g_szStore);
  4626. if (uiSelected != 3)
  4627. {
  4628. uiSelected = 3;
  4629. }
  4630. }
  4631. if (g_fStoreToCable) {
  4632. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DIRECTCABLE);
  4633. return TRUE;
  4634. }
  4635. if (!_IsValidStore(g_szStore, FALSE, g_migwiz->GetInstance(), NULL)) // need a valid directory! stay right here.
  4636. {
  4637. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  4638. LoadString(g_migwiz->GetInstance(), IDS_ENTERDEST, szLoadString, ARRAYSIZE(szLoadString));
  4639. _ExclusiveMessageBox(hwndDlg, szLoadString, szTitle, MB_OK);
  4640. hwndEdit = GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT);
  4641. SetFocus(hwndEdit);
  4642. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  4643. SetWindowLong(hwndDlg, DWLP_MSGRESULT, -1);
  4644. return -1;
  4645. }
  4646. hr = Engine_StartTransport (FALSE, g_szStore, &imageIsValid, &imageExists);
  4647. if ((!SUCCEEDED (hr)) || (!imageIsValid) || (!imageExists)) {
  4648. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  4649. if (!imageExists) {
  4650. LoadString(g_migwiz->GetInstance(), IDS_STORAGEEMPTY, szLoadString, ARRAYSIZE(szLoadString));
  4651. } else {
  4652. LoadString(g_migwiz->GetInstance(), IDS_STORAGEINVALID, szLoadString, ARRAYSIZE(szLoadString));
  4653. }
  4654. _ExclusiveMessageBox (hwndDlg, szLoadString, szTitle, MB_OK);
  4655. hwndEdit = GetDlgItem(hwndDlg, IDC_PICKAPPLYSTORE_EDIT);
  4656. SetFocus(hwndEdit);
  4657. SendMessage(hwndEdit, EM_SETSEL, 0, -1);
  4658. SetWindowLong(hwndDlg, DWLP_MSGRESULT, -1);
  4659. return -1;
  4660. }
  4661. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS);
  4662. }
  4663. return TRUE;
  4664. break;
  4665. }
  4666. break;
  4667. }
  4668. case WM_USER_CANCEL_PENDING:
  4669. g_fUberCancel = TRUE;
  4670. pSetEvent (&g_TerminateEvent);
  4671. _NextWizardPage (hwndDlg);
  4672. break;
  4673. default:
  4674. break;
  4675. }
  4676. return 0;
  4677. }
  4678. ///////////////////////////////////////////////////////////////
  4679. typedef struct {
  4680. HWND hwndProgressBar;
  4681. HWND hwndPropPage;
  4682. } APPLYPROGRESSSTRUCT;
  4683. BOOL CALLBACK
  4684. pSendQueryEndSession (
  4685. HWND hwnd,
  4686. LPARAM lParam
  4687. )
  4688. {
  4689. DWORD_PTR result;
  4690. if (hwnd == (HWND)lParam) {
  4691. return TRUE;
  4692. }
  4693. SetForegroundWindow (hwnd);
  4694. if (SendMessageTimeout (
  4695. hwnd,
  4696. WM_QUERYENDSESSION,
  4697. 0,
  4698. ENDSESSION_LOGOFF,
  4699. SMTO_ABORTIFHUNG|SMTO_NORMAL|SMTO_NOTIMEOUTIFNOTHUNG,
  4700. 1000,
  4701. &result
  4702. )) {
  4703. if (result) {
  4704. SendMessageTimeout (
  4705. hwnd,
  4706. WM_ENDSESSION,
  4707. TRUE,
  4708. ENDSESSION_LOGOFF,
  4709. SMTO_ABORTIFHUNG|SMTO_NORMAL|SMTO_NOTIMEOUTIFNOTHUNG,
  4710. 1000,
  4711. &result
  4712. );
  4713. return TRUE;
  4714. }
  4715. }
  4716. return FALSE;
  4717. }
  4718. BOOL
  4719. pLogOffSystem (
  4720. VOID
  4721. )
  4722. {
  4723. HWND topLevelWnd = NULL;
  4724. HWND tempWnd = NULL;
  4725. if (g_hwndCurrent) {
  4726. tempWnd = g_hwndCurrent;
  4727. while (tempWnd) {
  4728. topLevelWnd = tempWnd;
  4729. tempWnd = GetParent (tempWnd);
  4730. }
  4731. }
  4732. // first we enumerate all top level windows and send them WM_QUERYENDSESSION
  4733. if (!EnumWindows (pSendQueryEndSession, (LPARAM)topLevelWnd)) {
  4734. return FALSE;
  4735. }
  4736. // finally we call ExitWindowsEx forcing the Log off
  4737. return ExitWindowsEx (EWX_LOGOFF, EWX_FORCE);
  4738. }
  4739. DWORD WINAPI _ApplyProgressDlgProcThread (LPVOID lpParam)
  4740. {
  4741. APPLYPROGRESSSTRUCT* paps = (APPLYPROGRESSSTRUCT*)lpParam;
  4742. BOOL fHasUserCancelled = FALSE;
  4743. HRESULT hResult;
  4744. hResult = _DoApply(g_fReadFromNetwork ? NULL : g_szStore, paps->hwndProgressBar, paps->hwndPropPage, &fHasUserCancelled, NULL, 0);
  4745. if (fHasUserCancelled) {
  4746. hResult = E_FAIL;
  4747. } else {
  4748. if (SUCCEEDED(hResult)) {
  4749. if (g_RebootSystem) {
  4750. g_CompleteReboot = TRUE;
  4751. }
  4752. if (g_LogOffSystem) {
  4753. g_CompleteLogOff = TRUE;
  4754. }
  4755. }
  4756. }
  4757. SendMessage (paps->hwndPropPage, WM_USER_THREAD_COMPLETE, 0, (LPARAM) hResult);
  4758. pSetEvent (&g_TerminateEvent);
  4759. return hResult;
  4760. }
  4761. INT_PTR CALLBACK _ApplyProgressDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4762. {
  4763. HRESULT hResult;
  4764. HWND hwnd;
  4765. LONG lExStyles;
  4766. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, 0, FALSE, 0);
  4767. switch (uMsg)
  4768. {
  4769. case WM_INITDIALOG:
  4770. // RTL progress bar for RTL dialogs
  4771. lExStyles = GetWindowLong (hwndDlg, GWL_EXSTYLE);
  4772. if (lExStyles & WS_EX_LAYOUTRTL)
  4773. {
  4774. hwnd = GetDlgItem(hwndDlg, IDC_COLLECTPROGRESS_PROGRESS);
  4775. lExStyles = GetWindowLongA(hwnd, GWL_EXSTYLE);
  4776. lExStyles |= WS_EX_LAYOUTRTL; // toggle layout
  4777. SetWindowLongA(hwnd, GWL_EXSTYLE, lExStyles);
  4778. InvalidateRect(hwnd, NULL, TRUE); // redraw
  4779. }
  4780. // Let's set an update timer to 3 sec.
  4781. SetTimer (hwndDlg, 0, 3000, NULL);
  4782. break;
  4783. case WM_USER_FINISHED:
  4784. PropSheet_PressButton(GetParent(hwndDlg), PSBTN_NEXT);
  4785. return TRUE;
  4786. break;
  4787. case WM_USER_CANCELLED:
  4788. g_fUberCancel = TRUE;
  4789. _NextWizardPage (hwndDlg);
  4790. return TRUE;
  4791. break;
  4792. case WM_NOTIFY :
  4793. {
  4794. switch (((LPNMHDR)lParam)->code)
  4795. {
  4796. case PSN_SETACTIVE:
  4797. {
  4798. // blank progress bar
  4799. SendMessage(GetDlgItem(hwndDlg, IDC_DISKPROGRESS_PROGRESS), PBM_SETRANGE, 0, 100);
  4800. SendMessage(GetDlgItem(hwndDlg, IDC_DISKPROGRESS_PROGRESS), PBM_SETPOS, 0, 0);
  4801. ANIMATE_OPEN(hwndDlg,IDC_PROGRESS_ANIMATE3,IDA_FILECOPY);
  4802. ANIMATE_PLAY(hwndDlg,IDC_PROGRESS_ANIMATE3);
  4803. APPLYPROGRESSSTRUCT* paps = (APPLYPROGRESSSTRUCT*)CoTaskMemAlloc(sizeof(APPLYPROGRESSSTRUCT));
  4804. paps->hwndProgressBar = GetDlgItem(hwndDlg, IDC_APPLYPROGRESS_PROGRESS);
  4805. paps->hwndPropPage = hwndDlg;
  4806. // Lanuch apply thread
  4807. SHCreateThread(_ApplyProgressDlgProcThread, paps, 0, NULL);
  4808. }
  4809. break;
  4810. case PSN_QUERYCANCEL:
  4811. return _HandleCancel(hwndDlg, FALSE, TRUE);
  4812. break;
  4813. case PSN_WIZBACK:
  4814. ANIMATE_STOP(hwndDlg,IDC_PROGRESS_ANIMATE3);
  4815. ANIMATE_CLOSE(hwndDlg,IDC_PROGRESS_ANIMATE3);
  4816. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKAPPLYSTORE);
  4817. return TRUE;
  4818. break;
  4819. case PSN_WIZNEXT:
  4820. ANIMATE_STOP(hwndDlg,IDC_PROGRESS_ANIMATE3);
  4821. ANIMATE_CLOSE(hwndDlg,IDC_PROGRESS_ANIMATE3);
  4822. if (g_fUberCancel)
  4823. {
  4824. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  4825. }
  4826. else
  4827. {
  4828. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ENDAPPLY);
  4829. }
  4830. return TRUE;
  4831. break;
  4832. default :
  4833. break;
  4834. }
  4835. }
  4836. break;
  4837. case WM_USER_CANCEL_PENDING:
  4838. g_fUberCancel = TRUE;
  4839. pResetEvent (&g_TerminateEvent);
  4840. _NextWizardPage (hwndDlg);
  4841. break;
  4842. case WM_USER_THREAD_COMPLETE:
  4843. hResult = (HRESULT) lParam;
  4844. if (FAILED(hResult))
  4845. {
  4846. g_fUberCancel = TRUE;
  4847. }
  4848. _NextWizardPage (hwndDlg);
  4849. break;
  4850. case WM_USER_STATUS:
  4851. case WM_TIMER:
  4852. INT nResult = 0;
  4853. PTSTR szStatusString = NULL;
  4854. TCHAR szTmpStatus[MAX_LOADSTRING];
  4855. PCTSTR nativeObjectName;
  4856. HWND hwndText = GetDlgItem(hwndDlg, IDC_APPLYPROGRESS_STATUS);
  4857. // Let's update the status
  4858. EnterCriticalSection(&g_AppInfoCritSection);
  4859. switch (g_AppInfoPhase) {
  4860. case MIG_TRANSPORT_PHASE:
  4861. switch (g_AppInfoSubPhase) {
  4862. case SUBPHASE_CONNECTING2:
  4863. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_CONNECTING2, szTmpStatus, MAX_LOADSTRING);
  4864. if (nResult) {
  4865. _UpdateText (hwndText, szTmpStatus);
  4866. }
  4867. break;
  4868. case SUBPHASE_NETPREPARING:
  4869. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_NETPREPARING, szTmpStatus, MAX_LOADSTRING);
  4870. if (nResult) {
  4871. _UpdateText (hwndText, szTmpStatus);
  4872. }
  4873. break;
  4874. case SUBPHASE_CABLETRANS:
  4875. if (g_AppInfoText) {
  4876. _UpdateText (hwndText, g_AppInfoText);
  4877. }
  4878. break;
  4879. case SUBPHASE_UNCOMPRESSING:
  4880. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_TR_UNCOMPRESSING, szTmpStatus, MAX_LOADSTRING);
  4881. if (nResult) {
  4882. _UpdateText (hwndText, szTmpStatus);
  4883. }
  4884. default:
  4885. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_ORGANIZING, szTmpStatus, MAX_LOADSTRING);
  4886. _UpdateText (hwndText, szTmpStatus);
  4887. break;
  4888. }
  4889. break;
  4890. case MIG_HIGHPRIORITYQUEUE_PHASE:
  4891. case MIG_HIGHPRIORITYESTIMATE_PHASE:
  4892. case MIG_HIGHPRIORITYGATHER_PHASE:
  4893. case MIG_GATHERQUEUE_PHASE:
  4894. case MIG_GATHERESTIMATE_PHASE:
  4895. case MIG_GATHER_PHASE:
  4896. case MIG_ANALYSIS_PHASE:
  4897. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_ORGANIZING, szTmpStatus, MAX_LOADSTRING);
  4898. _UpdateText (hwndText, szTmpStatus);
  4899. break;
  4900. case MIG_APPLY_PHASE:
  4901. nResult = LoadString (g_migwiz->GetInstance(), IDS_APPINFO_APPLY, szTmpStatus, MAX_LOADSTRING);
  4902. _UpdateText (hwndText, szTmpStatus);
  4903. break;
  4904. default:
  4905. break;
  4906. }
  4907. LeaveCriticalSection(&g_AppInfoCritSection);
  4908. break;
  4909. }
  4910. return 0;
  4911. }
  4912. ///////////////////////////////////////////////////////////////
  4913. INT_PTR CALLBACK _AskCDDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4914. {
  4915. static UINT uiSelected = 1; // 1=MakeDisk, 2=HaveDisk, 3:UseCD, 4:Collected
  4916. static INT iSelectedDrive = -1; // Which removeable media drive is selected
  4917. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_NEXT, FALSE, 0);
  4918. switch (uMsg)
  4919. {
  4920. case WM_INITDIALOG:
  4921. uiSelected = 1;
  4922. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO1), BST_CHECKED);
  4923. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO2), BST_UNCHECKED);
  4924. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO3), BST_UNCHECKED);
  4925. break;
  4926. case WM_COMMAND:
  4927. if (BN_CLICKED == HIWORD(wParam))
  4928. {
  4929. switch (LOWORD(wParam))
  4930. {
  4931. case IDC_ASKCD_RADIO1:
  4932. uiSelected = 1;
  4933. break;
  4934. case IDC_ASKCD_RADIO2:
  4935. uiSelected = 2;
  4936. break;
  4937. case IDC_ASKCD_RADIO3:
  4938. uiSelected = 3;
  4939. break;
  4940. case IDC_ASKCD_RADIO4:
  4941. uiSelected = 4;
  4942. break;
  4943. }
  4944. BOOL fActivate = (1 == uiSelected);
  4945. EnableWindow (GetDlgItem (hwndDlg, IDC_ASKCD_COMBO), fActivate);
  4946. }
  4947. break;
  4948. case WM_NOTIFY :
  4949. switch (((LPNMHDR)lParam)->code)
  4950. {
  4951. case PSN_SETACTIVE:
  4952. // Reinit my globals
  4953. g_fAlreadyCollected = FALSE;
  4954. g_fHaveWhistlerCD = FALSE;
  4955. // Check for HomeLan
  4956. if (g_fReadFromNetwork)
  4957. {
  4958. PropSheet_PressButton(GetParent(hwndDlg), PSWIZB_NEXT);
  4959. }
  4960. else
  4961. {
  4962. HWND hwndCombo = GetDlgItem(hwndDlg, IDC_ASKCD_COMBO);
  4963. SendMessage(hwndCombo, CBEM_SETIMAGELIST, 0, (LPARAM)g_migwiz->GetImageList());
  4964. _ComboBoxEx_AddDrives (hwndCombo);
  4965. if (ComboBox_GetCount(hwndCombo) > 0) {
  4966. EnableWindow (hwndCombo, (1 == uiSelected));
  4967. Button_Enable (GetDlgItem(hwndDlg, IDC_ASKCD_RADIO1), TRUE);
  4968. if( iSelectedDrive != -1 )
  4969. {
  4970. ComboBox_SetCurSel(hwndCombo, iSelectedDrive);
  4971. }
  4972. } else {
  4973. // No floppy drives exist. Disable the creation option
  4974. if (uiSelected == 1) {
  4975. uiSelected = 3;
  4976. }
  4977. EnableWindow (hwndCombo, FALSE);
  4978. Button_Enable (GetDlgItem(hwndDlg, IDC_ASKCD_RADIO1), FALSE);
  4979. }
  4980. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO1), BST_UNCHECKED);
  4981. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO2), BST_UNCHECKED);
  4982. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO3), BST_UNCHECKED);
  4983. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO4), BST_UNCHECKED);
  4984. switch (uiSelected)
  4985. {
  4986. case 1: // Create wizard disk
  4987. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO1), BST_CHECKED);
  4988. break;
  4989. case 2: // I already have wizard disk
  4990. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO2), BST_CHECKED);
  4991. break;
  4992. case 3: // I will use the CD
  4993. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO3), BST_CHECKED);
  4994. break;
  4995. case 4: // I already have the stuff collected
  4996. Button_SetCheck(GetDlgItem(hwndDlg,IDC_ASKCD_RADIO4), BST_CHECKED);
  4997. break;
  4998. }
  4999. }
  5000. break;
  5001. case PSN_QUERYCANCEL:
  5002. return _HandleCancel(hwndDlg, FALSE, FALSE);
  5003. break;
  5004. case PSN_WIZNEXT:
  5005. if (g_fUberCancel)
  5006. {
  5007. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  5008. }
  5009. else if (g_fReadFromNetwork)
  5010. {
  5011. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS);
  5012. }
  5013. else
  5014. {
  5015. switch (uiSelected)
  5016. {
  5017. case 1: // Create wizard disk
  5018. {
  5019. LPTSTR pszDrive;
  5020. HWND hwndRemoveCombo = GetDlgItem(hwndDlg, IDC_ASKCD_COMBO);
  5021. iSelectedDrive = ComboBox_GetCurSel(hwndRemoveCombo);
  5022. pszDrive = (LPTSTR)ComboBox_GetItemData(hwndRemoveCombo, iSelectedDrive);
  5023. StrCpyN(g_szToolDiskDrive, pszDrive, ARRAYSIZE(g_szToolDiskDrive));
  5024. TCHAR szTitle[MAX_LOADSTRING];
  5025. LoadString(g_migwiz->GetInstance(), IDS_MIGWIZTITLE, szTitle, ARRAYSIZE(szTitle));
  5026. TCHAR szMsg[MAX_LOADSTRING];
  5027. LoadString(g_migwiz->GetInstance(), IDS_MAKETOOLDISK_INSERT, szMsg, ARRAYSIZE(szMsg));
  5028. if (IDOK == _ExclusiveMessageBox(hwndDlg, szMsg, szTitle, MB_OKCANCEL))
  5029. {
  5030. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DISKPROGRESS);
  5031. }
  5032. else
  5033. {
  5034. SetWindowLong(hwndDlg, DWLP_MSGRESULT, -1); // stay right here
  5035. }
  5036. return TRUE;
  5037. }
  5038. break;
  5039. case 2: // I already have wizard disk
  5040. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_DISKINSTRUCTIONS);
  5041. return TRUE;
  5042. case 3: // I will use the CD
  5043. g_fHaveWhistlerCD = TRUE;
  5044. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_CDINSTRUCTIONS);
  5045. return TRUE;
  5046. case 4: // I already have the stuff collected
  5047. g_fAlreadyCollected = TRUE;
  5048. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKAPPLYSTORE);
  5049. return TRUE;
  5050. }
  5051. }
  5052. return TRUE;
  5053. break;
  5054. }
  5055. break;
  5056. case WM_USER_CANCEL_PENDING:
  5057. g_fUberCancel = TRUE;
  5058. pSetEvent (&g_TerminateEvent);
  5059. _NextWizardPage (hwndDlg);
  5060. break;
  5061. }
  5062. return 0;
  5063. }
  5064. ///////////////////////////////////////////////////////////////
  5065. INT_PTR CALLBACK _CDInstructionsDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5066. {
  5067. // just highlight the title
  5068. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  5069. switch (uMsg)
  5070. {
  5071. case WM_NOTIFY:
  5072. {
  5073. switch (((LPNMHDR)lParam)->code)
  5074. {
  5075. case PSN_SETACTIVE:
  5076. if (g_fReadFromNetwork)
  5077. {
  5078. PropSheet_PressButton(GetParent(hwndDlg), PSWIZB_NEXT);
  5079. }
  5080. else
  5081. {
  5082. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
  5083. }
  5084. break;
  5085. case PSN_QUERYCANCEL:
  5086. return _HandleCancel(hwndDlg, FALSE, FALSE);
  5087. break;
  5088. case PSN_WIZBACK:
  5089. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_ASKCD);
  5090. return TRUE;
  5091. break;
  5092. case PSN_WIZNEXT:
  5093. if (g_fUberCancel)
  5094. {
  5095. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  5096. }
  5097. else if (g_fReadFromNetwork)
  5098. {
  5099. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_APPLYPROGRESS);
  5100. }
  5101. else
  5102. {
  5103. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKAPPLYSTORE);
  5104. }
  5105. return TRUE;
  5106. break;
  5107. }
  5108. }
  5109. break;
  5110. case WM_USER_CANCEL_PENDING:
  5111. g_fUberCancel = TRUE;
  5112. pSetEvent (&g_TerminateEvent);
  5113. _NextWizardPage (hwndDlg);
  5114. break;
  5115. }
  5116. return 0;
  5117. }
  5118. VOID
  5119. pGenerateHTMLAppList (HANDLE FileHandle)
  5120. {
  5121. TCHAR szLoadStr[MAX_LOADSTRING];
  5122. POBJLIST objList = NULL;
  5123. DWORD written;
  5124. #ifdef UNICODE
  5125. ((PBYTE)szLoadStr) [0] = 0xFF;
  5126. ((PBYTE)szLoadStr) [1] = 0xFE;
  5127. WriteFile (FileHandle, szLoadStr, 2, &written, NULL);
  5128. #endif
  5129. pWriteStrResToFile (FileHandle, IDS_APPINSTALL_BEGIN);
  5130. _tcscpy (szLoadStr, TEXT("<UL>\n"));
  5131. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  5132. objList = g_HTMLApps;
  5133. while (objList) {
  5134. if (objList->ObjectName) {
  5135. _tcscpy (szLoadStr, TEXT("<LI>"));
  5136. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  5137. WriteFile (FileHandle, objList->ObjectName, (_tcslen (objList->ObjectName) + 1) * sizeof (TCHAR), &written, NULL);
  5138. }
  5139. objList = objList->Next;
  5140. }
  5141. _tcscpy (szLoadStr, TEXT("</UL>\n"));
  5142. WriteFile (FileHandle, szLoadStr, (_tcslen (szLoadStr) + 1) * sizeof (TCHAR), &written, NULL);
  5143. pWriteStrResToFile (FileHandle, IDS_APPINSTALL_END);
  5144. }
  5145. INT_PTR CALLBACK _AppInstallDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5146. {
  5147. IWebBrowser2 *m_pweb = NULL; // IE4 IWebBrowser interface pointer
  5148. IUnknown *punk = NULL;
  5149. HWND webHostWnd = NULL;
  5150. HANDLE hHTMLAppList = INVALID_HANDLE_VALUE;
  5151. PWSTR szTarget;
  5152. // just highlight the title
  5153. _RootDlgProc(hwndDlg, uMsg, wParam, lParam, PSWIZB_BACK | PSWIZB_NEXT, FALSE, 0);
  5154. switch (uMsg)
  5155. {
  5156. case WM_INITDIALOG:
  5157. // If Wiz95 layout...
  5158. if (g_migwiz->GetOldStyle())
  5159. {
  5160. _OldStylify(hwndDlg, IDS_APPINSTALLTITLE);
  5161. }
  5162. break;
  5163. case WM_DESTROY:
  5164. if (m_pweb)
  5165. m_pweb->Release();
  5166. m_pweb = NULL;
  5167. //
  5168. // tell the container to remove IE4 and then
  5169. // release our reference to the container.
  5170. //
  5171. if (g_WebContainer)
  5172. {
  5173. g_WebContainer->remove();
  5174. g_WebContainer->Release();
  5175. g_WebContainer = NULL;
  5176. }
  5177. break;
  5178. case WM_NOTIFY:
  5179. {
  5180. switch (((LPNMHDR)lParam)->code)
  5181. {
  5182. case PSN_SETACTIVE:
  5183. if (!g_fCancelPressed) {
  5184. webHostWnd = GetDlgItem (hwndDlg, IDC_APPWEBHOST);
  5185. if (webHostWnd) {
  5186. // Now let's generate the failure HTML file.
  5187. if (*g_HTMLAppList) {
  5188. hHTMLAppList = CreateFile (g_HTMLAppList,
  5189. GENERIC_READ|GENERIC_WRITE,
  5190. FILE_SHARE_READ,
  5191. NULL,
  5192. CREATE_ALWAYS,
  5193. 0,
  5194. NULL);
  5195. if (hHTMLAppList != INVALID_HANDLE_VALUE) {
  5196. pGenerateHTMLAppList (hHTMLAppList);
  5197. if (g_WebContainer)
  5198. {
  5199. g_WebContainer->remove();
  5200. g_WebContainer->Release();
  5201. g_WebContainer = NULL;
  5202. }
  5203. g_WebContainer = new Container();
  5204. if (g_WebContainer)
  5205. {
  5206. g_WebContainer->setParent(webHostWnd);
  5207. g_WebContainer->add(L"Shell.Explorer");
  5208. g_WebContainer->setVisible(TRUE);
  5209. g_WebContainer->setFocus(TRUE);
  5210. //
  5211. // get the IWebBrowser2 interface and cache it.
  5212. //
  5213. punk = g_WebContainer->getUnknown();
  5214. if (punk)
  5215. {
  5216. punk->QueryInterface(IID_IWebBrowser2, (PVOID *)&m_pweb);
  5217. if (m_pweb) {
  5218. #ifdef UNICODE
  5219. m_pweb->Navigate(g_HTMLAppList, NULL, NULL, NULL, NULL);
  5220. #else
  5221. szTarget = _ConvertToUnicode (CP_ACP, g_HTMLAppList);
  5222. if (szTarget) {
  5223. m_pweb->Navigate(szTarget, NULL, NULL, NULL, NULL);
  5224. LocalFree ((HLOCAL)szTarget);
  5225. szTarget = NULL;
  5226. }
  5227. #endif
  5228. }
  5229. punk->Release();
  5230. punk = NULL;
  5231. }
  5232. }
  5233. // We intentionally want to keep this file open for the life of the wizard.
  5234. // With this we eliminate the possibility for someone to overwrite the
  5235. // content of the HTML file therefore forcing us to show something else
  5236. // maybe even run some malicious script.
  5237. // CloseHandle (hHTMLAppList);
  5238. }
  5239. } else {
  5240. ShowWindow(webHostWnd, SW_HIDE);
  5241. }
  5242. }
  5243. }
  5244. break;
  5245. case PSN_QUERYCANCEL:
  5246. return _HandleCancel(hwndDlg, FALSE, FALSE);
  5247. break;
  5248. case PSN_WIZBACK:
  5249. if (g_fCustomize == TRUE) {
  5250. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_CUSTOMIZE);
  5251. } else {
  5252. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_PICKMETHOD);
  5253. }
  5254. return TRUE;
  5255. break;
  5256. case PSN_WIZNEXT:
  5257. if (g_fUberCancel)
  5258. {
  5259. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_FAILCLEANUP);
  5260. }
  5261. else
  5262. {
  5263. SetWindowLong(hwndDlg, DWLP_MSGRESULT, IDD_COLLECTPROGRESS);
  5264. }
  5265. return TRUE;
  5266. }
  5267. }
  5268. break;
  5269. case WM_USER_CANCEL_PENDING:
  5270. g_fUberCancel = TRUE;
  5271. pSetEvent (&g_TerminateEvent);
  5272. _NextWizardPage (hwndDlg);
  5273. break;
  5274. }
  5275. return 0;
  5276. }