Old fashion design for PC-104
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.

1040 lines
25 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: TabReportDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of TabReportDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // TabReportDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "MultiIPIClient.h"
  18. #include "TabReportDlg.h"
  19. #include "TabReportDlg.h"
  20. #include "MainDlg.h"
  21. #include "..\LgLib\LgAux.h"
  22. #include "..\LgLib\LgPerformanceCounter.h"
  23. #include <shlwapi.h>
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. #define REPORT_IMAGES_IN_BLOCK 4
  30. CTabReportDlg::CTabReportDlg(CWnd* pParent /*=0*/)
  31. : CDialog(CTabReportDlg::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(CTabReportDlg)
  34. // NOTE: the ClassWizard will add member initialization here
  35. //}}AFX_DATA_INIT
  36. m_hListTreeNode = TVI_ROOT;
  37. m_bListWait = TRUE;
  38. m_nListLevel = 0;
  39. m_pListBuffer = 0;
  40. m_nListBufferSize = 0;
  41. m_bFileWait = FALSE;
  42. m_ppListPtr = NULL;
  43. m_nListPtrCount = 0;
  44. m_pListLocator = NULL;
  45. m_pListImage = NULL;
  46. m_pListPreview = NULL;
  47. m_pListText = NULL;
  48. }
  49. CTabReportDlg::~CTabReportDlg()
  50. {
  51. if( m_pListBuffer )
  52. {
  53. free( m_pListBuffer );
  54. }
  55. if( m_ppListPtr )
  56. {
  57. free( m_ppListPtr );
  58. }
  59. }
  60. void CTabReportDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CTabReportDlg)
  64. DDX_Control(pDX, IDC_BUTTON_DETECTION, m_ButtonDetection);
  65. DDX_Control(pDX, IDC_STATIC_PREVIEW, m_StaticPreview);
  66. DDX_Control(pDX, IDC_SLIDER_PREVIEW, m_SliderPreview);
  67. DDX_Control(pDX, IDC_SLIDER_IMAGE, m_SliderImage);
  68. DDX_Control(pDX, IDC_STATIC_IMAGE, m_StaticImage);
  69. DDX_Control(pDX, IDC_RICHEDIT, m_RichEdit);
  70. DDX_Control(pDX, IDC_STATIC_LOCATOR, m_StaticLocator);
  71. DDX_Control(pDX, IDC_TREE, m_Tree);
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CTabReportDlg, CDialog)
  75. //{{AFX_MSG_MAP(CTabReportDlg)
  76. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
  77. ON_WM_VSCROLL()
  78. ON_WM_SHOWWINDOW()
  79. ON_WM_PAINT()
  80. ON_BN_CLICKED(IDC_BUTTON_DETECTION, OnButtonDetection)
  81. ON_WM_HSCROLL()
  82. //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84. void MakeTempName( LPTSTR pTempName, LPTSTR pName )
  85. {
  86. strcpy( (LPTSTR)pTempName, "CACHE" );
  87. ::PathAppend( pTempName, pName );
  88. }
  89. BOOL CTabReportDlg::CheckFile( LPCTSTR pFileName, DWORD dwFileSize )
  90. {
  91. TRACE( "CHECK FILE\n" );
  92. TCHAR pFullName[MAX_PATH];
  93. strcpy( pFullName, m_pListName );
  94. ::PathAppend( pFullName, (PCHAR)pFileName );
  95. strupr( pFullName );
  96. if( !IsInCache( (PCHAR)pFullName, &dwFileSize ) )
  97. {
  98. if( dwFileSize && strstr( pFullName, "TARGET" ) )
  99. {
  100. // show particly loaded file
  101. TCHAR pTempName[MAX_PATH];
  102. MakeTempName( pTempName, pFullName );
  103. ShowDataFile( pTempName );
  104. }
  105. strcpy( m_pFileName, (PCHAR)pFullName );
  106. m_bFileWait = m_pMainDlg->GetDeviceClient()->DoRemoteReportFile( REMOTE_CONTEXT_CLIENT, (LPCTSTR)m_pFileName, strlen( (LPCTSTR)m_pFileName ) + 1, dwFileSize );
  107. if( !m_bFileWait )
  108. {
  109. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTabReportDlg::CheckFile"), _T("m_pMainDlg->GetDeviceClient()->DoRemoteReportFile failed") );
  110. }
  111. return FALSE;
  112. }
  113. else
  114. {
  115. TCHAR pTempName[MAX_PATH];
  116. MakeTempName( pTempName, pFullName );
  117. ShowDataFile( pTempName );
  118. }
  119. return TRUE;
  120. }
  121. void CTabReportDlg::DownloadListFromHost()
  122. {
  123. TRACE( "DownloadListFromHost\n" );
  124. // make asknowledge depend on level
  125. if( m_hListTreeNode != TVI_ROOT )
  126. {
  127. INT nLength = 0;
  128. m_nListLevel = MakeTreePath( m_hListTreeNode, m_pListName, &nLength );
  129. m_bListWait = m_pMainDlg->GetDeviceClient()->DoRemoteReportList( REMOTE_CONTEXT_CLIENT, m_pListName, nLength );
  130. if( !m_bListWait )
  131. {
  132. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTabReportDlg::DownloadListFromHost"), _T("m_pMainDlg->GetDeviceClient()->DoRemoteReportList 1 failed") );
  133. }
  134. }
  135. else
  136. {
  137. m_bListWait = m_pMainDlg->GetDeviceClient()->DoRemoteReportList( REMOTE_CONTEXT_CLIENT, NULL, 0 );
  138. if( !m_bListWait )
  139. {
  140. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTabReportDlg::DownloadListFromHost"), _T("m_pMainDlg->GetDeviceClient()->DoRemoteReportList 2 failed") );
  141. }
  142. }
  143. // clear everythink
  144. ClearCurrentReport();
  145. // try to open it immediatly (from cache)
  146. if( m_nListLevel == 2 )
  147. OpenFromCache( m_pListName );
  148. }
  149. void CTabReportDlg::DownloadFileFromHost()
  150. {
  151. TRACE( "DownloadFileFromHost\n" );
  152. // first of all transfer only importent files
  153. PCHAR pList = m_pListBuffer;
  154. INT nSize = m_nListBufferSize;
  155. if( m_nFileLevel < 4 )
  156. {
  157. switch( m_nFileLevel )
  158. {
  159. case 0: // locator
  160. if( m_pListLocator && !CheckFile( m_pListLocator+4, *(PDWORD)m_pListLocator ) )
  161. return;
  162. m_nFileLevel++;
  163. m_pListLocator = NULL;
  164. case 1: // 1st image
  165. if( m_pListPreview && !CheckFile( m_pListPreview+4, *(PDWORD)m_pListPreview ) )
  166. return;
  167. m_nFileLevel++;
  168. m_pListPreview = NULL;
  169. case 2: // text
  170. if( m_pListImage && !CheckFile( m_pListImage+4, *(PDWORD)m_pListImage ) )
  171. return;
  172. m_nFileLevel++;
  173. m_pListImage = NULL;
  174. case 3: // remaining
  175. if( m_pListText && !CheckFile( m_pListText+4, *(PDWORD)m_pListText ) )
  176. return;
  177. m_nFileLevel++;
  178. m_pListText = NULL;
  179. }
  180. }
  181. // transfer remaining
  182. pList = m_pListBuffer;
  183. nSize = m_nListBufferSize;
  184. for( INT i = 0; i < m_nListPtrCount; i++ )
  185. {
  186. if( m_ppListPtr[i] )
  187. {
  188. DWORD dwFileSize = *(PDWORD)m_ppListPtr[i];
  189. PCHAR pFileName = m_ppListPtr[i] + 4;
  190. if( !CheckFile( pFileName, dwFileSize ) )
  191. break;
  192. m_ppListPtr[i] = NULL;
  193. }
  194. }
  195. }
  196. void CTabReportDlg::SetReportList( PBYTE pList, INT nSize )
  197. {
  198. TRACE( "SET REPORT LIST\n" );
  199. if( m_nListLevel < 2 )
  200. {
  201. // clear cache
  202. if( m_nListLevel == 0 )
  203. DeleteOldFiles( pList, nSize );
  204. INT nNewItemCount = 0;
  205. HTREEITEM hChild = (m_hListTreeNode == TVI_ROOT) ? m_Tree.GetRootItem() : m_Tree.GetChildItem( m_hListTreeNode );
  206. while( nSize )
  207. {
  208. pList += 4;
  209. nSize -= 4;
  210. // take current record length
  211. INT nLength = strlen( (PCHAR)pList );
  212. // add new node (if it really new)
  213. BOOL bFound = FALSE;
  214. while( hChild )
  215. {
  216. CString Name = m_Tree.GetItemText( hChild );
  217. if( Name == pList )
  218. {
  219. bFound = TRUE;
  220. break;
  221. }
  222. hChild = m_Tree.GetNextSiblingItem( hChild );
  223. }
  224. if( !bFound )
  225. {
  226. m_Tree.InsertItem( (PCHAR)pList, m_hListTreeNode );
  227. nNewItemCount ++;
  228. }
  229. // take next record
  230. nSize -= (nLength + 1);
  231. pList += (nLength + 1);
  232. }
  233. // renew list
  234. if( nNewItemCount )
  235. m_Tree.InvalidateRect( 0 );
  236. // allow new list requests
  237. m_bListWait = FALSE;
  238. }
  239. else
  240. {
  241. // remember list
  242. m_pListBuffer = (PCHAR)realloc( m_pListBuffer, nSize );
  243. if( m_pListBuffer )
  244. {
  245. m_nListBufferSize = nSize;
  246. memcpy( m_pListBuffer, pList, nSize );
  247. }
  248. else
  249. {
  250. m_pListBuffer = 0;
  251. m_nListBufferSize = nSize = 0;
  252. }
  253. CLgPerformanceCounter pc;
  254. pc.Begin();
  255. // clear importent pointers
  256. m_pListLocator = NULL;
  257. m_pListImage = NULL;
  258. m_pListPreview = NULL;
  259. m_pListText = NULL;
  260. // prepare list
  261. m_nListPtrCount = 0;
  262. while( nSize )
  263. {
  264. // store pointer in ptr list
  265. m_ppListPtr = (PCHAR*)realloc( m_ppListPtr, sizeof( PBYTE ) * (m_nListPtrCount + 1) );
  266. if( m_ppListPtr )
  267. {
  268. // store pointer to list entry
  269. m_ppListPtr[ m_nListPtrCount ] = (PCHAR)pList;
  270. m_nListPtrCount ++;
  271. }
  272. // skip length information
  273. pList += 4;
  274. nSize -= 4;
  275. // take current record length
  276. INT nLength = strlen( (PCHAR)pList );
  277. if( strstr( (PCHAR)pList, "LOCATOR" ) )
  278. { m_pListLocator = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
  279. else
  280. if( strstr( (PCHAR)pList, "IMAGES00000" ) )
  281. { m_pListImage = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
  282. else
  283. if( strstr( (PCHAR)pList, "PREVIEW" ) )
  284. { m_pListPreview = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
  285. else
  286. if( strstr( (PCHAR)pList, "TARGET" ) )
  287. { m_pListText = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
  288. // take next record
  289. nSize -= (nLength + 1);
  290. pList += (nLength + 1);
  291. }
  292. TRACE( "LIST PROCESSING TIME IS %0.8f\n", pc.End() );
  293. if( !m_bFileWait )
  294. {
  295. m_nFileLevel = 0;
  296. DownloadFileFromHost();
  297. }
  298. // allow new list requests
  299. m_bListWait = FALSE;
  300. }
  301. }
  302. void CTabReportDlg::SetReportFile( PBYTE pBuffer, INT nSize )
  303. {
  304. TRACE( "SET REPORT FILE\n" );
  305. if( m_bFileWait )
  306. {
  307. // place new file into cache
  308. PlaceToCache( m_pFileName, pBuffer, nSize );
  309. m_bFileWait = FALSE;
  310. if( !m_bListWait )
  311. {
  312. // check tree position
  313. if( m_hListTreeNode == m_Tree.GetSelectedItem() )
  314. {
  315. DownloadFileFromHost();
  316. }
  317. else
  318. {
  319. m_hListTreeNode = m_Tree.GetSelectedItem();
  320. DownloadListFromHost();
  321. }
  322. }
  323. }
  324. }
  325. INT CTabReportDlg::MakeTreePath( HTREEITEM hNode, LPTSTR pName, PINT pLength )
  326. {
  327. TRACE( "MakeTreePath\n" );
  328. INT nLevel = 0;
  329. CString FullName;
  330. if( hNode != TVI_ROOT )
  331. {
  332. FullName = m_Tree.GetItemText( hNode );
  333. hNode = m_Tree.GetNextItem( hNode, TVGN_PARENT );
  334. nLevel++;
  335. }
  336. while( hNode )
  337. {
  338. CString SubName = m_Tree.GetItemText( hNode );
  339. hNode = m_Tree.GetNextItem( hNode, TVGN_PARENT );
  340. FullName = SubName + '\\' + FullName;
  341. nLevel++;
  342. };
  343. // copy data
  344. strcpy( pName, (LPCTSTR)FullName );
  345. *pLength = FullName.GetLength() + 1;
  346. TCHAR pTempName[MAX_PATH];
  347. MakeTempName( pTempName, pName );
  348. LgCreateDirectory( pTempName );
  349. return nLevel;
  350. }
  351. void CTabReportDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
  352. {
  353. TRACE( "OnSelchangedTree\n" );
  354. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  355. if( !m_bListWait )
  356. {
  357. TRACE( "LIST IS FREE\n" );
  358. // store current level handle
  359. m_hListTreeNode = pNMTreeView->itemNew.hItem;
  360. DownloadListFromHost();
  361. }
  362. else
  363. {
  364. TRACE( "LIST IS BUZY\n" );
  365. }
  366. *pResult = 0;
  367. }
  368. BOOL CTabReportDlg::IsInCache( LPCTSTR pFileName, PDWORD pFileSize )
  369. {
  370. TRACE( "IsInCache\n" );
  371. TCHAR pTempName[MAX_PATH];
  372. MakeTempName( pTempName, (LPTSTR)pFileName );
  373. CFile file;
  374. if( file.Open( pTempName, CFile::modeRead ) )
  375. {
  376. if( file.GetLength() >= *pFileSize )
  377. {
  378. file.Close();
  379. return TRUE;
  380. }
  381. *pFileSize = file.GetLength();
  382. file.Close();
  383. }
  384. else
  385. *pFileSize = 0;
  386. return FALSE;
  387. }
  388. BOOL CTabReportDlg::PlaceToCache( LPCTSTR pFileName, PBYTE pData, INT nCount )
  389. {
  390. TRACE( "PlaceToCache\n" );
  391. TCHAR pTempName[MAX_PATH];
  392. MakeTempName( pTempName, (LPTSTR)pFileName );
  393. INT nWritten = 0;
  394. CFile file;
  395. if( file.Open( pTempName, CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate ) )
  396. {
  397. file.SeekToEnd();
  398. file.Write( pData, nCount );
  399. file.Close();
  400. }
  401. return TRUE;
  402. }
  403. BOOL CTabReportDlg::OpenFromCache( LPCTSTR pFolderName )
  404. {
  405. TRACE( "OpenFromCache\n" );
  406. // load with new data
  407. TCHAR pTempName[MAX_PATH];
  408. MakeTempName( pTempName, (LPTSTR)pFolderName );
  409. strcat( pTempName, "*.*" );
  410. CFileFind ff;
  411. if( ff.FindFile( pTempName ) )
  412. {
  413. BOOL bContinue = TRUE;
  414. while( bContinue )
  415. {
  416. TRACE( "OPEN FROM CACHE\n" );
  417. bContinue = ff.FindNextFile();
  418. // TRACE( "%s\n", ff.GetFileName() );
  419. ShowDataFile( ff.GetFileName() );
  420. }
  421. ff.Close();
  422. }
  423. return TRUE;
  424. }
  425. BOOL CTabReportDlg::ShowDataFile( LPCTSTR pFileName )
  426. {
  427. TRACE( "ShowDataFile\n" );
  428. TCHAR pName[MAX_PATH];
  429. strcpy( pName, pFileName );
  430. strupr( pName );
  431. if( strstr( pName, "LOCATOR" ) )
  432. {
  433. TRACE( "LOCATOR\n" );
  434. CLgImageJPEG jpeg;
  435. if( jpeg.Load( pName ) )
  436. {
  437. CLgImageDIB dib;
  438. if( jpeg.ConvertToDIB( dib ) )
  439. {
  440. CRect rect;
  441. m_LocatorWnd.GetClientRect( &rect );
  442. dib.Draw( m_LocatorWnd.GetMemoryDC().GetSafeHdc(), &rect );
  443. m_LocatorWnd.InvalidateRect( NULL );
  444. return TRUE;
  445. }
  446. }
  447. }
  448. else
  449. if( strstr( pName, "PREALARM" ) )
  450. {
  451. TRACE( "PREALARM\n" );
  452. }
  453. else
  454. if( strstr( pName, "IMAGES00000" ) )
  455. {
  456. m_SliderImage.SetRange( 0, ( atoi( strstr( pName, "IMAGES" ) + 6 ) + 1 ) * REPORT_IMAGES_IN_BLOCK );
  457. TRACE( "%d IMAGES\n", atoi( strstr( pName, "IMAGES" ) + 6 ) );
  458. CLgImageJPEG jpeg;
  459. if( jpeg.Load( pName ) )
  460. {
  461. CLgImageDIB dib;
  462. if( jpeg.ConvertToDIB( dib ) )
  463. {
  464. CRect rect;
  465. m_StaticImage.GetClientRect( &rect );
  466. rect.bottom *= ((LPBITMAPINFO)dib)->bmiHeader.biHeight / 288;
  467. dib.Draw( m_ImageWnd.GetMemoryDC().GetSafeHdc(), &rect );
  468. m_ImageWnd.InvalidateRect( NULL );
  469. return TRUE;
  470. }
  471. }
  472. }
  473. else
  474. if( strstr( pName, "IMAGES" ) )
  475. {
  476. m_SliderImage.SetRange( 0, ( atoi( strstr( pName, "IMAGES" ) + 6 ) + 1 ) * REPORT_IMAGES_IN_BLOCK );
  477. TRACE( "%d IMAGES\n", atoi( strstr( pName, "IMAGES" ) + 6 ) );
  478. }
  479. else
  480. if( strstr( pName, "TARGETS" ) )
  481. {
  482. TRACE( "TARGETS\n" );
  483. CFile file;
  484. if( file.Open( pName, CFile::modeRead ) )
  485. {
  486. DWORD dwSize = file.GetLength();
  487. PBYTE pBuffer = new BYTE[ dwSize + 1 ];
  488. if( pBuffer )
  489. {
  490. file.Read( pBuffer, dwSize );
  491. pBuffer[ dwSize ] = 0;
  492. m_RichEdit.SetWindowText( (PCHAR)pBuffer );
  493. delete [] pBuffer;
  494. }
  495. file.Close();
  496. }
  497. }
  498. else
  499. {
  500. TRACE( "ERROR\n" );
  501. }
  502. return FALSE;
  503. }
  504. BOOL CTabReportDlg::OnInitDialog()
  505. {
  506. CDialog::OnInitDialog();
  507. CRect rect;
  508. m_StaticLocator.GetClientRect( &rect );
  509. m_LocatorWnd.Create( this, rect );
  510. m_StaticPreview.GetClientRect( &rect );
  511. m_PreviewWnd.Create( this, rect );
  512. m_StaticImage.GetClientRect( &rect );
  513. m_ImageWnd.Create( this, rect );
  514. return TRUE; // return TRUE unless you set the focus to a control
  515. // EXCEPTION: OCX Property Pages should return FALSE
  516. }
  517. void CTabReportDlg::InitFromCache()
  518. {
  519. }
  520. void CTabReportDlg::ClearCurrentReport()
  521. {
  522. CRect rect;
  523. m_LocatorWnd.GetClientRect( &rect );
  524. m_LocatorWnd.GetMemoryDC().FillSolidRect( &rect, RGB(0,0,0) );
  525. m_LocatorWnd.InvalidateRect( NULL );
  526. m_ImageWnd.GetClientRect( &rect );
  527. m_ImageWnd.GetMemoryDC().FillSolidRect( &rect, RGB(0,0,0) );
  528. m_ImageWnd.InvalidateRect( NULL );
  529. m_PreviewWnd.GetClientRect( &rect );
  530. m_PreviewWnd.GetMemoryDC().FillSolidRect( &rect, RGB(0,0,0) );
  531. m_PreviewWnd.InvalidateRect( NULL );
  532. m_RichEdit.SetWindowText( "" );
  533. m_SliderImage.SetPos(0);
  534. m_SliderPreview.SetPos(0);
  535. m_SliderImage.SetRange(0,-1);
  536. m_SliderPreview.SetRange(0,-1);
  537. }
  538. void CTabReportDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  539. {
  540. CSliderCtrl *pSlider = (CSliderCtrl*)pScrollBar;
  541. if( pSlider->GetDlgCtrlID() == IDC_SLIDER_IMAGE )
  542. {
  543. CHAR pPathName[MAX_PATH];
  544. INT nLength;
  545. MakeTreePath( m_Tree.GetSelectedItem(), pPathName, &nLength );
  546. CHAR pFileName[MAX_PATH];
  547. sprintf( pFileName, "IMAGES%05d.JPG", m_SliderImage.GetPos() / REPORT_IMAGES_IN_BLOCK );
  548. ::PathAppend( pPathName, pFileName );
  549. MakeTempName( pFileName, pPathName );
  550. CLgImageJPEG jpeg;
  551. if( jpeg.Load( pFileName ) )
  552. {
  553. CLgImageDIB dib;
  554. if( jpeg.ConvertToDIB( dib ) )
  555. {
  556. CRect rect;
  557. m_StaticImage.GetClientRect( &rect );
  558. INT nHeight = rect.bottom;
  559. rect.bottom *= ((LPBITMAPINFO)dib)->bmiHeader.biHeight / 288;
  560. rect.OffsetRect( 0, - ( REPORT_IMAGES_IN_BLOCK - 1 - (m_SliderImage.GetPos() % REPORT_IMAGES_IN_BLOCK) ) * nHeight );
  561. dib.Draw( m_ImageWnd.GetMemoryDC().GetSafeHdc(), &rect );
  562. m_ImageWnd.InvalidateRect( NULL );
  563. }
  564. }
  565. }
  566. CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  567. }
  568. void CTabReportDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  569. {
  570. CSliderCtrl *pSlider = (CSliderCtrl*)pScrollBar;
  571. if( pSlider->GetDlgCtrlID() == IDC_SLIDER_IMAGE )
  572. {
  573. CHAR pPathName[MAX_PATH];
  574. INT nLength;
  575. MakeTreePath( m_Tree.GetSelectedItem(), pPathName, &nLength );
  576. CHAR pFileName[MAX_PATH];
  577. sprintf( pFileName, "IMAGES%05d.JPG", m_SliderImage.GetPos() / REPORT_IMAGES_IN_BLOCK );
  578. ::PathAppend( pPathName, pFileName );
  579. MakeTempName( pFileName, pPathName );
  580. CLgImageJPEG jpeg;
  581. if( jpeg.Load( pFileName ) )
  582. {
  583. CLgImageDIB dib;
  584. if( jpeg.ConvertToDIB( dib ) )
  585. {
  586. CRect rect;
  587. m_StaticImage.GetClientRect( &rect );
  588. INT nHeight = rect.bottom;
  589. rect.bottom *= ((LPBITMAPINFO)dib)->bmiHeader.biHeight / 288;
  590. rect.OffsetRect( 0, - ( REPORT_IMAGES_IN_BLOCK - 1 - (m_SliderImage.GetPos() % REPORT_IMAGES_IN_BLOCK) ) * nHeight );
  591. dib.Draw( m_ImageWnd.GetMemoryDC().GetSafeHdc(), &rect );
  592. m_ImageWnd.InvalidateRect( NULL );
  593. }
  594. }
  595. }
  596. CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  597. }
  598. void CTabReportDlg::OnShowWindow(BOOL bShow, UINT nStatus)
  599. {
  600. CDialog::OnShowWindow(bShow, nStatus);
  601. if( bShow )
  602. {
  603. if( !m_bListWait )
  604. {
  605. TRACE( "LIST IS FREE\n" );
  606. // store current level handle
  607. m_hListTreeNode = TVI_ROOT;
  608. DownloadListFromHost();
  609. }
  610. else
  611. {
  612. TRACE( "LIST IS BUZY\n" );
  613. }
  614. }
  615. }
  616. BOOL CTabReportDlg::PreTranslateMessage(MSG* pMsg)
  617. {
  618. switch( pMsg->message )
  619. {
  620. case WM_KEYDOWN:
  621. switch( pMsg->wParam )
  622. {
  623. case VK_SPACE:
  624. m_pMainDlg->AlarmStop();
  625. break;
  626. }
  627. break;
  628. }
  629. return CDialog::PreTranslateMessage(pMsg);
  630. }
  631. void CTabReportDlg::UpdateControlPosition()
  632. {
  633. CProgramSkin::SKIN skin;
  634. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_IMAGE, skin ) )
  635. {
  636. m_ImageWnd.MoveWindow( &skin.rect );
  637. m_StaticImage.MoveWindow( &skin.rect );
  638. }
  639. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_IMAGE_SLIDER, skin ) )
  640. m_SliderImage.MoveWindow( &skin.rect );
  641. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_PREVIEW, skin ) )
  642. m_PreviewWnd.MoveWindow( &skin.rect );
  643. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_PREVIEW_SLIDER, skin ) )
  644. m_SliderPreview.MoveWindow( &skin.rect );
  645. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_LOCATOR, skin ) )
  646. m_LocatorWnd.MoveWindow( &skin.rect );
  647. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_TREE, skin ) )
  648. m_Tree.MoveWindow( &skin.rect );
  649. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_TEXT, skin ) )
  650. m_RichEdit.MoveWindow( &skin.rect );
  651. if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_DETECTION, skin ) )
  652. {
  653. m_ButtonDetection.MoveWindow( &skin.rect );
  654. m_ButtonDetection.SetBitmap( skin.hBitmap );
  655. }
  656. /*
  657. // space between controls
  658. INT nSpace = 5;
  659. // store client rect of control
  660. CRect ClientRect;
  661. GetClientRect( &ClientRect );
  662. // position image wnd
  663. INT nImageHeight = ( ClientRect.Height() - nSpace * 3 ) / 2;
  664. CRect ImageRect;
  665. ImageRect.SetRect( ClientRect.right - nSpace - nImageHeight * 4 / 3, nSpace,
  666. ClientRect.right - nSpace, nSpace + nImageHeight );
  667. m_StaticImage.MoveWindow( &ImageRect );
  668. m_ImageWnd.MoveWindow( &ImageRect );
  669. // position preview wnd
  670. CRect PreviewRect;
  671. PreviewRect.SetRect( ImageRect.left, ImageRect.bottom + nSpace,
  672. ImageRect.right, ClientRect.bottom - nSpace );
  673. m_StaticPreview.MoveWindow( &PreviewRect );
  674. m_PreviewWnd.MoveWindow( &PreviewRect );
  675. // slider width
  676. INT nSliderWidth = 20;
  677. // position image slider wnd
  678. CRect SliderImageRect;
  679. SliderImageRect.SetRect( ImageRect.left - nSpace - nSliderWidth, ImageRect.top,
  680. ImageRect.left - nSpace, ImageRect.bottom );
  681. m_SliderImage.MoveWindow( &SliderImageRect );
  682. // position image slider wnd
  683. CRect SliderPreviewRect;
  684. SliderPreviewRect.SetRect( PreviewRect.left - nSpace - nSliderWidth, PreviewRect.top,
  685. PreviewRect.left - nSpace, PreviewRect.bottom );
  686. m_SliderPreview.MoveWindow( &SliderPreviewRect );
  687. // position locator wnd
  688. CRect LocatorRect;
  689. LocatorRect.SetRect( SliderImageRect.left - nSpace - ImageRect.Height(), SliderImageRect.top,
  690. SliderImageRect.left - nSpace, SliderImageRect.bottom );
  691. m_StaticLocator.MoveWindow( &LocatorRect );
  692. m_LocatorWnd.MoveWindow( &LocatorRect );
  693. // position text wnd
  694. CRect TextRect;
  695. TextRect.SetRect( ClientRect.left + nSpace, LocatorRect.bottom + nSpace,
  696. LocatorRect.right, SliderPreviewRect.bottom );
  697. m_RichEdit.MoveWindow( &TextRect );
  698. // position list wnd
  699. CRect TreeRect;
  700. TreeRect.SetRect( ClientRect.left + nSpace, ClientRect.top + nSpace,
  701. LocatorRect.left - nSpace, LocatorRect.bottom );
  702. m_Tree.MoveWindow( &TreeRect );
  703. */
  704. }
  705. void CTabReportDlg::DeleteOldFiles( PBYTE pList, INT nListSize )
  706. {
  707. // WIN32_FIND_DATA win32FD;
  708. // LARGE_INTEGER ft;
  709. // LPTSTR pNames = NULL;
  710. _TCHAR pBuffer[MAX_PATH];
  711. // INT nNamesCount = 0;
  712. PBYTE pOptimazedList = (PBYTE)malloc( nListSize );
  713. if( !pOptimazedList )
  714. return;
  715. // prepare optimazed file list
  716. memcpy( pOptimazedList, pList, nListSize );
  717. INT nTempSize = nListSize;
  718. PBYTE pTempList = pOptimazedList;
  719. while( nTempSize )
  720. {
  721. pList += 4;
  722. nTempSize -= 4;
  723. // take current record length
  724. INT nLength = strlen( (PCHAR)pList ) + 1;
  725. *(PINT)pTempList = nLength;
  726. pTempList += 4;
  727. strupr( (PCHAR)pTempList );
  728. // take next record
  729. nTempSize -= nLength;
  730. pList += nLength;
  731. pTempList += nLength;
  732. }
  733. // prepare delete list
  734. PCHAR pDeleteList = NULL;
  735. INT nDeleteListSize = 0;
  736. INT nDeleteListCount = 0;
  737. CFileFind finder;
  738. BOOL bWorking = finder.FindFile("CACHE\\*.*");
  739. while (bWorking)
  740. {
  741. // get file name
  742. bWorking = finder.FindNextFile();
  743. // if it is directory name
  744. if( finder.IsDirectory() )
  745. {
  746. CString name = (LPCTSTR)finder.GetFileName();
  747. LPSTR pName = (LPTSTR)(LPCTSTR)name;
  748. if( *pName != '.' )
  749. {
  750. INT nSize = strlen( pName ) + 1;
  751. memcpy( pBuffer, pName, nSize );
  752. strupr( pBuffer );
  753. // search in list
  754. INT nTempSize = nListSize;
  755. PBYTE pTempList = pOptimazedList;
  756. BOOL bDelete = TRUE;
  757. while( nTempSize )
  758. {
  759. // take current record length
  760. INT nLength = *(PINT)pTempList;
  761. pTempList += 4;
  762. nTempSize -= 4;
  763. if( !memcmp( pTempList, pBuffer, nLength ) )
  764. {
  765. bDelete = FALSE;
  766. break;
  767. }
  768. // take next record
  769. nTempSize -= nLength;
  770. pTempList += nLength;
  771. }
  772. if( bDelete )
  773. {
  774. pDeleteList = (PCHAR)realloc( pDeleteList, nDeleteListSize + nSize + 1 + 6 );
  775. if( pDeleteList )
  776. {
  777. memcpy( pDeleteList + nDeleteListSize, "CACHE\\", 6 );
  778. memcpy( pDeleteList + nDeleteListSize + 6, pName, nSize );
  779. nDeleteListSize += (nSize+6);
  780. pDeleteList[nDeleteListSize] = 0;
  781. nDeleteListCount ++;
  782. }
  783. else
  784. nDeleteListSize = nDeleteListCount = 0;
  785. }
  786. }
  787. }
  788. }
  789. if( nDeleteListCount )
  790. {
  791. SHFILEOPSTRUCT sfs = { 0 };
  792. sfs.wFunc = FO_DELETE;
  793. sfs.pFrom = pDeleteList;
  794. sfs.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS;
  795. sfs.lpszProgressTitle = _T("Synchronizing reports...");
  796. ::SHFileOperation(&sfs);
  797. }
  798. if( pDeleteList )
  799. free( pDeleteList );
  800. free( pOptimazedList );
  801. /*
  802. ::SystemTimeToFileTime( &st, (LPFILETIME)&ft );
  803. ft.QuadPart -= m_nDays * 24i64 * 60i64 * 60i64 * 10000000i64;
  804. StickFolderNames(pBuffer, m_pProfile->SettingsReport(), _T("*.*"));
  805. HANDLE hFF = ::FindFirstFile(pBuffer, &win32FD);
  806. if(hFF != INVALID_HANDLE_VALUE)
  807. do{
  808. if(win32FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  809. {
  810. SYSTEMTIME cst = { 0 };
  811. if(_stscanf(win32FD.cFileName, _T("%02hu_%02hu_%04hu"), &cst.wDay, &cst.wMonth, &cst.wYear) == 3)
  812. {
  813. LARGE_INTEGER cft;
  814. ::SystemTimeToFileTime(&cst, (LPFILETIME)&cft);
  815. if(cft.QuadPart < ft.QuadPart)
  816. {
  817. StickFolderNames(pBuffer, m_pProfile->SettingsReport(), win32FD.cFileName );
  818. StickNames(pNames, nNamesCount, pBuffer);
  819. }
  820. }
  821. }
  822. }while(::FindNextFile(hFF, &win32FD));
  823. if(nNamesCount)
  824. {
  825. SHFILEOPSTRUCT sfs = { 0 };
  826. sfs.wFunc = FO_DELETE;
  827. sfs.pFrom = pNames;
  828. sfs.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS;
  829. sfs.lpszProgressTitle = _T("Deleting old history...");
  830. ::SHFileOperation(&sfs);
  831. delete pNames;
  832. }
  833. ::FindClose(hFF);
  834. */
  835. }
  836. void CTabReportDlg::SetSkin(CProgramSkin *pProgramSkin)
  837. {
  838. m_pSkin = pProgramSkin;
  839. }
  840. void CTabReportDlg::OnPaint()
  841. {
  842. CPaintDC dc(this); // device context for painting
  843. RECT rect;
  844. GetClientRect( &rect );
  845. // get skin info
  846. CProgramSkin::SKIN skin;
  847. if( !m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT, skin ) )
  848. return;
  849. DIBSECTION DibSection;
  850. if( !::GetObject( skin.hBitmap, sizeof(DibSection), &DibSection ) )
  851. return;
  852. HDC hMemDC = ::CreateCompatibleDC( dc.GetSafeHdc() );
  853. if( !hMemDC )
  854. return;
  855. HBITMAP hBitmap = (HBITMAP)::SelectObject( hMemDC, skin.hBitmap );
  856. ::BitBlt( dc.GetSafeHdc(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, hMemDC, 0, 0, SRCCOPY );
  857. ::SelectObject( hMemDC, hBitmap );
  858. ::DeleteDC( hMemDC );
  859. }
  860. void CTabReportDlg::OnButtonDetection()
  861. {
  862. m_pMainDlg->ShowReport( FALSE ) ;
  863. }