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.

571 lines
22 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1998
  3. All rights reserved
  4. File: TASKS.CPP
  5. ***************************************************************************/
  6. #include "pch.h"
  7. #include "callback.h"
  8. #include "utils.h"
  9. #include "tasks.h"
  10. #include "logging.h"
  11. DEFINE_MODULE("RIPREP")
  12. extern HWND g_hTasksDialog;
  13. typedef struct {
  14. HANDLE hChecked;
  15. HANDLE hError;
  16. HANDLE hArrow;
  17. HANDLE hFontNormal;
  18. HANDLE hFontBold;
  19. int dwWidth;
  20. int dwHeight;
  21. } SETUPDLGDATA, *LPSETUPDLGDATA;
  22. //
  23. // TasksDlgProc()
  24. //
  25. INT_PTR CALLBACK
  26. TasksDlgProc(
  27. HWND hDlg,
  28. UINT uMsg,
  29. WPARAM wParam,
  30. LPARAM lParam )
  31. {
  32. static HBRUSH hBrush = NULL;
  33. LPSETUPDLGDATA psdd = (LPSETUPDLGDATA) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  34. INT_PTR result;
  35. switch (uMsg)
  36. {
  37. default:
  38. return FALSE;
  39. case WM_INITDIALOG:
  40. {
  41. BITMAP bm;
  42. // grab the bitmaps
  43. psdd =
  44. (LPSETUPDLGDATA) TraceAlloc( GMEM_FIXED, sizeof(SETUPDLGDATA) );
  45. if ( psdd == NULL ) {
  46. // This returns FALSE at successful completion
  47. // So returning opposite
  48. return TRUE;
  49. }
  50. psdd->hChecked = LoadImage( g_hinstance,
  51. MAKEINTRESOURCE( IDB_CHECK ),
  52. IMAGE_BITMAP,
  53. 0, 0,
  54. LR_DEFAULTSIZE | LR_LOADTRANSPARENT );
  55. DebugMemoryAddHandle( psdd->hChecked );
  56. GetObject( psdd->hChecked, sizeof(bm), &bm );
  57. psdd->dwWidth = bm.bmWidth;
  58. psdd->hError = LoadImage( g_hinstance,
  59. MAKEINTRESOURCE( IDB_X ),
  60. IMAGE_BITMAP,
  61. 0, 0,
  62. LR_DEFAULTSIZE | LR_LOADTRANSPARENT );
  63. DebugMemoryAddHandle( psdd->hError );
  64. GetObject( psdd->hError, sizeof(bm), &bm );
  65. psdd->dwWidth = ( psdd->dwWidth > bm.bmWidth ? psdd->dwWidth : bm.bmWidth );
  66. psdd->hArrow = LoadImage( g_hinstance,
  67. MAKEINTRESOURCE( IDB_ARROW ),
  68. IMAGE_BITMAP,
  69. 0, 0,
  70. LR_DEFAULTSIZE | LR_LOADTRANSPARENT );
  71. DebugMemoryAddHandle( psdd->hArrow );
  72. GetObject( psdd->hArrow, sizeof(bm), &bm );
  73. psdd->dwWidth = ( psdd->dwWidth > bm.bmWidth ?
  74. psdd->dwWidth :
  75. bm.bmWidth );
  76. HWND hwnd = GetDlgItem( hDlg, IDC_L_TASKS );
  77. HFONT hFontOld = (HFONT) SendMessage( hwnd, WM_GETFONT, 0, 0);
  78. if(hFontOld != NULL)
  79. {
  80. LOGFONT lf;
  81. if ( GetObject( hFontOld, sizeof(LOGFONT), (LPSTR) &lf ) )
  82. {
  83. DWORD dw;
  84. dw = LoadString( g_hinstance,
  85. IDS_LARGEFONTNAME,
  86. lf.lfFaceName,
  87. LF_FACESIZE);
  88. Assert( dw );
  89. lf.lfWidth = 0;
  90. lf.lfWeight = 400;
  91. lf.lfHeight -= 4;
  92. psdd->hFontNormal = CreateFontIndirect(&lf);
  93. DebugMemoryAddHandle( psdd->hFontNormal );
  94. lf.lfWeight = 700;
  95. psdd->hFontBold = CreateFontIndirect(&lf);
  96. DebugMemoryAddHandle( psdd->hFontBold );
  97. }
  98. }
  99. HDC hDC = GetDC( NULL );
  100. SelectObject( hDC, psdd->hFontBold );
  101. TEXTMETRIC tm;
  102. GetTextMetrics( hDC, &tm );
  103. psdd->dwHeight = tm.tmHeight;
  104. ReleaseDC( NULL, hDC );
  105. SetWindowLongPtr( hDlg, GWLP_USERDATA, (LONG_PTR) psdd );
  106. WCHAR szTitle[ 256 ];
  107. DWORD dw;
  108. dw = LoadString( g_hinstance, IDS_APPNAME, szTitle, ARRAYSIZE(szTitle));
  109. Assert( dw );
  110. SetWindowText( hDlg, szTitle );
  111. SetDlgItemText( hDlg, IDC_S_OPERATION, L"" );
  112. CenterDialog( hDlg );
  113. return FALSE;
  114. }
  115. break;
  116. case WM_MEASUREITEM:
  117. {
  118. LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
  119. RECT rc;
  120. if ( lpmis == NULL ) {
  121. // Breaks and returns TRUE at successful completion
  122. // So returning opposite
  123. return FALSE;
  124. }
  125. HWND hwnd = GetDlgItem( hDlg, IDC_L_TASKS );
  126. GetClientRect( hwnd, &rc );
  127. lpmis->itemWidth = rc.right - rc.left;
  128. lpmis->itemHeight = psdd->dwHeight;
  129. }
  130. break;
  131. case WM_DRAWITEM:
  132. {
  133. Assert( psdd );
  134. LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
  135. if ( !lpdis ) {
  136. // Below, another null pointer in the same
  137. // data field is taken care of. We are
  138. // duplicating the result here.
  139. break; // ignore
  140. }
  141. LPLBITEMDATA plbid = (LPLBITEMDATA)lpdis->itemData;
  142. RECT rc = lpdis->rcItem;
  143. HANDLE hOldFont = INVALID_HANDLE_VALUE;
  144. WCHAR szText[MAX_PATH];
  145. if ( !plbid )
  146. break; // ignore
  147. ListBox_GetText(lpdis->hwndItem, lpdis->itemID, szText);
  148. rc.right = rc.bottom = psdd->dwWidth;
  149. switch ( plbid->uState )
  150. {
  151. case STATE_NOTSTARTED:
  152. hOldFont = SelectObject( lpdis->hDC, psdd->hFontNormal );
  153. break;
  154. case STATE_STARTED:
  155. DrawBitmap( psdd->hArrow, lpdis, &rc );
  156. hOldFont = SelectObject( lpdis->hDC, psdd->hFontBold );
  157. break;
  158. case STATE_DONE:
  159. DrawBitmap( psdd->hChecked, lpdis, &rc );
  160. hOldFont = SelectObject( lpdis->hDC, psdd->hFontNormal );
  161. break;
  162. case STATE_ERROR:
  163. DrawBitmap( psdd->hError, lpdis, &rc );
  164. hOldFont = SelectObject( lpdis->hDC, psdd->hFontNormal );
  165. break;
  166. }
  167. rc = lpdis->rcItem;
  168. rc.left += psdd->dwHeight;
  169. DrawText( lpdis->hDC, plbid->pszText, -1, &rc, DT_LEFT | DT_VCENTER );
  170. if ( hOldFont != INVALID_HANDLE_VALUE )
  171. {
  172. SelectObject( lpdis->hDC, hOldFont );
  173. }
  174. }
  175. break;
  176. case WM_CTLCOLORLISTBOX:
  177. if ( hBrush == NULL )
  178. {
  179. LOGBRUSH brush;
  180. brush.lbColor = GetSysColor( COLOR_3DFACE );
  181. brush.lbStyle = BS_SOLID;
  182. hBrush = (HBRUSH) CreateBrushIndirect( &brush );
  183. DebugMemoryAddHandle( hBrush );
  184. }
  185. SetBkMode( (HDC) wParam, OPAQUE );
  186. SetBkColor( (HDC) wParam, GetSysColor( COLOR_3DFACE ) );
  187. return (INT_PTR)hBrush;
  188. case WM_DESTROY:
  189. if ( hBrush != NULL )
  190. {
  191. DebugMemoryDelete( hBrush );
  192. DeleteObject(hBrush);
  193. hBrush = NULL;
  194. }
  195. Assert( psdd );
  196. DeleteObject( psdd->hChecked );
  197. DebugMemoryDelete( psdd->hChecked );
  198. DeleteObject( psdd->hError );
  199. DebugMemoryDelete( psdd->hError );
  200. DeleteObject( psdd->hArrow );
  201. DebugMemoryDelete( psdd->hArrow );
  202. DeleteObject( psdd->hFontNormal );
  203. DebugMemoryDelete( psdd->hFontNormal );
  204. DeleteObject( psdd->hFontBold );
  205. DebugMemoryDelete( psdd->hFontBold );
  206. TraceFree( psdd );
  207. SetWindowLongPtr( hDlg, GWLP_USERDATA, NULL );
  208. EndDialog( g_hTasksDialog, 0 );
  209. break;
  210. case WM_SETTINGCHANGE:
  211. if ( hBrush != NULL )
  212. {
  213. DebugMemoryDelete( hBrush );
  214. DeleteObject(hBrush);
  215. hBrush = NULL;
  216. }
  217. break;
  218. case WM_UPDATE:
  219. {
  220. LPWSTR pszOperation = (LPWSTR) wParam;
  221. LPWSTR pszObject = (LPWSTR) lParam;
  222. LPWSTR pszTemp = NULL;
  223. LPWSTR psz;
  224. if ( lParam && wParam ) {
  225. RECT rect;
  226. SIZE size;
  227. HDC hdc = GetDC( hDlg );
  228. ULONG pszTempSize = 0;
  229. INT iLength = wcslen( pszOperation );
  230. psz = pszObject;
  231. if ( psz && StrCmpN( psz, L"\\\\?\\", 4) == 0 )
  232. {
  233. psz += 4;
  234. }
  235. GetWindowRect( GetDlgItem( hDlg, IDC_S_OPERATION ), &rect );
  236. if (hdc != NULL) {
  237. GetTextExtentPoint( hdc, pszOperation, iLength, &size );
  238. PathCompactPath( hdc, psz, rect.right - rect.left - size.cx );
  239. ReleaseDC( hDlg, hdc );
  240. }
  241. pszTempSize = iLength + wcslen(psz) + 2; // +1 space +1 NULL
  242. pszTemp = (LPWSTR) TraceAlloc( LMEM_FIXED, pszTempSize * sizeof(WCHAR));
  243. if (!pszTemp )
  244. goto Update_Cleanup;
  245. _snwprintf( pszTemp, pszTempSize, pszOperation, psz );
  246. pszTemp[pszTempSize-1] = 0;
  247. psz = pszTemp;
  248. } else if ( pszObject ) {
  249. psz = pszObject;
  250. } else if ( wParam ) {
  251. psz = pszOperation;
  252. } else {
  253. psz = L"";
  254. }
  255. Assert( psz );
  256. SetDlgItemText( hDlg, IDC_S_OPERATION, psz );
  257. Update_Cleanup:
  258. if ( pszTemp )
  259. TraceFree( pszTemp );
  260. if ( pszObject )
  261. TraceFree( pszObject );
  262. if ( pszOperation )
  263. TraceFree( pszOperation );
  264. }
  265. break;
  266. case WM_ERROR:
  267. case WM_ERROR_OK:
  268. //
  269. // Close the log file to prevent the "write-behind / data-loss" popups.
  270. //
  271. if ( g_hLogFile != INVALID_HANDLE_VALUE ) {
  272. CloseHandle( g_hLogFile );
  273. g_hLogFile = INVALID_HANDLE_VALUE;
  274. }
  275. // Signal that the error log should be displayed.
  276. g_fErrorOccurred = TRUE;
  277. result = TRUE; // message processed
  278. if ( lParam != NULL )
  279. {
  280. LBITEMDATA * pitem = (LBITEMDATA *) lParam;
  281. LPWSTR pszFile = pitem->pszText;
  282. DWORD Error = pitem->uState;
  283. // Remove the "\\?\" from the beginning of the line
  284. if ( pszFile != NULL
  285. && StrCmpN( pszFile, L"\\\\?\\", 4 ) == 0 )
  286. {
  287. pszFile = &pszFile[4];
  288. }
  289. switch (Error)
  290. {
  291. case ERROR_DISK_FULL:
  292. {
  293. WCHAR szTemplate[ 1024 ];
  294. INT i = MessageBoxFromStrings( hDlg, IDS_DISK_FULL_TITLE, IDS_DISK_FULL_TEXT, MB_ABORTRETRYIGNORE );
  295. DWORD dw;
  296. dw = LoadString( g_hinstance, IDS_DISK_FULL_TEXT, szTemplate, ARRAYSIZE(szTemplate) );
  297. Assert( dw );
  298. LogMsg( szTemplate );
  299. if ( i == IDABORT )
  300. {
  301. pitem->uState = ERROR_REQUEST_ABORTED;
  302. }
  303. else if ( i == IDRETRY )
  304. {
  305. pitem->uState = ERROR_RETRY;
  306. }
  307. else // ignore the error
  308. {
  309. pitem->uState = ERROR_SUCCESS;
  310. }
  311. }
  312. break;
  313. case ERROR_FILE_ENCRYPTED:
  314. {
  315. INT i = IDOK;
  316. WCHAR szTemplate[ 1024 ]; // random
  317. WCHAR szText[ ARRAYSIZE(szTemplate) + MAX_PATH ];
  318. WCHAR szTitle[ MAX_PATH ]; // random
  319. DWORD dw;
  320. dw = LoadString( g_hinstance, IDS_ENCRYPTED_FILE_TEXT, szTemplate, ARRAYSIZE(szTemplate) );
  321. Assert( dw );
  322. dw = LoadString( g_hinstance, IDS_ENCRYPTED_FILE_TITLE, szTitle, ARRAYSIZE(szTitle) );
  323. Assert( dw );
  324. _snwprintf( szText, ARRAYSIZE(szText), szTemplate, pszFile );
  325. TERMINATE_BUFFER(szText);
  326. if ( !g_fQuietFlag ) {
  327. i = MessageBox( hDlg, szText, szTitle, MB_OKCANCEL );
  328. }
  329. dw = LoadString( g_hinstance, IDS_ENCRYPTED_FILE_LOG, szTemplate, ARRAYSIZE(szTemplate) );
  330. Assert( dw );
  331. LogMsg( szTemplate, pszFile );
  332. pitem->uState = ( i == IDOK ? ERROR_SUCCESS : ERROR_REQUEST_ABORTED );
  333. }
  334. break;
  335. case ERROR_SHARING_VIOLATION:
  336. {
  337. BOOL SkipCheck = FALSE;
  338. WCHAR szTemplate[ 1024 ]; // random
  339. WCHAR szText[ ARRAYSIZE(szTemplate) + MAX_PATH ];
  340. WCHAR szTitle[ MAX_PATH ]; // random
  341. DWORD dw;
  342. if (g_hCompatibilityInf != INVALID_HANDLE_VALUE) {
  343. INFCONTEXT Context;
  344. if (SetupFindFirstLine(
  345. g_hCompatibilityInf,
  346. L"FilesToIgnoreCopyErrors",
  347. pszFile,
  348. &Context)) {
  349. pitem->uState = ERROR_SUCCESS;
  350. SkipCheck = TRUE;
  351. }
  352. }
  353. if (!SkipCheck) {
  354. dw = LoadString( g_hinstance, IDS_SHARING_VIOLATION_TEXT, szTemplate, ARRAYSIZE(szTemplate) );
  355. Assert( dw );
  356. dw = LoadString( g_hinstance, IDS_SHARING_VIOLATION_TITLE, szTitle, ARRAYSIZE(szTitle) );
  357. Assert( dw );
  358. _snwprintf( szText, ARRAYSIZE(szText), szTemplate, pszFile );
  359. TERMINATE_BUFFER(szText);
  360. if ( !g_fQuietFlag )
  361. {
  362. INT i = MessageBox( hDlg, szText, szTitle, MB_ABORTRETRYIGNORE );
  363. if ( i == IDABORT )
  364. {
  365. pitem->uState = ERROR_REQUEST_ABORTED;
  366. }
  367. else if ( i == IDRETRY )
  368. {
  369. pitem->uState = ERROR_RETRY;
  370. }
  371. else // ignore the error
  372. {
  373. pitem->uState = ERROR_SUCCESS;
  374. }
  375. }
  376. else // ignore the error - it will be logged
  377. {
  378. pitem->uState = ERROR_SUCCESS;
  379. }
  380. }
  381. dw = LoadString( g_hinstance, IDS_SHARING_VIOLATION_LOG, szTemplate, ARRAYSIZE(szTemplate) );
  382. Assert( dw );
  383. LogMsg( szTemplate, pszFile );
  384. }
  385. break;
  386. case ERROR_ACCESS_DENIED:
  387. {
  388. INT i = IDOK;
  389. WCHAR szTemplate[ 1024 ]; // random
  390. WCHAR szText[ ARRAYSIZE(szTemplate) + MAX_PATH ];
  391. WCHAR szTitle[ MAX_PATH ]; // random
  392. DWORD dw;
  393. dw = LoadString( g_hinstance, IDS_ACCESS_DENIED_TEXT, szTemplate, ARRAYSIZE(szTemplate) );
  394. Assert( dw );
  395. dw = LoadString( g_hinstance, IDS_ACCESS_DENIED_TITLE, szTitle, ARRAYSIZE(szTitle) );
  396. Assert( dw );
  397. _snwprintf( szText, ARRAYSIZE(szText), szTemplate, pszFile );
  398. TERMINATE_BUFFER(szText);
  399. if ( !g_fQuietFlag ) {
  400. i = MessageBox( hDlg, szText, szTitle, MB_OKCANCEL );
  401. }
  402. dw = LoadString( g_hinstance, IDS_ACCESS_DENIED_LOG, szTemplate, ARRAYSIZE(szTemplate) );
  403. Assert( dw );
  404. LogMsg( szTemplate, pszFile );
  405. pitem->uState = ( i == IDOK ? ERROR_SUCCESS : ERROR_REQUEST_ABORTED );
  406. }
  407. break;
  408. case ERROR_INVALID_DRIVE: // special meaning multi-disk detected
  409. {
  410. INT i = IDOK;
  411. i = MessageBoxFromStrings( hDlg, IDS_MULTIPLE_DISK_TITLE, IDS_MULTIPLE_DISK_TEXT, MB_OKCANCEL );
  412. pitem->uState = ( i == IDOK ? ERROR_SUCCESS : ERROR_REQUEST_ABORTED );
  413. }
  414. break;
  415. case ERROR_REPARSE_ATTRIBUTE_CONFLICT:
  416. {
  417. INT i = IDOK;
  418. WCHAR szTemplate[ 1024 ]; // random
  419. WCHAR szText[ ARRAYSIZE(szTemplate) + MAX_PATH ];
  420. WCHAR szTitle[ MAX_PATH ]; // random
  421. DWORD dw;
  422. dw = LoadString( g_hinstance, IDS_NOT_COPYING_REPARSE_POINT_TEXT, szTemplate, ARRAYSIZE(szTemplate) );
  423. Assert( dw );
  424. dw = LoadString( g_hinstance, IDS_NOT_COPYING_REPARSE_POINT_TITLE, szTitle, ARRAYSIZE(szTitle) );
  425. Assert( dw );
  426. _snwprintf( szText, ARRAYSIZE(szText), szTemplate, pszFile );
  427. TERMINATE_BUFFER(szText);
  428. if ( !g_fQuietFlag ) {
  429. i = MessageBox( hDlg, szText, szTitle, MB_OKCANCEL );
  430. }
  431. dw = LoadString( g_hinstance, IDS_NOT_COPYING_REPARSE_POINT_LOG, szTemplate, ARRAYSIZE(szTemplate) );
  432. Assert( dw );
  433. LogMsg( szTemplate, pszFile );
  434. pitem->uState = ( i == IDOK ? ERROR_SUCCESS : ERROR_REQUEST_ABORTED );
  435. }
  436. break;
  437. case STATUS_MISSING_SYSTEMFILE:
  438. MessageBoxFromStrings( hDlg, IDS_BOOT_PARTITION_TITLE, IDS_BOOT_PARTITION_TEXT, MB_OK );
  439. pitem->uState = ERROR_REQUEST_ABORTED; // stop copying
  440. break;
  441. case STATUS_OBJECT_TYPE_MISMATCH:
  442. MessageBoxFromStrings( hDlg, IDS_DYNAMIC_DISK_TITLE, IDS_DYNAMIC_DISK_TEXT, MB_OK );
  443. pitem->uState = ERROR_REQUEST_ABORTED; // stop copying
  444. break;
  445. case ERROR_OLD_WIN_VERSION:
  446. default:
  447. if ( Error != ERROR_SUCCESS )
  448. {
  449. if ( uMsg == WM_ERROR_OK || Error == ERROR_OLD_WIN_VERSION )
  450. {
  451. MessageBoxFromError( hDlg, (LPWSTR) pszFile, (DWORD) Error, NULL, MB_OK );
  452. pitem->uState = ERROR_REQUEST_ABORTED;
  453. }
  454. else // uMsg == WM_ERROR
  455. {
  456. WCHAR szTemplate[ 1024 ]; // random
  457. DWORD dw;
  458. dw = LoadString( g_hinstance, IDS_RETRY_ABORT_IGNORE_TEXT, szTemplate, ARRAYSIZE(szTemplate) );
  459. Assert( dw );
  460. if ( !g_fQuietFlag )
  461. {
  462. INT i;
  463. i = MessageBoxFromError(
  464. hDlg,
  465. (LPWSTR) pszFile,
  466. // this may not be an NTSTATUS error. See if it's
  467. // a winerror first.
  468. NT_SUCCESS(Error) ? Error : (DWORD)RtlNtStatusToDosError(Error),
  469. szTemplate,
  470. MB_ABORTRETRYIGNORE );
  471. if ( i == IDABORT )
  472. {
  473. pitem->uState = ERROR_REQUEST_ABORTED;
  474. }
  475. else if ( i == IDRETRY )
  476. {
  477. pitem->uState = ERROR_RETRY;
  478. }
  479. else // ignore the error
  480. {
  481. pitem->uState = ERROR_SUCCESS;
  482. }
  483. }
  484. else // ignore the error - it will be logged.
  485. {
  486. pitem->uState = ERROR_SUCCESS;
  487. }
  488. }
  489. LogMsg( L"Error 0x%08x: %s\r\n", Error, pszFile );
  490. }
  491. break;
  492. }
  493. }
  494. SetWindowLongPtr( hDlg, DWLP_MSGRESULT, result );
  495. break;
  496. }
  497. return TRUE;
  498. }