Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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