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

512 lines
17 KiB

  1. //=============================================================================*
  2. // COPYRIGHT� 2001 Microsoft Corporation and Executive Software International, Inc.
  3. //=============================================================================*
  4. // File: PostMsgC.cpp
  5. //=============================================================================*
  6. // System Include files
  7. #include "stdafx.h"
  8. #ifndef SNAPIN
  9. #ifndef NOWINDOWSH
  10. #include <windows.h>
  11. #endif
  12. #endif
  13. // ESI Common Include files
  14. #include "ErrMacro.h"
  15. extern "C" {
  16. #include "SysStruc.h"
  17. }
  18. #include "DfrgCmn.h"
  19. #include "DfrgEngn.h"
  20. #include "DiskDisp.h"
  21. #include "DfrgUI.h"
  22. #include "DfrgCtl.h"
  23. #include "GetDfrgRes.h"
  24. #include "DataIo.h"
  25. #include "DataIoCl.h"
  26. #include "Graphix.h"
  27. #include "PostMsgC.h"
  28. #include "DlgAnl.h"
  29. #include "DlgDfrg.h"
  30. #include "DfrgRes.h"
  31. #include "VolList.h"
  32. #include "FraggedFileList.h"
  33. /****************************************************************************************************************
  34. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  35. ROUTINE DESCRIPTION:
  36. This routines handles the 're-routed' window posted command messages. The general DataIo (DCOM)
  37. routines that we use would normally call the PostMessage() routine to handle incoming data requests.
  38. But for console applications, there is NO windows application to handle the PostMessage() commands,
  39. so in DataIo.cpp (SetData() routine), it was modified to call a locally define PostMessageConsole()
  40. routine instead if the user defines "ConsoleApplication" at build time.
  41. GLOBAL DATA:
  42. None
  43. INPUT:
  44. hWnd - Handle to the window - always NULL
  45. uMsg - The message.
  46. wParam - The word parameter for the message.
  47. lParam - the long parameter for the message.
  48. Note: These are the same inputs that the WndProc() routine would handle for PostMessage() commands.
  49. RETURN:
  50. TRUE
  51. */
  52. BOOL
  53. CVolume::PostMessageLocal (
  54. IN HWND hWnd,
  55. IN UINT Msg,
  56. IN WPARAM wParam,
  57. IN LPARAM lParam
  58. )
  59. {
  60. DATA_IO* pDataIo;
  61. switch (LOWORD(wParam)) {
  62. // says that the engine is instantiated, but not defragging or analyzing
  63. case ID_ENGINE_START:
  64. {
  65. Message(TEXT("ID_ENGINE_START"), -1, NULL);
  66. // The engine sends a startup block to identify the volume
  67. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  68. ENGINE_START_DATA *pEngineStartData = (ENGINE_START_DATA*) &(pDataIo->cData);
  69. EF_ASSERT(pDataIo->ulDataSize == sizeof(ENGINE_START_DATA));
  70. // the engine is running, unlock the buttons
  71. EngineState(ENGINE_STATE_RUNNING);
  72. Locked(FALSE);
  73. m_pVolList->Locked(FALSE);
  74. Paused(FALSE);
  75. StoppedByUser(FALSE);
  76. // make sure the startup volume is the current volume in the UI
  77. EF_ASSERT(!lstrcmp(FileSystem(), pEngineStartData->cFileSystem));
  78. // set the defrag mode to what the engine says
  79. DefragMode(pEngineStartData->dwAnalyzeOrDefrag);
  80. // set the UI buttons for the current state
  81. m_pDfrgCtl->SetButtonState();
  82. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  83. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  84. break;
  85. }
  86. // defrag or analyze has actually started
  87. case ID_BEGIN_SCAN:
  88. {
  89. Message(TEXT("ID_BEGIN_SCAN"), -1, NULL);
  90. //Get a pointer to the data sent via DCOM.
  91. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  92. BEGIN_SCAN_INFO* pScanInfo = (BEGIN_SCAN_INFO*)&(pDataIo->cData);
  93. //Make sure this is a valid size packet.
  94. EF_ASSERT(pDataIo->ulDataSize == sizeof(BEGIN_SCAN_INFO));
  95. //Make sure the engine agrees which file system it's running on.
  96. EF_ASSERT(!lstrcmp(FileSystem(), pScanInfo->cFileSystem));
  97. // the engine is running, unlock the buttons
  98. EngineState(ENGINE_STATE_RUNNING);
  99. m_pVolList->Locked(FALSE);
  100. Locked(FALSE);
  101. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  102. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  103. break;
  104. }
  105. // user pressed Pause button, engine acknowledges
  106. case ID_PAUSE_ON_SNAPSHOT:
  107. {
  108. Message(TEXT("ID_PAUSE"), -1, NULL);
  109. NOT_DATA* pNotData;
  110. //Get a pointer to the data sent via DCOM.
  111. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  112. pNotData = (NOT_DATA*)&(pDataIo->cData);
  113. //Make sure this is a valid size packet.
  114. EF_ASSERT(pDataIo->ulDataSize >= sizeof(NOT_DATA));
  115. PausedBySnapshot(TRUE);
  116. Paused(TRUE);
  117. Locked(FALSE);
  118. m_pDfrgCtl->SetButtonState();
  119. m_pDfrgCtl->RefreshListViewRow( this );
  120. m_pDfrgCtl->InvalidateGraphicsWindow();
  121. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  122. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  123. break;
  124. }
  125. case ID_PAUSE:
  126. {
  127. Message(TEXT("ID_PAUSE"), -1, NULL);
  128. NOT_DATA* pNotData;
  129. //Get a pointer to the data sent via DCOM.
  130. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  131. pNotData = (NOT_DATA*)&(pDataIo->cData);
  132. //Make sure this is a valid size packet.
  133. EF_ASSERT(pDataIo->ulDataSize >= sizeof(NOT_DATA));
  134. Paused(TRUE);
  135. Locked(FALSE);
  136. m_pDfrgCtl->SetButtonState();
  137. m_pDfrgCtl->RefreshListViewRow( this );
  138. m_pDfrgCtl->InvalidateGraphicsWindow();
  139. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  140. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  141. break;
  142. }
  143. // user pressed Resume button, engine acknowledges
  144. case ID_CONTINUE:
  145. {
  146. Message(TEXT("ID_CONTINUE"), -1, NULL);
  147. NOT_DATA* pNotData;
  148. //Get a pointer to the data sent via DCOM.
  149. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  150. pNotData = (NOT_DATA*)&(pDataIo->cData);
  151. //Make sure this is a valid size packet.
  152. EF_ASSERT(pDataIo->ulDataSize >= sizeof(NOT_DATA));
  153. Paused(FALSE);
  154. PausedBySnapshot(FALSE);
  155. Locked(FALSE);
  156. m_pDfrgCtl->SetButtonState();
  157. m_pDfrgCtl->RefreshListViewRow( this );
  158. m_pDfrgCtl->InvalidateGraphicsWindow();
  159. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  160. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  161. break;
  162. }
  163. // defrag or analyze has ended
  164. case ID_END_SCAN:
  165. {
  166. BOOL bFragmented = FALSE;
  167. Message(TEXT("ID_END_SCAN"), -1, NULL);
  168. END_SCAN_DATA* pEndScanData;
  169. //Get a pointer to the data sent via DCOM.
  170. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  171. pEndScanData = (END_SCAN_DATA*)&(pDataIo->cData);
  172. //Make sure this is a valid size packet.
  173. EF_ASSERT(pDataIo->ulDataSize >= sizeof(END_SCAN_DATA));
  174. // did the file system somehow magically change?
  175. EF_ASSERT(!lstrcmp(FileSystem(), pEndScanData->cFileSystem));
  176. bFragmented = ((pEndScanData->dwAnalyzeOrDefrag & DEFRAG_FAILED ) ? TRUE: FALSE);
  177. pEndScanData->dwAnalyzeOrDefrag = DWORD(LOWORD(pEndScanData->dwAnalyzeOrDefrag));
  178. // i'm not sure how this could change, but i'll set it anyway
  179. DefragMode(pEndScanData->dwAnalyzeOrDefrag);
  180. // the engine is now idle
  181. EngineState(ENGINE_STATE_IDLE);
  182. // set the progress bar to zero
  183. PercentDone(0,TEXT(""));
  184. // unlock the buttons
  185. Locked(FALSE);
  186. m_pDfrgCtl->InvalidateGraphicsWindow();
  187. m_pDfrgCtl->RefreshListViewRow(this);
  188. #ifdef ESI_PROGRESS_BAR
  189. m_pDfrgCtl->InvalidateProgressBar();
  190. #endif
  191. // Did the user ask it to stop - if so no pop-ups.
  192. if(!StoppedByUser()){
  193. // Note whether this was an analyze or defrag that finished.
  194. switch(DefragMode()) {
  195. case ANALYZE:
  196. RaiseAnalyzeDoneDialog(this);
  197. break;
  198. case DEFRAG:
  199. RaiseDefragDoneDialog(this, bFragmented);
  200. break;
  201. default:
  202. EF_ASSERT(FALSE);
  203. break;
  204. }
  205. }
  206. Paused(FALSE);
  207. m_pDfrgCtl->SetButtonState();
  208. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  209. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  210. break;
  211. }
  212. // engine died
  213. case ID_TERMINATING:
  214. {
  215. Message(TEXT("ID_TERMINATING"), -1, NULL);
  216. NOT_DATA* pNotData;
  217. //Get a pointer to the data sent via DCOM.
  218. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  219. pNotData = (NOT_DATA*)&(pDataIo->cData);
  220. //Make sure this is a valid size packet.
  221. EF_ASSERT(pDataIo->ulDataSize >= sizeof(NOT_DATA));
  222. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  223. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  224. // get rid of the graphics data
  225. Reset();
  226. // was this engine aborted so that it could be restarted?
  227. if(Restart()){
  228. // turn the restart state off
  229. Restart(FALSE);
  230. // send an ANALYZE or DEFRAG message to restart the engine
  231. if (DefragMode() == DEFRAG){
  232. Defragment();
  233. }
  234. else {
  235. Analyze();
  236. }
  237. }
  238. break;
  239. }
  240. // engine error data
  241. case ID_ERROR:
  242. {
  243. ERROR_DATA* pErrorData;
  244. // Get a pointer to the data sent via DCOM.
  245. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  246. pErrorData = (ERROR_DATA*)&(pDataIo->cData);
  247. // Make sure this is a valid size packet.
  248. EF_ASSERT(pDataIo->ulDataSize >= sizeof(ERROR_DATA));
  249. if (_tcslen(pErrorData->cErrText) > 0) {
  250. VString title(IDS_DK_TITLE, GetDfrgResHandle());
  251. m_pDfrgCtl->MessageBox(pErrorData->cErrText, title.GetBuffer(), MB_OK|MB_ICONSTOP);
  252. }
  253. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  254. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  255. break;
  256. }
  257. // sends the progress bar setting and the status that is
  258. // displayed in the list view
  259. case ID_STATUS:
  260. {
  261. Message(TEXT("ID_STATUS"), -1, NULL);
  262. //Get a pointer to the data sent via DCOM.
  263. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  264. STATUS_DATA *pStatusData = (STATUS_DATA*) &(pDataIo->cData);
  265. //Make sure this is a valid size packet.
  266. EF_ASSERT(pDataIo->ulDataSize == sizeof(STATUS_DATA));
  267. if (!StoppedByUser()){
  268. //Get the percent dones for the status bar
  269. //acs// Get the Pass we are on.
  270. Pass(pStatusData->dwPass);
  271. // if (PercentDone() != pStatusData->dwPercentDone){
  272. PercentDone(pStatusData->dwPercentDone,pStatusData->vsFileName);
  273. #ifdef ESI_PROGRESS_BAR
  274. m_pDfrgCtl->InvalidateProgressBar();
  275. #endif
  276. // }
  277. if (DefragState() != pStatusData->dwEngineState){
  278. Message(TEXT("DefragState changed"), -1, NULL);
  279. DefragState(pStatusData->dwEngineState);
  280. m_pDfrgCtl->RefreshListViewRow(this);
  281. m_pDfrgCtl->InvalidateGraphicsWindow();
  282. }
  283. }
  284. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  285. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  286. break;
  287. }
  288. // sends the list of most fragged files
  289. case ID_FRAGGED_DATA:{
  290. Message(TEXT("ID_FRAGGED_DATA"), -1, NULL);
  291. //Get a pointer to the data sent via DCOM.
  292. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  293. EF_ASSERT(pDataIo);
  294. PTCHAR pTransferBuffer = &(pDataIo->cData);
  295. // parse the transfer buffer and build the
  296. // fragged file list list in the container
  297. m_FraggedFileList.ParseTransferBuffer(pTransferBuffer);
  298. //Make sure this is a valid size packet.
  299. DWORD transBufSize = m_FraggedFileList.GetTransferBufferSize();
  300. EF_ASSERT(pDataIo->ulDataSize == transBufSize);
  301. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  302. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  303. break;
  304. }
  305. // sends the data displayed in the graphic wells (cluster maps)
  306. case ID_DISP_DATA:
  307. {
  308. //Get a pointer to the data sent via DCOM.
  309. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  310. DISPLAY_DATA* pDispData = (DISPLAY_DATA*)&(pDataIo->cData);
  311. //Make sure this is a valid size packet.
  312. EF_ASSERT(pDataIo->ulDataSize >= sizeof(DISPLAY_DATA));
  313. if (!StoppedByUser()){
  314. Message(TEXT("ID_DISP_DATA received analyze data."), -1, NULL);
  315. m_AnalyzeDisplay.SetLineArray(
  316. (char*)&(pDispData->LineArray),
  317. pDispData->dwAnalyzeNumLines);
  318. Message(TEXT("ID_DISP_DATA received defrag data."), -1, NULL);
  319. m_DefragDisplay.SetLineArray(
  320. (char*)((BYTE*)&pDispData->LineArray) + pDispData->dwAnalyzeNumLines,
  321. pDispData->dwDefragNumLines);
  322. //Repaint graphics area
  323. m_pDfrgCtl->InvalidateGraphicsWindow();
  324. }
  325. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  326. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  327. break;
  328. }
  329. // sends the text data that is displayed on the report
  330. case ID_REPORT_TEXT_DATA:
  331. {
  332. Message(TEXT("ID_REPORT_TEXT_DATA"), -1, NULL);
  333. TEXT_DATA* pTextData = NULL;
  334. //Get a pointer to the data sent via DCOM.
  335. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  336. pTextData = (TEXT_DATA*)&(pDataIo->cData);
  337. //Make sure this is a valid size packet.
  338. EF_ASSERT(pDataIo->ulDataSize >= sizeof(TEXT_DATA));
  339. //Copy over the text display information.
  340. CopyMemory(&m_TextData, pTextData, sizeof(TEXT_DATA));
  341. //Check for not enough disk space
  342. if (!WasFutilityChecked()){
  343. // check futility
  344. if (WarnFutility()){
  345. StoppedByUser(TRUE);
  346. AbortEngine(TRUE); // abort
  347. DefragState(DEFRAG_STATE_NONE); // defrag state is now NONE
  348. Reset();
  349. }
  350. // set futility checked
  351. WasFutilityChecked(TRUE);
  352. }
  353. Message(TEXT("ID_REPORT_TEXT_DATA - end"), -1, NULL);
  354. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  355. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  356. break;
  357. }
  358. case ID_NO_GRAPHICS_MEMORY:
  359. {
  360. Message(TEXT("ID_NO_GRAPHICS_MEMORY"), -1, NULL);
  361. NOT_DATA* pNotData;
  362. //Get a pointer to the data sent via DCOM.
  363. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  364. pNotData = (NOT_DATA*)&(pDataIo->cData);
  365. //Make sure this is a valid size packet.
  366. EF_ASSERT(pDataIo->ulDataSize >= sizeof(NOT_DATA));
  367. //Set no graphics flag
  368. NoGraphicsMemory(TRUE);
  369. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  370. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  371. break;
  372. }
  373. case ID_PING:
  374. // Do nothing.
  375. // This is just a ping sent by the engine to make sure the UI is still up.
  376. {
  377. Message(TEXT("ID_PING"), -1, NULL);
  378. NOT_DATA* pNotData;
  379. //Get a pointer to the data sent via DCOM.
  380. pDataIo = (DATA_IO*)GlobalLock((void*)lParam);
  381. pNotData = (NOT_DATA*)&(pDataIo->cData);
  382. //Make sure this is a valid size packet.
  383. EF_ASSERT(pDataIo->ulDataSize >= sizeof(NOT_DATA));
  384. EH_ASSERT(GlobalUnlock((void*)lParam) == FALSE);
  385. EH_ASSERT(GlobalFree((void*)lParam) == NULL);
  386. break;
  387. }
  388. default:
  389. EF_ASSERT(FALSE);
  390. break;
  391. }
  392. return TRUE;
  393. }