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
1040 lines
25 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: TabReportDlg.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of TabReportDlg.cpp
|
|
//----------------------------------------------------------------------------
|
|
// TabReportDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "MultiIPIClient.h"
|
|
#include "TabReportDlg.h"
|
|
#include "TabReportDlg.h"
|
|
#include "MainDlg.h"
|
|
#include "..\LgLib\LgAux.h"
|
|
#include "..\LgLib\LgPerformanceCounter.h"
|
|
#include <shlwapi.h>
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
#define REPORT_IMAGES_IN_BLOCK 4
|
|
|
|
CTabReportDlg::CTabReportDlg(CWnd* pParent /*=0*/)
|
|
: CDialog(CTabReportDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CTabReportDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
|
|
m_hListTreeNode = TVI_ROOT;
|
|
m_bListWait = TRUE;
|
|
m_nListLevel = 0;
|
|
m_pListBuffer = 0;
|
|
m_nListBufferSize = 0;
|
|
m_bFileWait = FALSE;
|
|
|
|
m_ppListPtr = NULL;
|
|
m_nListPtrCount = 0;
|
|
|
|
m_pListLocator = NULL;
|
|
m_pListImage = NULL;
|
|
m_pListPreview = NULL;
|
|
m_pListText = NULL;
|
|
}
|
|
|
|
CTabReportDlg::~CTabReportDlg()
|
|
{
|
|
if( m_pListBuffer )
|
|
{
|
|
free( m_pListBuffer );
|
|
}
|
|
|
|
if( m_ppListPtr )
|
|
{
|
|
free( m_ppListPtr );
|
|
}
|
|
}
|
|
|
|
void CTabReportDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CTabReportDlg)
|
|
DDX_Control(pDX, IDC_BUTTON_DETECTION, m_ButtonDetection);
|
|
DDX_Control(pDX, IDC_STATIC_PREVIEW, m_StaticPreview);
|
|
DDX_Control(pDX, IDC_SLIDER_PREVIEW, m_SliderPreview);
|
|
DDX_Control(pDX, IDC_SLIDER_IMAGE, m_SliderImage);
|
|
DDX_Control(pDX, IDC_STATIC_IMAGE, m_StaticImage);
|
|
DDX_Control(pDX, IDC_RICHEDIT, m_RichEdit);
|
|
DDX_Control(pDX, IDC_STATIC_LOCATOR, m_StaticLocator);
|
|
DDX_Control(pDX, IDC_TREE, m_Tree);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CTabReportDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CTabReportDlg)
|
|
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
|
|
ON_WM_VSCROLL()
|
|
ON_WM_SHOWWINDOW()
|
|
ON_WM_PAINT()
|
|
ON_BN_CLICKED(IDC_BUTTON_DETECTION, OnButtonDetection)
|
|
ON_WM_HSCROLL()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
void MakeTempName( LPTSTR pTempName, LPTSTR pName )
|
|
{
|
|
strcpy( (LPTSTR)pTempName, "CACHE" );
|
|
::PathAppend( pTempName, pName );
|
|
}
|
|
|
|
BOOL CTabReportDlg::CheckFile( LPCTSTR pFileName, DWORD dwFileSize )
|
|
{
|
|
TRACE( "CHECK FILE\n" );
|
|
|
|
TCHAR pFullName[MAX_PATH];
|
|
strcpy( pFullName, m_pListName );
|
|
::PathAppend( pFullName, (PCHAR)pFileName );
|
|
strupr( pFullName );
|
|
|
|
if( !IsInCache( (PCHAR)pFullName, &dwFileSize ) )
|
|
{
|
|
if( dwFileSize && strstr( pFullName, "TARGET" ) )
|
|
{
|
|
// show particly loaded file
|
|
TCHAR pTempName[MAX_PATH];
|
|
MakeTempName( pTempName, pFullName );
|
|
ShowDataFile( pTempName );
|
|
}
|
|
|
|
strcpy( m_pFileName, (PCHAR)pFullName );
|
|
m_bFileWait = m_pMainDlg->GetDeviceClient()->DoRemoteReportFile( REMOTE_CONTEXT_CLIENT, (LPCTSTR)m_pFileName, strlen( (LPCTSTR)m_pFileName ) + 1, dwFileSize );
|
|
if( !m_bFileWait )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTabReportDlg::CheckFile"), _T("m_pMainDlg->GetDeviceClient()->DoRemoteReportFile failed") );
|
|
}
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
TCHAR pTempName[MAX_PATH];
|
|
MakeTempName( pTempName, pFullName );
|
|
ShowDataFile( pTempName );
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void CTabReportDlg::DownloadListFromHost()
|
|
{
|
|
TRACE( "DownloadListFromHost\n" );
|
|
|
|
// make asknowledge depend on level
|
|
if( m_hListTreeNode != TVI_ROOT )
|
|
{
|
|
INT nLength = 0;
|
|
m_nListLevel = MakeTreePath( m_hListTreeNode, m_pListName, &nLength );
|
|
m_bListWait = m_pMainDlg->GetDeviceClient()->DoRemoteReportList( REMOTE_CONTEXT_CLIENT, m_pListName, nLength );
|
|
if( !m_bListWait )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTabReportDlg::DownloadListFromHost"), _T("m_pMainDlg->GetDeviceClient()->DoRemoteReportList 1 failed") );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_bListWait = m_pMainDlg->GetDeviceClient()->DoRemoteReportList( REMOTE_CONTEXT_CLIENT, NULL, 0 );
|
|
if( !m_bListWait )
|
|
{
|
|
LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CTabReportDlg::DownloadListFromHost"), _T("m_pMainDlg->GetDeviceClient()->DoRemoteReportList 2 failed") );
|
|
}
|
|
}
|
|
|
|
// clear everythink
|
|
ClearCurrentReport();
|
|
|
|
// try to open it immediatly (from cache)
|
|
if( m_nListLevel == 2 )
|
|
OpenFromCache( m_pListName );
|
|
}
|
|
|
|
|
|
void CTabReportDlg::DownloadFileFromHost()
|
|
{
|
|
TRACE( "DownloadFileFromHost\n" );
|
|
|
|
// first of all transfer only importent files
|
|
PCHAR pList = m_pListBuffer;
|
|
INT nSize = m_nListBufferSize;
|
|
if( m_nFileLevel < 4 )
|
|
{
|
|
switch( m_nFileLevel )
|
|
{
|
|
case 0: // locator
|
|
if( m_pListLocator && !CheckFile( m_pListLocator+4, *(PDWORD)m_pListLocator ) )
|
|
return;
|
|
m_nFileLevel++;
|
|
m_pListLocator = NULL;
|
|
case 1: // 1st image
|
|
if( m_pListPreview && !CheckFile( m_pListPreview+4, *(PDWORD)m_pListPreview ) )
|
|
return;
|
|
m_nFileLevel++;
|
|
m_pListPreview = NULL;
|
|
case 2: // text
|
|
if( m_pListImage && !CheckFile( m_pListImage+4, *(PDWORD)m_pListImage ) )
|
|
return;
|
|
m_nFileLevel++;
|
|
m_pListImage = NULL;
|
|
case 3: // remaining
|
|
if( m_pListText && !CheckFile( m_pListText+4, *(PDWORD)m_pListText ) )
|
|
return;
|
|
m_nFileLevel++;
|
|
m_pListText = NULL;
|
|
}
|
|
}
|
|
|
|
// transfer remaining
|
|
pList = m_pListBuffer;
|
|
nSize = m_nListBufferSize;
|
|
for( INT i = 0; i < m_nListPtrCount; i++ )
|
|
{
|
|
if( m_ppListPtr[i] )
|
|
{
|
|
DWORD dwFileSize = *(PDWORD)m_ppListPtr[i];
|
|
PCHAR pFileName = m_ppListPtr[i] + 4;
|
|
if( !CheckFile( pFileName, dwFileSize ) )
|
|
break;
|
|
m_ppListPtr[i] = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CTabReportDlg::SetReportList( PBYTE pList, INT nSize )
|
|
{
|
|
TRACE( "SET REPORT LIST\n" );
|
|
|
|
if( m_nListLevel < 2 )
|
|
{
|
|
// clear cache
|
|
if( m_nListLevel == 0 )
|
|
DeleteOldFiles( pList, nSize );
|
|
|
|
INT nNewItemCount = 0;
|
|
|
|
HTREEITEM hChild = (m_hListTreeNode == TVI_ROOT) ? m_Tree.GetRootItem() : m_Tree.GetChildItem( m_hListTreeNode );
|
|
while( nSize )
|
|
{
|
|
pList += 4;
|
|
nSize -= 4;
|
|
|
|
// take current record length
|
|
INT nLength = strlen( (PCHAR)pList );
|
|
|
|
// add new node (if it really new)
|
|
BOOL bFound = FALSE;
|
|
while( hChild )
|
|
{
|
|
CString Name = m_Tree.GetItemText( hChild );
|
|
if( Name == pList )
|
|
{
|
|
bFound = TRUE;
|
|
break;
|
|
}
|
|
hChild = m_Tree.GetNextSiblingItem( hChild );
|
|
}
|
|
if( !bFound )
|
|
{
|
|
m_Tree.InsertItem( (PCHAR)pList, m_hListTreeNode );
|
|
nNewItemCount ++;
|
|
}
|
|
|
|
// take next record
|
|
nSize -= (nLength + 1);
|
|
pList += (nLength + 1);
|
|
}
|
|
|
|
// renew list
|
|
if( nNewItemCount )
|
|
m_Tree.InvalidateRect( 0 );
|
|
|
|
// allow new list requests
|
|
m_bListWait = FALSE;
|
|
}
|
|
else
|
|
{
|
|
// remember list
|
|
m_pListBuffer = (PCHAR)realloc( m_pListBuffer, nSize );
|
|
if( m_pListBuffer )
|
|
{
|
|
m_nListBufferSize = nSize;
|
|
memcpy( m_pListBuffer, pList, nSize );
|
|
}
|
|
else
|
|
{
|
|
m_pListBuffer = 0;
|
|
m_nListBufferSize = nSize = 0;
|
|
}
|
|
|
|
CLgPerformanceCounter pc;
|
|
pc.Begin();
|
|
|
|
// clear importent pointers
|
|
m_pListLocator = NULL;
|
|
m_pListImage = NULL;
|
|
m_pListPreview = NULL;
|
|
m_pListText = NULL;
|
|
|
|
// prepare list
|
|
m_nListPtrCount = 0;
|
|
while( nSize )
|
|
{
|
|
// store pointer in ptr list
|
|
m_ppListPtr = (PCHAR*)realloc( m_ppListPtr, sizeof( PBYTE ) * (m_nListPtrCount + 1) );
|
|
if( m_ppListPtr )
|
|
{
|
|
// store pointer to list entry
|
|
m_ppListPtr[ m_nListPtrCount ] = (PCHAR)pList;
|
|
m_nListPtrCount ++;
|
|
}
|
|
|
|
// skip length information
|
|
pList += 4;
|
|
nSize -= 4;
|
|
|
|
// take current record length
|
|
INT nLength = strlen( (PCHAR)pList );
|
|
|
|
if( strstr( (PCHAR)pList, "LOCATOR" ) )
|
|
{ m_pListLocator = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
|
|
else
|
|
if( strstr( (PCHAR)pList, "IMAGES00000" ) )
|
|
{ m_pListImage = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
|
|
else
|
|
if( strstr( (PCHAR)pList, "PREVIEW" ) )
|
|
{ m_pListPreview = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
|
|
else
|
|
if( strstr( (PCHAR)pList, "TARGET" ) )
|
|
{ m_pListText = m_ppListPtr[m_nListPtrCount-1]; m_ppListPtr[m_nListPtrCount-1] = NULL; }
|
|
|
|
// take next record
|
|
nSize -= (nLength + 1);
|
|
pList += (nLength + 1);
|
|
}
|
|
|
|
TRACE( "LIST PROCESSING TIME IS %0.8f\n", pc.End() );
|
|
|
|
if( !m_bFileWait )
|
|
{
|
|
m_nFileLevel = 0;
|
|
|
|
DownloadFileFromHost();
|
|
}
|
|
|
|
// allow new list requests
|
|
m_bListWait = FALSE;
|
|
}
|
|
}
|
|
|
|
void CTabReportDlg::SetReportFile( PBYTE pBuffer, INT nSize )
|
|
{
|
|
TRACE( "SET REPORT FILE\n" );
|
|
|
|
if( m_bFileWait )
|
|
{
|
|
// place new file into cache
|
|
PlaceToCache( m_pFileName, pBuffer, nSize );
|
|
|
|
m_bFileWait = FALSE;
|
|
|
|
if( !m_bListWait )
|
|
{
|
|
// check tree position
|
|
if( m_hListTreeNode == m_Tree.GetSelectedItem() )
|
|
{
|
|
DownloadFileFromHost();
|
|
}
|
|
else
|
|
{
|
|
m_hListTreeNode = m_Tree.GetSelectedItem();
|
|
|
|
DownloadListFromHost();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
INT CTabReportDlg::MakeTreePath( HTREEITEM hNode, LPTSTR pName, PINT pLength )
|
|
{
|
|
TRACE( "MakeTreePath\n" );
|
|
|
|
INT nLevel = 0;
|
|
CString FullName;
|
|
if( hNode != TVI_ROOT )
|
|
{
|
|
FullName = m_Tree.GetItemText( hNode );
|
|
hNode = m_Tree.GetNextItem( hNode, TVGN_PARENT );
|
|
nLevel++;
|
|
}
|
|
while( hNode )
|
|
{
|
|
CString SubName = m_Tree.GetItemText( hNode );
|
|
hNode = m_Tree.GetNextItem( hNode, TVGN_PARENT );
|
|
FullName = SubName + '\\' + FullName;
|
|
nLevel++;
|
|
};
|
|
|
|
// copy data
|
|
strcpy( pName, (LPCTSTR)FullName );
|
|
*pLength = FullName.GetLength() + 1;
|
|
|
|
TCHAR pTempName[MAX_PATH];
|
|
MakeTempName( pTempName, pName );
|
|
LgCreateDirectory( pTempName );
|
|
|
|
return nLevel;
|
|
}
|
|
|
|
void CTabReportDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
TRACE( "OnSelchangedTree\n" );
|
|
|
|
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
|
|
|
if( !m_bListWait )
|
|
{
|
|
TRACE( "LIST IS FREE\n" );
|
|
|
|
// store current level handle
|
|
m_hListTreeNode = pNMTreeView->itemNew.hItem;
|
|
|
|
DownloadListFromHost();
|
|
}
|
|
else
|
|
{
|
|
TRACE( "LIST IS BUZY\n" );
|
|
}
|
|
|
|
*pResult = 0;
|
|
}
|
|
|
|
BOOL CTabReportDlg::IsInCache( LPCTSTR pFileName, PDWORD pFileSize )
|
|
{
|
|
TRACE( "IsInCache\n" );
|
|
|
|
TCHAR pTempName[MAX_PATH];
|
|
MakeTempName( pTempName, (LPTSTR)pFileName );
|
|
|
|
CFile file;
|
|
if( file.Open( pTempName, CFile::modeRead ) )
|
|
{
|
|
if( file.GetLength() >= *pFileSize )
|
|
{
|
|
file.Close();
|
|
return TRUE;
|
|
}
|
|
*pFileSize = file.GetLength();
|
|
file.Close();
|
|
}
|
|
else
|
|
*pFileSize = 0;
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CTabReportDlg::PlaceToCache( LPCTSTR pFileName, PBYTE pData, INT nCount )
|
|
{
|
|
TRACE( "PlaceToCache\n" );
|
|
|
|
TCHAR pTempName[MAX_PATH];
|
|
MakeTempName( pTempName, (LPTSTR)pFileName );
|
|
|
|
INT nWritten = 0;
|
|
|
|
CFile file;
|
|
if( file.Open( pTempName, CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate ) )
|
|
{
|
|
file.SeekToEnd();
|
|
file.Write( pData, nCount );
|
|
file.Close();
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CTabReportDlg::OpenFromCache( LPCTSTR pFolderName )
|
|
{
|
|
TRACE( "OpenFromCache\n" );
|
|
|
|
// load with new data
|
|
TCHAR pTempName[MAX_PATH];
|
|
MakeTempName( pTempName, (LPTSTR)pFolderName );
|
|
strcat( pTempName, "*.*" );
|
|
|
|
CFileFind ff;
|
|
if( ff.FindFile( pTempName ) )
|
|
{
|
|
BOOL bContinue = TRUE;
|
|
while( bContinue )
|
|
{
|
|
TRACE( "OPEN FROM CACHE\n" );
|
|
|
|
bContinue = ff.FindNextFile();
|
|
// TRACE( "%s\n", ff.GetFileName() );
|
|
ShowDataFile( ff.GetFileName() );
|
|
}
|
|
ff.Close();
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CTabReportDlg::ShowDataFile( LPCTSTR pFileName )
|
|
{
|
|
TRACE( "ShowDataFile\n" );
|
|
|
|
TCHAR pName[MAX_PATH];
|
|
strcpy( pName, pFileName );
|
|
strupr( pName );
|
|
|
|
if( strstr( pName, "LOCATOR" ) )
|
|
{
|
|
TRACE( "LOCATOR\n" );
|
|
CLgImageJPEG jpeg;
|
|
if( jpeg.Load( pName ) )
|
|
{
|
|
CLgImageDIB dib;
|
|
if( jpeg.ConvertToDIB( dib ) )
|
|
{
|
|
CRect rect;
|
|
m_LocatorWnd.GetClientRect( &rect );
|
|
dib.Draw( m_LocatorWnd.GetMemoryDC().GetSafeHdc(), &rect );
|
|
m_LocatorWnd.InvalidateRect( NULL );
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
if( strstr( pName, "PREALARM" ) )
|
|
{
|
|
TRACE( "PREALARM\n" );
|
|
}
|
|
else
|
|
if( strstr( pName, "IMAGES00000" ) )
|
|
{
|
|
m_SliderImage.SetRange( 0, ( atoi( strstr( pName, "IMAGES" ) + 6 ) + 1 ) * REPORT_IMAGES_IN_BLOCK );
|
|
TRACE( "%d IMAGES\n", atoi( strstr( pName, "IMAGES" ) + 6 ) );
|
|
|
|
CLgImageJPEG jpeg;
|
|
if( jpeg.Load( pName ) )
|
|
{
|
|
CLgImageDIB dib;
|
|
if( jpeg.ConvertToDIB( dib ) )
|
|
{
|
|
CRect rect;
|
|
m_StaticImage.GetClientRect( &rect );
|
|
rect.bottom *= ((LPBITMAPINFO)dib)->bmiHeader.biHeight / 288;
|
|
dib.Draw( m_ImageWnd.GetMemoryDC().GetSafeHdc(), &rect );
|
|
m_ImageWnd.InvalidateRect( NULL );
|
|
return TRUE;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
if( strstr( pName, "IMAGES" ) )
|
|
{
|
|
m_SliderImage.SetRange( 0, ( atoi( strstr( pName, "IMAGES" ) + 6 ) + 1 ) * REPORT_IMAGES_IN_BLOCK );
|
|
TRACE( "%d IMAGES\n", atoi( strstr( pName, "IMAGES" ) + 6 ) );
|
|
}
|
|
else
|
|
if( strstr( pName, "TARGETS" ) )
|
|
{
|
|
TRACE( "TARGETS\n" );
|
|
CFile file;
|
|
if( file.Open( pName, CFile::modeRead ) )
|
|
{
|
|
DWORD dwSize = file.GetLength();
|
|
PBYTE pBuffer = new BYTE[ dwSize + 1 ];
|
|
if( pBuffer )
|
|
{
|
|
file.Read( pBuffer, dwSize );
|
|
pBuffer[ dwSize ] = 0;
|
|
m_RichEdit.SetWindowText( (PCHAR)pBuffer );
|
|
delete [] pBuffer;
|
|
}
|
|
file.Close();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TRACE( "ERROR\n" );
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CTabReportDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CRect rect;
|
|
|
|
m_StaticLocator.GetClientRect( &rect );
|
|
|
|
m_LocatorWnd.Create( this, rect );
|
|
|
|
m_StaticPreview.GetClientRect( &rect );
|
|
m_PreviewWnd.Create( this, rect );
|
|
|
|
m_StaticImage.GetClientRect( &rect );
|
|
m_ImageWnd.Create( this, rect );
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CTabReportDlg::InitFromCache()
|
|
{
|
|
|
|
}
|
|
|
|
void CTabReportDlg::ClearCurrentReport()
|
|
{
|
|
CRect rect;
|
|
|
|
m_LocatorWnd.GetClientRect( &rect );
|
|
m_LocatorWnd.GetMemoryDC().FillSolidRect( &rect, RGB(0,0,0) );
|
|
m_LocatorWnd.InvalidateRect( NULL );
|
|
|
|
m_ImageWnd.GetClientRect( &rect );
|
|
m_ImageWnd.GetMemoryDC().FillSolidRect( &rect, RGB(0,0,0) );
|
|
m_ImageWnd.InvalidateRect( NULL );
|
|
|
|
m_PreviewWnd.GetClientRect( &rect );
|
|
m_PreviewWnd.GetMemoryDC().FillSolidRect( &rect, RGB(0,0,0) );
|
|
m_PreviewWnd.InvalidateRect( NULL );
|
|
|
|
m_RichEdit.SetWindowText( "" );
|
|
|
|
m_SliderImage.SetPos(0);
|
|
m_SliderPreview.SetPos(0);
|
|
m_SliderImage.SetRange(0,-1);
|
|
m_SliderPreview.SetRange(0,-1);
|
|
}
|
|
|
|
void CTabReportDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
|
{
|
|
CSliderCtrl *pSlider = (CSliderCtrl*)pScrollBar;
|
|
|
|
if( pSlider->GetDlgCtrlID() == IDC_SLIDER_IMAGE )
|
|
{
|
|
CHAR pPathName[MAX_PATH];
|
|
INT nLength;
|
|
MakeTreePath( m_Tree.GetSelectedItem(), pPathName, &nLength );
|
|
|
|
CHAR pFileName[MAX_PATH];
|
|
sprintf( pFileName, "IMAGES%05d.JPG", m_SliderImage.GetPos() / REPORT_IMAGES_IN_BLOCK );
|
|
|
|
::PathAppend( pPathName, pFileName );
|
|
MakeTempName( pFileName, pPathName );
|
|
|
|
|
|
CLgImageJPEG jpeg;
|
|
if( jpeg.Load( pFileName ) )
|
|
{
|
|
CLgImageDIB dib;
|
|
if( jpeg.ConvertToDIB( dib ) )
|
|
{
|
|
CRect rect;
|
|
m_StaticImage.GetClientRect( &rect );
|
|
INT nHeight = rect.bottom;
|
|
rect.bottom *= ((LPBITMAPINFO)dib)->bmiHeader.biHeight / 288;
|
|
|
|
rect.OffsetRect( 0, - ( REPORT_IMAGES_IN_BLOCK - 1 - (m_SliderImage.GetPos() % REPORT_IMAGES_IN_BLOCK) ) * nHeight );
|
|
|
|
dib.Draw( m_ImageWnd.GetMemoryDC().GetSafeHdc(), &rect );
|
|
m_ImageWnd.InvalidateRect( NULL );
|
|
}
|
|
}
|
|
}
|
|
|
|
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
|
|
}
|
|
|
|
void CTabReportDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
|
{
|
|
CSliderCtrl *pSlider = (CSliderCtrl*)pScrollBar;
|
|
|
|
if( pSlider->GetDlgCtrlID() == IDC_SLIDER_IMAGE )
|
|
{
|
|
CHAR pPathName[MAX_PATH];
|
|
INT nLength;
|
|
MakeTreePath( m_Tree.GetSelectedItem(), pPathName, &nLength );
|
|
|
|
CHAR pFileName[MAX_PATH];
|
|
sprintf( pFileName, "IMAGES%05d.JPG", m_SliderImage.GetPos() / REPORT_IMAGES_IN_BLOCK );
|
|
|
|
::PathAppend( pPathName, pFileName );
|
|
MakeTempName( pFileName, pPathName );
|
|
|
|
|
|
CLgImageJPEG jpeg;
|
|
if( jpeg.Load( pFileName ) )
|
|
{
|
|
CLgImageDIB dib;
|
|
if( jpeg.ConvertToDIB( dib ) )
|
|
{
|
|
CRect rect;
|
|
m_StaticImage.GetClientRect( &rect );
|
|
INT nHeight = rect.bottom;
|
|
rect.bottom *= ((LPBITMAPINFO)dib)->bmiHeader.biHeight / 288;
|
|
|
|
rect.OffsetRect( 0, - ( REPORT_IMAGES_IN_BLOCK - 1 - (m_SliderImage.GetPos() % REPORT_IMAGES_IN_BLOCK) ) * nHeight );
|
|
|
|
dib.Draw( m_ImageWnd.GetMemoryDC().GetSafeHdc(), &rect );
|
|
m_ImageWnd.InvalidateRect( NULL );
|
|
}
|
|
}
|
|
}
|
|
|
|
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
|
|
}
|
|
|
|
void CTabReportDlg::OnShowWindow(BOOL bShow, UINT nStatus)
|
|
{
|
|
CDialog::OnShowWindow(bShow, nStatus);
|
|
|
|
if( bShow )
|
|
{
|
|
if( !m_bListWait )
|
|
{
|
|
TRACE( "LIST IS FREE\n" );
|
|
|
|
// store current level handle
|
|
m_hListTreeNode = TVI_ROOT;
|
|
|
|
DownloadListFromHost();
|
|
}
|
|
else
|
|
{
|
|
TRACE( "LIST IS BUZY\n" );
|
|
}
|
|
}
|
|
}
|
|
|
|
BOOL CTabReportDlg::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
switch( pMsg->message )
|
|
{
|
|
case WM_KEYDOWN:
|
|
switch( pMsg->wParam )
|
|
{
|
|
case VK_SPACE:
|
|
m_pMainDlg->AlarmStop();
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return CDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
void CTabReportDlg::UpdateControlPosition()
|
|
{
|
|
CProgramSkin::SKIN skin;
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_IMAGE, skin ) )
|
|
{
|
|
m_ImageWnd.MoveWindow( &skin.rect );
|
|
m_StaticImage.MoveWindow( &skin.rect );
|
|
}
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_IMAGE_SLIDER, skin ) )
|
|
m_SliderImage.MoveWindow( &skin.rect );
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_PREVIEW, skin ) )
|
|
m_PreviewWnd.MoveWindow( &skin.rect );
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_PREVIEW_SLIDER, skin ) )
|
|
m_SliderPreview.MoveWindow( &skin.rect );
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_LOCATOR, skin ) )
|
|
m_LocatorWnd.MoveWindow( &skin.rect );
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_TREE, skin ) )
|
|
m_Tree.MoveWindow( &skin.rect );
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_TEXT, skin ) )
|
|
m_RichEdit.MoveWindow( &skin.rect );
|
|
|
|
if( m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT_DETECTION, skin ) )
|
|
{
|
|
m_ButtonDetection.MoveWindow( &skin.rect );
|
|
m_ButtonDetection.SetBitmap( skin.hBitmap );
|
|
}
|
|
/*
|
|
// space between controls
|
|
INT nSpace = 5;
|
|
|
|
// store client rect of control
|
|
CRect ClientRect;
|
|
GetClientRect( &ClientRect );
|
|
|
|
// position image wnd
|
|
INT nImageHeight = ( ClientRect.Height() - nSpace * 3 ) / 2;
|
|
CRect ImageRect;
|
|
ImageRect.SetRect( ClientRect.right - nSpace - nImageHeight * 4 / 3, nSpace,
|
|
ClientRect.right - nSpace, nSpace + nImageHeight );
|
|
m_StaticImage.MoveWindow( &ImageRect );
|
|
m_ImageWnd.MoveWindow( &ImageRect );
|
|
|
|
// position preview wnd
|
|
CRect PreviewRect;
|
|
PreviewRect.SetRect( ImageRect.left, ImageRect.bottom + nSpace,
|
|
ImageRect.right, ClientRect.bottom - nSpace );
|
|
m_StaticPreview.MoveWindow( &PreviewRect );
|
|
m_PreviewWnd.MoveWindow( &PreviewRect );
|
|
|
|
// slider width
|
|
INT nSliderWidth = 20;
|
|
|
|
// position image slider wnd
|
|
CRect SliderImageRect;
|
|
SliderImageRect.SetRect( ImageRect.left - nSpace - nSliderWidth, ImageRect.top,
|
|
ImageRect.left - nSpace, ImageRect.bottom );
|
|
m_SliderImage.MoveWindow( &SliderImageRect );
|
|
|
|
// position image slider wnd
|
|
CRect SliderPreviewRect;
|
|
SliderPreviewRect.SetRect( PreviewRect.left - nSpace - nSliderWidth, PreviewRect.top,
|
|
PreviewRect.left - nSpace, PreviewRect.bottom );
|
|
m_SliderPreview.MoveWindow( &SliderPreviewRect );
|
|
|
|
// position locator wnd
|
|
CRect LocatorRect;
|
|
LocatorRect.SetRect( SliderImageRect.left - nSpace - ImageRect.Height(), SliderImageRect.top,
|
|
SliderImageRect.left - nSpace, SliderImageRect.bottom );
|
|
m_StaticLocator.MoveWindow( &LocatorRect );
|
|
m_LocatorWnd.MoveWindow( &LocatorRect );
|
|
|
|
// position text wnd
|
|
CRect TextRect;
|
|
TextRect.SetRect( ClientRect.left + nSpace, LocatorRect.bottom + nSpace,
|
|
LocatorRect.right, SliderPreviewRect.bottom );
|
|
m_RichEdit.MoveWindow( &TextRect );
|
|
|
|
// position list wnd
|
|
CRect TreeRect;
|
|
TreeRect.SetRect( ClientRect.left + nSpace, ClientRect.top + nSpace,
|
|
LocatorRect.left - nSpace, LocatorRect.bottom );
|
|
m_Tree.MoveWindow( &TreeRect );
|
|
*/
|
|
}
|
|
|
|
void CTabReportDlg::DeleteOldFiles( PBYTE pList, INT nListSize )
|
|
{
|
|
// WIN32_FIND_DATA win32FD;
|
|
// LARGE_INTEGER ft;
|
|
// LPTSTR pNames = NULL;
|
|
_TCHAR pBuffer[MAX_PATH];
|
|
// INT nNamesCount = 0;
|
|
|
|
PBYTE pOptimazedList = (PBYTE)malloc( nListSize );
|
|
if( !pOptimazedList )
|
|
return;
|
|
|
|
// prepare optimazed file list
|
|
memcpy( pOptimazedList, pList, nListSize );
|
|
INT nTempSize = nListSize;
|
|
PBYTE pTempList = pOptimazedList;
|
|
while( nTempSize )
|
|
{
|
|
pList += 4;
|
|
nTempSize -= 4;
|
|
|
|
// take current record length
|
|
INT nLength = strlen( (PCHAR)pList ) + 1;
|
|
|
|
*(PINT)pTempList = nLength;
|
|
pTempList += 4;
|
|
strupr( (PCHAR)pTempList );
|
|
|
|
// take next record
|
|
nTempSize -= nLength;
|
|
pList += nLength;
|
|
pTempList += nLength;
|
|
}
|
|
|
|
// prepare delete list
|
|
PCHAR pDeleteList = NULL;
|
|
INT nDeleteListSize = 0;
|
|
INT nDeleteListCount = 0;
|
|
CFileFind finder;
|
|
BOOL bWorking = finder.FindFile("CACHE\\*.*");
|
|
while (bWorking)
|
|
{
|
|
// get file name
|
|
bWorking = finder.FindNextFile();
|
|
|
|
// if it is directory name
|
|
if( finder.IsDirectory() )
|
|
{
|
|
CString name = (LPCTSTR)finder.GetFileName();
|
|
LPSTR pName = (LPTSTR)(LPCTSTR)name;
|
|
if( *pName != '.' )
|
|
{
|
|
INT nSize = strlen( pName ) + 1;
|
|
memcpy( pBuffer, pName, nSize );
|
|
strupr( pBuffer );
|
|
|
|
// search in list
|
|
INT nTempSize = nListSize;
|
|
PBYTE pTempList = pOptimazedList;
|
|
BOOL bDelete = TRUE;
|
|
while( nTempSize )
|
|
{
|
|
// take current record length
|
|
INT nLength = *(PINT)pTempList;
|
|
|
|
pTempList += 4;
|
|
nTempSize -= 4;
|
|
|
|
if( !memcmp( pTempList, pBuffer, nLength ) )
|
|
{
|
|
bDelete = FALSE;
|
|
break;
|
|
}
|
|
|
|
// take next record
|
|
nTempSize -= nLength;
|
|
pTempList += nLength;
|
|
}
|
|
|
|
if( bDelete )
|
|
{
|
|
pDeleteList = (PCHAR)realloc( pDeleteList, nDeleteListSize + nSize + 1 + 6 );
|
|
if( pDeleteList )
|
|
{
|
|
memcpy( pDeleteList + nDeleteListSize, "CACHE\\", 6 );
|
|
memcpy( pDeleteList + nDeleteListSize + 6, pName, nSize );
|
|
nDeleteListSize += (nSize+6);
|
|
pDeleteList[nDeleteListSize] = 0;
|
|
nDeleteListCount ++;
|
|
}
|
|
else
|
|
nDeleteListSize = nDeleteListCount = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( nDeleteListCount )
|
|
{
|
|
SHFILEOPSTRUCT sfs = { 0 };
|
|
|
|
sfs.wFunc = FO_DELETE;
|
|
sfs.pFrom = pDeleteList;
|
|
sfs.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS;
|
|
sfs.lpszProgressTitle = _T("Synchronizing reports...");
|
|
|
|
::SHFileOperation(&sfs);
|
|
}
|
|
|
|
if( pDeleteList )
|
|
free( pDeleteList );
|
|
|
|
free( pOptimazedList );
|
|
/*
|
|
::SystemTimeToFileTime( &st, (LPFILETIME)&ft );
|
|
|
|
ft.QuadPart -= m_nDays * 24i64 * 60i64 * 60i64 * 10000000i64;
|
|
|
|
StickFolderNames(pBuffer, m_pProfile->SettingsReport(), _T("*.*"));
|
|
|
|
HANDLE hFF = ::FindFirstFile(pBuffer, &win32FD);
|
|
|
|
if(hFF != INVALID_HANDLE_VALUE)
|
|
do{
|
|
if(win32FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
{
|
|
SYSTEMTIME cst = { 0 };
|
|
|
|
if(_stscanf(win32FD.cFileName, _T("%02hu_%02hu_%04hu"), &cst.wDay, &cst.wMonth, &cst.wYear) == 3)
|
|
{
|
|
LARGE_INTEGER cft;
|
|
|
|
::SystemTimeToFileTime(&cst, (LPFILETIME)&cft);
|
|
|
|
if(cft.QuadPart < ft.QuadPart)
|
|
{
|
|
StickFolderNames(pBuffer, m_pProfile->SettingsReport(), win32FD.cFileName );
|
|
StickNames(pNames, nNamesCount, pBuffer);
|
|
}
|
|
}
|
|
}
|
|
}while(::FindNextFile(hFF, &win32FD));
|
|
|
|
if(nNamesCount)
|
|
{
|
|
SHFILEOPSTRUCT sfs = { 0 };
|
|
|
|
sfs.wFunc = FO_DELETE;
|
|
sfs.pFrom = pNames;
|
|
sfs.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS;
|
|
sfs.lpszProgressTitle = _T("Deleting old history...");
|
|
|
|
::SHFileOperation(&sfs);
|
|
|
|
delete pNames;
|
|
}
|
|
|
|
::FindClose(hFF);
|
|
*/
|
|
}
|
|
|
|
void CTabReportDlg::SetSkin(CProgramSkin *pProgramSkin)
|
|
{
|
|
m_pSkin = pProgramSkin;
|
|
}
|
|
|
|
void CTabReportDlg::OnPaint()
|
|
{
|
|
CPaintDC dc(this); // device context for painting
|
|
|
|
RECT rect;
|
|
GetClientRect( &rect );
|
|
|
|
// get skin info
|
|
CProgramSkin::SKIN skin;
|
|
if( !m_pSkin->GetSkin( CProgramSkin::SKIN_REPORT, skin ) )
|
|
return;
|
|
|
|
DIBSECTION DibSection;
|
|
if( !::GetObject( skin.hBitmap, sizeof(DibSection), &DibSection ) )
|
|
return;
|
|
|
|
HDC hMemDC = ::CreateCompatibleDC( dc.GetSafeHdc() );
|
|
if( !hMemDC )
|
|
return;
|
|
|
|
HBITMAP hBitmap = (HBITMAP)::SelectObject( hMemDC, skin.hBitmap );
|
|
|
|
::BitBlt( dc.GetSafeHdc(), rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, hMemDC, 0, 0, SRCCOPY );
|
|
|
|
::SelectObject( hMemDC, hBitmap );
|
|
|
|
::DeleteDC( hMemDC );
|
|
}
|
|
|
|
void CTabReportDlg::OnButtonDetection()
|
|
{
|
|
m_pMainDlg->ShowReport( FALSE ) ;
|
|
}
|