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.
1072 lines
26 KiB
1072 lines
26 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 29/03/2000
|
|
// Last modification: 08/10/2003
|
|
// Project Intruder Position Indicator
|
|
// SUBSYSTEM: LogFiles targets
|
|
// FILE: LogFiles.cpp
|
|
// AUTHOR: Chizhevskiy Sergey
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file for implemenation of class CLogFiles
|
|
//----------------------------------------------------------------------------
|
|
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
#include "..\LgLib\LgDebug.h"
|
|
#include "..\LgLib\LgPerformanceCounter.h"
|
|
|
|
#include "LogFiles.h"
|
|
|
|
#define SECOND2NANO( a ) ( 10000000i64 * (__int64)( a ) )
|
|
#define MINUTE2NANO( a ) ( SECOND2NANO( a ) * 60i64 )
|
|
#define HOUR2NANO( a ) ( MINUTE2NANO( a ) * 60i64 )
|
|
#define DAY2NANO( a ) ( HOUR2NANO( a ) * 24i64 )
|
|
|
|
static LPTSTR StickFolderNames( LPTSTR pResult, LPCTSTR name1, LPCTSTR name2 )
|
|
{
|
|
INT len1 = (name1 == NULL ? 0 : _tcslen(name1));
|
|
INT len2 = (name2 == NULL ? 0 : _tcslen(name2));
|
|
|
|
if(len1)
|
|
{
|
|
if(*(name1 + len1 - 1) == '\\')
|
|
{
|
|
_tcsncpy(pResult, name1, len1 - 1);
|
|
pResult[--len1] = 0;
|
|
}
|
|
else
|
|
_tcsncpy(pResult, name1, len1 + 1);
|
|
}
|
|
|
|
if(len2)
|
|
{
|
|
if(*name2 == '\\')
|
|
_tcsncpy(pResult + len1, name2, len2 + 1);
|
|
else
|
|
{
|
|
_tcsncpy(pResult + len1, "\\", 1);
|
|
_tcsncpy(pResult + len1 + 1, name2, len2 + 1);
|
|
}
|
|
}
|
|
|
|
return pResult;
|
|
}
|
|
|
|
void CLogFiles::Reset()
|
|
{
|
|
static volatile BOOL fInside = FALSE;
|
|
_TCHAR pDayFolder[MAX_PATH];
|
|
_TCHAR pIncidentFolder[MAX_PATH];
|
|
|
|
m_bReset = FALSE;
|
|
|
|
if(!fInside)
|
|
{
|
|
fInside = TRUE;
|
|
|
|
TCHAR pFolder[MAX_PATH];
|
|
|
|
SYSTEMTIME st;
|
|
::GetLocalTime( &st );
|
|
|
|
StickFolderNames(pFolder, m_pProfile->SettingsReport(), NULL);
|
|
|
|
::CreateDirectory(pFolder, NULL);
|
|
|
|
_stprintf(pDayFolder, _T("%02hu_%02hu_%04hu"),
|
|
st.wDay, st.wMonth, st.wYear);
|
|
|
|
StickFolderNames(pFolder, pFolder, pDayFolder);
|
|
::CreateDirectory(pFolder, NULL);
|
|
|
|
_stprintf(pIncidentFolder, "%02hu_%02hu_%02hu",
|
|
st.wHour, st.wMinute, st.wSecond);
|
|
StickFolderNames(pFolder, pFolder, pIncidentFolder);
|
|
::CreateDirectory(pFolder, NULL);
|
|
|
|
StickFolderNames(m_pPathText, pFolder, m_pProfile->SettingsTargetTxt());
|
|
StickFolderNames(m_pPathTextEx, pFolder, "ext.log" );
|
|
StickFolderNames(m_pPathImage, pFolder, m_pProfile->SettingsTargetBmp());
|
|
StickFolderNames(m_pPathLocator, pFolder, m_pProfile->SettingsLocatorBmp());
|
|
StickFolderNames(m_pPathPreview, pFolder, m_pProfile->SettingsPreAlarmBmp());
|
|
|
|
_stprintf(m_pPathText, _T( "%s.txt" ), m_pPathText);
|
|
// _stprintf(m_pPathLocator, _T( "%s.bmp" ), m_pPathLocator);
|
|
// _stprintf(m_pPathPreview, _T( "%s.bmp" ), m_pPathPreview);
|
|
_stprintf(m_pPathLocator, _T( "%s.jpg" ), m_pPathLocator);
|
|
_stprintf(m_pPathPreview, _T( "%s.jpg" ), m_pPathPreview);
|
|
|
|
m_PreviewNumber = 0;
|
|
m_ImageNumber = 0;
|
|
|
|
fInside = FALSE;
|
|
}
|
|
}
|
|
|
|
void CLogFiles::StoreText(TARGET_DESCRIPTION& td)
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteText)
|
|
{
|
|
fInsige = FALSE;
|
|
|
|
return;
|
|
}
|
|
|
|
if (!m_bReset)
|
|
Reset();
|
|
|
|
HANDLE hFile = ::CreateFile(m_pPathText, GENERIC_WRITE,
|
|
FILE_SHARE_READ, NULL, OPEN_ALWAYS,
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_END);
|
|
TCHAR pBuffer[0x500];
|
|
LPCTSTR master = " ";
|
|
|
|
if(m_bDebugMode)
|
|
{
|
|
switch(td.master)
|
|
{
|
|
case 'a':
|
|
master = "M ";
|
|
break;
|
|
|
|
case 'b':
|
|
master = "S ";
|
|
break;
|
|
|
|
case 'f':
|
|
master = "F ";
|
|
break;
|
|
|
|
case 'w':
|
|
master = td.device ? "SW" : "MW";
|
|
break;
|
|
|
|
case 'q':
|
|
master = "D ";
|
|
break;
|
|
}
|
|
}
|
|
|
|
// convert to clockwise
|
|
double dAngle = m_pProfile->ConvertToUserCoordinate( td.angle );
|
|
|
|
if(td.master == 'f')
|
|
_stprintf(pBuffer, _T( "%02hu/%02hu/%04hu %02hu:%02hu:%02hu DRD\n"),
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond);
|
|
else
|
|
if( td.master == 'q' )
|
|
{
|
|
_stprintf( pBuffer, _T("%02hu/%02hu/%04hu %02hu:%02hu:%02hu %s %3.0f° (dopler)\r\n"),
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond,
|
|
master, dAngle );
|
|
}
|
|
else
|
|
#ifdef DRAW_TARGET_WIDTH
|
|
_stprintf(pBuffer, _T( "%02hu/%02hu/%04hu %02hu:%02hu:%02hu %s %3.0f° %3.1f m. (W %d)\r\n"),
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond,
|
|
master, dAngle, td.range, td.width );
|
|
#else
|
|
_stprintf(pBuffer, _T( "%02hu/%02hu/%04hu %02hu:%02hu:%02hu %s %3.0f° %3.1f m.\r\n"),
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond,
|
|
master, dAngle, td.range );
|
|
#endif
|
|
|
|
|
|
DWORD dwWrite;
|
|
|
|
::WriteFile(hFile, pBuffer, _tcslen(pBuffer), &dwWrite, NULL);
|
|
::CloseHandle(hFile);
|
|
|
|
m_bReset = TRUE;
|
|
}
|
|
|
|
fInsige = FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
INT CLogFiles::PrepareImageText( TARGET_DESCRIPTION& td, LPCTSTR pTag, LPTSTR pText, INT nMaxText )
|
|
{
|
|
// convert to clockwise
|
|
double dAngle = m_pProfile->ConvertToUserCoordinate( td.angle );
|
|
|
|
if(!td.master)
|
|
return _sntprintf( pText, nMaxText, "%02hu\\%02hu\\%04hu %02hu:%02hu:%02hu PHOTO",
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond);
|
|
else
|
|
if(td.master == 'l')
|
|
{
|
|
return _sntprintf( pText, nMaxText, "%02hu\\%02hu\\%04hu %02hu:%02hu:%02hu BLIND",
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond );
|
|
}
|
|
else
|
|
if(td.master == 'q')
|
|
{
|
|
return _sntprintf( pText, nMaxText, "%02hu\\%02hu\\%04hu %02hu:%02hu:%02hu DOPLER %3.1f°",
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond,
|
|
dAngle );
|
|
}
|
|
else
|
|
if(td.master == 'f')
|
|
{
|
|
return _sntprintf( pText, nMaxText, "%02hu\\%02hu\\%04hu %02hu:%02hu:%02hu DRD %3.1f°",
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond,
|
|
dAngle );
|
|
}
|
|
else
|
|
return _sntprintf( pText, nMaxText, "%02hu\\%02hu\\%04hu %02hu:%02hu:%02hu %s%3.0f° %3.1fm",
|
|
td.time.wDay, td.time.wMonth, td.time.wYear,
|
|
td.time.wHour, td.time.wMinute, td.time.wSecond,
|
|
pTag, dAngle, td.range);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CLogFiles::StoreInformation(LPCTSTR pStr, SYSTEMTIME &time)
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteText)
|
|
{
|
|
fInsige = FALSE;
|
|
return;
|
|
}
|
|
|
|
if(!m_bReset)
|
|
Reset();
|
|
|
|
HANDLE hFile = ::CreateFile(m_pPathText, GENERIC_WRITE,
|
|
FILE_SHARE_READ, NULL, OPEN_ALWAYS,
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
_TCHAR pBuffer[MAX_PATH];
|
|
DWORD dwWrite;
|
|
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_END);
|
|
|
|
INT nBuffer = _sntprintf( pBuffer, MAX_PATH, _T("%02hu/%02hu/%04hu %02hu:%02hu:%02hu %s\r\n"),
|
|
time.wDay, time.wMonth, time.wYear,
|
|
time.wHour, time.wMinute, time.wSecond, pStr );
|
|
if( nBuffer < 0 )
|
|
nBuffer = MAX_PATH;
|
|
|
|
::WriteFile(hFile, pBuffer, nBuffer, &dwWrite, NULL);
|
|
::CloseHandle(hFile);
|
|
|
|
m_bReset = TRUE;
|
|
}
|
|
|
|
fInsige = FALSE;
|
|
}
|
|
}
|
|
|
|
void CLogFiles::StoreInformationEx(LPCTSTR pStr, SYSTEMTIME &time)
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteText)
|
|
{
|
|
fInsige = FALSE;
|
|
return;
|
|
}
|
|
|
|
if(!m_bReset)
|
|
Reset();
|
|
|
|
HANDLE hFile = ::CreateFile(m_pPathTextEx, GENERIC_WRITE,
|
|
FILE_SHARE_READ, NULL, OPEN_ALWAYS,
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
_TCHAR pBuffer[0x500];
|
|
DWORD dwWrite;
|
|
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_END);
|
|
|
|
INT nBuffer = _sntprintf( pBuffer, MAX_PATH, _T("%02hu/%02hu/%04hu %02hu:%02hu:%02hu %s\r\n"),
|
|
time.wDay, time.wMonth, time.wYear,
|
|
time.wHour, time.wMinute, time.wSecond, pStr );
|
|
if( nBuffer < 0 )
|
|
nBuffer = MAX_PATH;
|
|
|
|
::WriteFile(hFile, pBuffer, nBuffer, &dwWrite, NULL);
|
|
::CloseHandle(hFile);
|
|
|
|
m_bReset = TRUE;
|
|
}
|
|
|
|
fInsige = FALSE;
|
|
}
|
|
}
|
|
|
|
void CLogFiles::StoreLocator()
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteImage)
|
|
{
|
|
fInsige = FALSE;
|
|
return;
|
|
}
|
|
|
|
if(!m_bReset)
|
|
Reset();
|
|
|
|
m_pLocator->StoreImage( m_pPathLocator );
|
|
|
|
m_bReset = TRUE;
|
|
|
|
fInsige = FALSE;
|
|
}
|
|
}
|
|
|
|
HBITMAP CLogFiles::StorePreview(TARGET_DESCRIPTION& td)
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
HBITMAP fSuccess = NULL;
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteImage)
|
|
{
|
|
fInsige = FALSE;
|
|
return NULL;
|
|
}
|
|
|
|
if (!m_bReset )
|
|
Reset();
|
|
|
|
|
|
LPBITMAPINFOHEADER pBIH = m_PreviewDIB;
|
|
LPBYTE pBytes = m_PreviewDIB;
|
|
|
|
if( pBytes && pBIH )
|
|
{
|
|
INT nSubImage = m_PreviewNumber;
|
|
|
|
// shift to appropriate location
|
|
pBytes += nSubImage * 288 * WIDTHBYTES( pBIH->biWidth * pBIH->biBitCount );
|
|
|
|
TCHAR pImageText[MAX_PATH];
|
|
PrepareImageText( td, "", pImageText, MAX_PATH );
|
|
if( fSuccess = m_pVideoWnd->StoreImage( pBytes, pImageText, 384, 288, 24 ) )
|
|
{
|
|
INT nHeight = pBIH->biHeight;
|
|
INT nSizeImage = pBIH->biSizeImage;
|
|
|
|
pBIH->biHeight = ( nSubImage + 1 ) * 288;
|
|
pBIH->biSizeImage = pBIH->biHeight * WIDTHBYTES( pBIH->biWidth * pBIH->biBitCount );
|
|
|
|
m_PreviewJPEG.Create( m_PreviewDIB, m_PreviewDIB, m_pProfile->ReportQualityImage() );
|
|
m_PreviewJPEG.Save( m_pPathPreview );
|
|
|
|
pBIH->biHeight = nHeight;
|
|
pBIH->biSizeImage = nSizeImage;
|
|
|
|
m_PreviewNumber = (m_PreviewNumber + 1) % 15;
|
|
m_bReset = TRUE;
|
|
}
|
|
}
|
|
|
|
fInsige = FALSE;
|
|
} // if(!fInsige)
|
|
|
|
return fSuccess;
|
|
}
|
|
|
|
/*
|
|
HBITMAP CLogFiles::StorePreview(TARGET_DESCRIPTION& td)
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
HBITMAP fSuccess = NULL;
|
|
TCHAR pImageText[MAX_PATH];
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteImage)
|
|
{
|
|
fInsige = FALSE;
|
|
return NULL;
|
|
}
|
|
|
|
if (!m_bReset )
|
|
Reset();
|
|
|
|
HANDLE hFile = ::CreateFile( m_pPathPreview, GENERIC_WRITE | GENERIC_READ,
|
|
FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
{
|
|
BITMAPFILEHEADER bfh;
|
|
BITMAPINFOHEADER bih;
|
|
DWORD dwRead, dwWrite;
|
|
|
|
switch(::GetLastError())
|
|
{
|
|
case ERROR_SUCCESS:
|
|
bfh.bfType = (((WORD)'M') << 8) + 'B';
|
|
bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + ((m_pProfile->ImageBitCount() == 8) ? sizeof(RGBQUAD)*256 : 0);
|
|
bfh.bfReserved1 = 0;
|
|
bfh.bfReserved2 = 0;
|
|
bfh.bfOffBits = bfh.bfSize;
|
|
bih = m_lpBmi->bmiHeader;
|
|
bih.biBitCount = m_pProfile->ImageBitCount(); // +++
|
|
bih.biHeight = 0;
|
|
bih.biSizeImage = 0;
|
|
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_BEGIN);
|
|
|
|
::WriteFile(hFile, &bfh, sizeof(bfh), &dwWrite, NULL);
|
|
::WriteFile(hFile, &bih, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
|
|
if( m_pProfile->ImageBitCount() == 8 )
|
|
::WriteFile(hFile, m_lpBmi->bmiColors, sizeof(RGBQUAD) * 256, &dwWrite, NULL); // 256 colors
|
|
|
|
case ERROR_ALREADY_EXISTS:
|
|
|
|
if( m_pProfile->ImageBitCount() == 8 )
|
|
::SetFilePointer(hFile, sizeof(RGBQUAD) * 256 + sizeof(BITMAPINFOHEADER) +sizeof(BITMAPFILEHEADER) + 384 * 288 * m_PreviewNumber, 0UL, FILE_BEGIN); // 256 colors
|
|
else
|
|
::SetFilePointer(hFile, sizeof(BITMAPINFOHEADER) +sizeof(BITMAPFILEHEADER) + 384 * 288 * 3 * m_PreviewNumber, 0UL, FILE_BEGIN); // true color
|
|
|
|
PrepareImageText( td, "", pImageText, MAX_PATH );
|
|
fSuccess = m_pVideoWnd->StoreImage( hFile, pImageText, 384, 288, m_pProfile->ImageBitCount() );
|
|
|
|
if(fSuccess)
|
|
{
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_BEGIN);
|
|
::ReadFile(hFile, &bfh, sizeof(bfh), &dwRead, NULL);
|
|
::ReadFile(hFile, &bih, sizeof(bih), &dwRead, NULL);
|
|
|
|
if(bih.biHeight < 288 * 15)
|
|
{
|
|
bih.biHeight += 288;
|
|
if( m_pProfile->ImageBitCount() == 8 )
|
|
{
|
|
bfh.bfSize += 384 * 288; // 256 colors
|
|
bih.biSizeImage += 384*288; // 256 colors
|
|
}
|
|
else
|
|
{
|
|
bfh.bfSize += 384 * 288 * 3; // true color
|
|
bih.biSizeImage += 384*288 * 3; // true color
|
|
}
|
|
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_BEGIN);
|
|
::WriteFile(hFile, &bfh, sizeof(bfh), &dwWrite, NULL);
|
|
::WriteFile(hFile, &bih, sizeof(bih), &dwWrite, NULL);
|
|
}
|
|
|
|
m_PreviewNumber = (m_PreviewNumber + 1) % 15;
|
|
|
|
m_bReset = TRUE;
|
|
}
|
|
break;
|
|
} // end of switch(::GetLastError())
|
|
|
|
::CloseHandle( hFile );
|
|
} // end of if(hFile != INVALID_HANDLE_VALUE)
|
|
|
|
fInsige = FALSE;
|
|
} // if(!fInsige)
|
|
|
|
return fSuccess;
|
|
}
|
|
*/
|
|
|
|
void CLogFiles::StoreImage( TARGET_DESCRIPTION& td, BOOL bFixed )
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if( !m_bWriteImage )
|
|
{
|
|
fInsige = FALSE;
|
|
return;
|
|
}
|
|
|
|
if( !m_bReset )
|
|
Reset();
|
|
|
|
LPBITMAPINFOHEADER pBIH = m_ImageDIB;
|
|
LPBYTE pBytes = m_ImageDIB;
|
|
|
|
if( pBytes && pBIH )
|
|
{
|
|
INT nSubImage = m_ImageNumber % REPORT_IMAGES_IN_BLOCK;
|
|
|
|
// shift to appropriate location
|
|
pBytes += nSubImage * 288 * WIDTHBYTES( pBIH->biWidth * pBIH->biBitCount );
|
|
|
|
HBITMAP bCapture = NULL;
|
|
|
|
if( bFixed )
|
|
{
|
|
TCHAR pImageText[MAX_PATH];
|
|
PrepareImageText( td, "FIX ", pImageText, MAX_PATH );
|
|
bCapture = m_pFixedVideoWnd->StoreImage( pBytes, pImageText, 384, 288, 24 );
|
|
}
|
|
else
|
|
{
|
|
TCHAR pImageText[MAX_PATH];
|
|
PrepareImageText( td, "", pImageText, MAX_PATH );
|
|
bCapture = m_pVideoWnd->StoreImage( pBytes, pImageText, 384, 288, 24 );
|
|
}
|
|
|
|
if( bCapture )
|
|
{
|
|
INT nHeight = pBIH->biHeight;
|
|
INT nSizeImage = pBIH->biSizeImage;
|
|
|
|
pBIH->biHeight = ( nSubImage + 1 ) * 288;
|
|
pBIH->biSizeImage = pBIH->biHeight * WIDTHBYTES( pBIH->biWidth * pBIH->biBitCount );
|
|
|
|
TCHAR pBuffer[MAX_PATH];
|
|
_stprintf( pBuffer, _T( "%s%05d.jpg" ), m_pPathImage, m_ImageNumber / REPORT_IMAGES_IN_BLOCK );
|
|
m_ImageJPEG.Create( m_ImageDIB, m_ImageDIB, m_pProfile->ReportQualityImage() );
|
|
m_ImageJPEG.Save( pBuffer );
|
|
|
|
pBIH->biHeight = nHeight;
|
|
pBIH->biSizeImage = nSizeImage;
|
|
|
|
::DeleteObject( bCapture );
|
|
m_ImageNumber++;
|
|
m_bReset = TRUE;
|
|
}
|
|
}
|
|
|
|
fInsige = FALSE;
|
|
} // end of if(!fInsige)
|
|
}
|
|
|
|
/*
|
|
void CLogFiles::StoreImage( TARGET_DESCRIPTION& td, BOOL bFixed )
|
|
{
|
|
volatile static BOOL fInsige = FALSE;
|
|
_TCHAR pBuffer[MAX_PATH];
|
|
|
|
if(!fInsige)
|
|
{
|
|
CheckFreeSpace();
|
|
|
|
fInsige = TRUE;
|
|
|
|
if(!m_bWriteImage)
|
|
{
|
|
fInsige = FALSE;
|
|
return;
|
|
}
|
|
|
|
if(!m_bReset)
|
|
Reset();
|
|
|
|
_stprintf(pBuffer, _T( "%s%05d.bmp" ), m_pPathImage, m_ImageNumber / REPORT_IMAGES_IN_BLOCK );
|
|
|
|
HANDLE hFile = ::CreateFile(pBuffer, GENERIC_WRITE | GENERIC_READ,
|
|
FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if( hFile != INVALID_HANDLE_VALUE )
|
|
{
|
|
BITMAPFILEHEADER bfh;
|
|
BITMAPINFOHEADER bih;
|
|
HBITMAP hBitmap = NULL;
|
|
DWORD dwRead, dwWrite;
|
|
|
|
switch(::GetLastError())
|
|
{
|
|
case ERROR_SUCCESS:
|
|
bfh.bfType = (((WORD)'M' ) << 8) + 'B';
|
|
bfh.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + ((m_pProfile->ImageBitCount() == 8) ? sizeof(RGBQUAD)*256 : 0);
|
|
bfh.bfReserved1 = 0;
|
|
bfh.bfReserved2 = 0;
|
|
bfh.bfOffBits = bfh.bfSize;
|
|
bih = m_lpBmi->bmiHeader;
|
|
bih.biBitCount = m_pProfile->ImageBitCount(); // +++
|
|
bih.biHeight = 0;
|
|
bih.biSizeImage = 0;
|
|
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_BEGIN);
|
|
::WriteFile(hFile, &bfh, sizeof(bfh), &dwWrite, NULL);
|
|
::WriteFile(hFile, &bih, sizeof(BITMAPINFOHEADER), &dwWrite, NULL);
|
|
if( m_pProfile->ImageBitCount() == 8 )
|
|
::WriteFile(hFile, m_lpBmi->bmiColors, sizeof(RGBQUAD) * 256, &dwWrite, NULL); // 256 colors
|
|
|
|
case ERROR_ALREADY_EXISTS:
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_END);
|
|
|
|
if( bFixed )
|
|
{
|
|
TCHAR pImageText[MAX_PATH];
|
|
PrepareImageText( td, "FIX ", pImageText, MAX_PATH );
|
|
hBitmap = m_pFixedVideoWnd->StoreImage( hFile, pImageText, 384, 288, m_pProfile->ImageBitCount() );
|
|
}
|
|
else
|
|
{
|
|
TCHAR pImageText[MAX_PATH];
|
|
PrepareImageText( td, "", pImageText, MAX_PATH );
|
|
hBitmap = m_pVideoWnd->StoreImage( hFile, pImageText, 384, 288, m_pProfile->ImageBitCount() );
|
|
}
|
|
|
|
if(hBitmap)
|
|
{
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_BEGIN);
|
|
::ReadFile(hFile, &bfh, sizeof(bfh), &dwRead, NULL);
|
|
::ReadFile(hFile, &bih, sizeof(bih), &dwRead, NULL);
|
|
|
|
bih.biHeight += 288;
|
|
if( m_pProfile->ImageBitCount() == 8 )
|
|
{
|
|
bfh.bfSize += 384 * 288; // 256 colors
|
|
bih.biSizeImage += 384*288; // 256 colors
|
|
}
|
|
else
|
|
{
|
|
bfh.bfSize += 384 * 288 * 3; // true color
|
|
bih.biSizeImage += 384*288 * 3; // true color
|
|
}
|
|
|
|
::SetFilePointer(hFile, 0UL, 0UL, FILE_BEGIN);
|
|
|
|
::WriteFile(hFile, &bfh, sizeof(bfh), &dwWrite, NULL);
|
|
::WriteFile(hFile, &bih, sizeof(bih), &dwWrite, NULL);
|
|
|
|
::DeleteObject(hBitmap);
|
|
|
|
m_ImageNumber++;
|
|
m_bReset = TRUE;
|
|
}
|
|
} // end of switch(::GetLastError())
|
|
|
|
::CloseHandle( hFile );
|
|
|
|
// --------------------- convert to jpeg ----------------------
|
|
// prepare bmp name
|
|
PCHAR pBmpFileName = pBuffer;
|
|
|
|
// prepare jpeg name
|
|
TCHAR pJpegFileName[MAX_PATH];
|
|
strcpy( pJpegFileName, pBmpFileName );
|
|
::PathRemoveExtension( pJpegFileName );
|
|
strcat( pJpegFileName, ".JPG" );
|
|
|
|
// convert to jpeg
|
|
if( m_ImageDIB.Load( pBmpFileName, TRUE ) )
|
|
{
|
|
LPBITMAPINFOHEADER pBIH = m_ImageDIB;
|
|
if( pBIH && pBIH->biWidth > 0 && pBIH->biHeight > 0 )
|
|
{
|
|
CLgImageJPEG jpeg;
|
|
if( jpeg.Create( m_ImageDIB, m_ImageDIB ) )
|
|
jpeg.Save( pJpegFileName );
|
|
}
|
|
}
|
|
} // end of if(hFile != INVALID_HANDLE_VALUE)
|
|
|
|
fInsige = FALSE;
|
|
} // end of if(!fInsige)
|
|
}
|
|
*/
|
|
CLogFiles::CLogFiles()
|
|
{
|
|
m_lpBmi = NULL;
|
|
m_pVideoWnd = NULL;
|
|
m_pLocator = 0;
|
|
m_pProfile = 0;
|
|
m_hEventQuit = 0;
|
|
m_hThread = 0;
|
|
m_bDebugMode = 0;
|
|
m_PreviewNumber = 0;
|
|
m_ImageNumber = 0;
|
|
m_bReset = 0;
|
|
m_bWriteImage = 0;
|
|
m_bWriteText = 0;
|
|
m_nDays = 0;
|
|
|
|
m_bReset = FALSE;
|
|
m_pVideoWnd = NULL;
|
|
m_pLocator = NULL;
|
|
m_hEventQuit = NULL;
|
|
m_nDays = 1000;
|
|
m_hThread= NULL;
|
|
|
|
m_lpBmi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256];
|
|
|
|
ZeroMemory(m_lpBmi, sizeof(BITMAPINFOHEADER));
|
|
|
|
m_lpBmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
m_lpBmi->bmiHeader.biWidth = 384;
|
|
m_lpBmi->bmiHeader.biHeight = 288;
|
|
m_lpBmi->bmiHeader.biPlanes = 1;
|
|
m_lpBmi->bmiHeader.biBitCount = 8;
|
|
m_lpBmi->bmiHeader.biCompression = 0;
|
|
m_lpBmi->bmiHeader.biSizeImage = m_lpBmi->bmiHeader.biWidth *
|
|
m_lpBmi->bmiHeader.biHeight;
|
|
|
|
for(int i = 0; i < 255; i++)
|
|
{
|
|
m_lpBmi->bmiColors[i].rgbRed = i;
|
|
m_lpBmi->bmiColors[i].rgbGreen = i;
|
|
m_lpBmi->bmiColors[i].rgbBlue = i;
|
|
m_lpBmi->bmiColors[i].rgbReserved = 0;
|
|
}
|
|
|
|
m_lpBmi->bmiColors[i].rgbRed = 255;
|
|
m_lpBmi->bmiColors[i].rgbGreen = 0;
|
|
m_lpBmi->bmiColors[i].rgbBlue = 0;
|
|
m_lpBmi->bmiColors[i].rgbReserved = 0;
|
|
|
|
m_PreviewNumber = 0;
|
|
m_ImageNumber = 0;
|
|
|
|
m_bWriteText = TRUE;
|
|
m_bWriteImage = TRUE;
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLogFiles::CLogFiles" );
|
|
}
|
|
|
|
CLogFiles::~CLogFiles()
|
|
{
|
|
::SetEvent(m_hEventQuit);
|
|
|
|
if(::WaitForSingleObject(m_hThread, 1000UL) != WAIT_OBJECT_0)
|
|
::TerminateThread(m_hThread, 0); // !!!
|
|
|
|
::CloseHandle(m_hThread);
|
|
::CloseHandle(m_hEventQuit);
|
|
|
|
delete[] m_lpBmi; // Added delete[] 22/04/2001
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLogFiles::~CLogFiles" );
|
|
}
|
|
|
|
BOOL CLogFiles::Create(CVideoWnd *pVideoWnd, CVideoWnd *pFixedVideoWnd, CLgsRadarWnd *pLocator, CProfile *pProfile)
|
|
{
|
|
m_pVideoWnd = pVideoWnd;
|
|
m_pFixedVideoWnd = pFixedVideoWnd;
|
|
m_pLocator = pLocator;
|
|
m_pProfile = pProfile;
|
|
m_bClockwise = pProfile->LgsDisplayClockwise();
|
|
|
|
m_hEventQuit = ::CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
m_nDays = m_pProfile->ReportHistory();
|
|
|
|
DWORD dwThreadId;
|
|
|
|
m_hThread = ::CreateThread(NULL, 0UL, ThreadProcLogFiles, (LPVOID)this, 0UL, &dwThreadId);
|
|
|
|
if(!m_hThread)
|
|
return FALSE;
|
|
|
|
if( !m_ImageDIB.Create( 384, 288 * REPORT_IMAGES_IN_BLOCK, 24 ) )
|
|
return FALSE;
|
|
|
|
if( !m_PreviewDIB.Create( 384, 288 * 15, 24 ) )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static void StickNames(LPTSTR &pResult, INT& nSize, LPCTSTR pName)
|
|
{
|
|
INT nLen = _tcslen(pName);
|
|
|
|
if(nSize)
|
|
{
|
|
INT nNewSize = nSize + nLen + 1;
|
|
LPTSTR pNewBuffer = new _TCHAR[nNewSize];
|
|
|
|
memcpy(pNewBuffer, pResult, nSize);
|
|
memcpy(pNewBuffer + nSize - 1, pName, nLen); // rewrite last zero
|
|
memcpy(pNewBuffer + nSize - 1 + nLen, _T("\0\0"), 2); // add double zero
|
|
|
|
delete[] pResult;
|
|
|
|
pResult = pNewBuffer;
|
|
|
|
nSize = nNewSize;
|
|
}
|
|
else
|
|
{
|
|
nSize = nLen + 2;
|
|
pResult = new _TCHAR[nSize];
|
|
|
|
memcpy(pResult, pName, nLen );
|
|
memcpy(pResult + nLen, _T("\0\0"), 2); // add double zero
|
|
}
|
|
}
|
|
|
|
void CLogFiles::DeleteOldFiles(SYSTEMTIME st)
|
|
{
|
|
WIN32_FIND_DATA win32FD;
|
|
LARGE_INTEGER ft;
|
|
LPTSTR pNames = NULL;
|
|
_TCHAR pBuffer[MAX_PATH];
|
|
INT nNamesCount = 0;
|
|
|
|
::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);
|
|
}
|
|
|
|
BOOL CLogFiles::CheckOldFiles(SYSTEMTIME st)
|
|
{
|
|
WIN32_FIND_DATA win32FD;
|
|
LARGE_INTEGER ft;
|
|
_TCHAR pBuffer[MAX_PATH];
|
|
BOOL fExist = FALSE;
|
|
|
|
::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)
|
|
fExist = TRUE;
|
|
}
|
|
}
|
|
}while(::FindNextFile(hFF, &win32FD));
|
|
|
|
::FindClose(hFF);
|
|
|
|
return fExist;
|
|
}
|
|
|
|
DWORD CALLBACK ThreadProcLogFiles(LPVOID lpvParam)
|
|
{
|
|
__try
|
|
{
|
|
TIME_ZONE_INFORMATION tzi;
|
|
LARGE_INTEGER lt;
|
|
SYSTEMTIME st;
|
|
CLogFiles* self = (CLogFiles*) lpvParam;
|
|
BOOL fNeedCheck = TRUE;
|
|
|
|
::GetTimeZoneInformation(&tzi);
|
|
|
|
HANDLE hTimer = ::CreateWaitableTimer(NULL, FALSE, NULL);
|
|
|
|
|
|
::GetLocalTime(&st);
|
|
st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
|
|
::SystemTimeToFileTime( &st, (LPFILETIME)< );
|
|
lt.QuadPart += DAY2NANO( 1 ) + MINUTE2NANO( tzi.Bias );
|
|
::SetWaitableTimer(hTimer, <, 0UL, NULL, NULL, FALSE);
|
|
|
|
HANDLE phEvents[] = { self->m_hEventQuit, hTimer };
|
|
|
|
if(self->CheckOldFiles(st))
|
|
if(CMessageBox::MessageBox( self->m_pLocator->GetSafeHwnd(), "Exists old report files, delete them?", "Report", MB_YESNO | MB_ICONQUESTION) == IDYES )
|
|
self->DeleteOldFiles(st);
|
|
|
|
while(TRUE)
|
|
{
|
|
switch(::WaitForMultipleObjects(2, phEvents, FALSE, INFINITE))
|
|
{
|
|
case WAIT_OBJECT_0 + 0:
|
|
goto THREAD_EXIT;
|
|
|
|
case WAIT_OBJECT_0 + 1:
|
|
::CancelWaitableTimer(hTimer);
|
|
::GetLocalTime(&st);
|
|
self->DeleteOldFiles(st);
|
|
st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
|
|
::SystemTimeToFileTime( &st, (LPFILETIME)< );
|
|
lt.QuadPart += DAY2NANO( 1 ) + MINUTE2NANO( tzi.Bias );
|
|
::SetWaitableTimer(hTimer, <, 0UL, NULL, NULL, FALSE);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
} // end of while(TRUE)
|
|
|
|
THREAD_EXIT:
|
|
::CancelWaitableTimer(hTimer);
|
|
::CloseHandle(hTimer);
|
|
}
|
|
__except(1)
|
|
{
|
|
MessageBox( NULL, "Error in CApplication::Run", "Error in CApplication::Run", MB_OK );
|
|
}
|
|
return 0UL;
|
|
}
|
|
|
|
void CLogFiles::Begin()
|
|
{
|
|
m_bReset = FALSE;
|
|
}
|
|
|
|
void CLogFiles::SetDebugMode(BOOL fMode)
|
|
{
|
|
m_bDebugMode = fMode;
|
|
}
|
|
|
|
void CLogFiles::CheckFreeSpace()
|
|
{
|
|
volatile static BOOL bInside = FALSE;
|
|
|
|
if( !bInside )
|
|
{
|
|
bInside = TRUE;
|
|
|
|
if( m_bWriteText || m_bWriteImage )
|
|
{
|
|
|
|
ULARGE_INTEGER uliFreeBytesAvailableToCaller;
|
|
ULARGE_INTEGER uliTotalNumberOfBytes;
|
|
ULARGE_INTEGER uliTotalNumberOfFreeBytes;
|
|
|
|
::GetDiskFreeSpaceEx(m_pProfile->SettingsReport(),
|
|
&uliFreeBytesAvailableToCaller,
|
|
&uliTotalNumberOfBytes,
|
|
&uliTotalNumberOfFreeBytes);
|
|
|
|
if(50000000i64 < uliFreeBytesAvailableToCaller.QuadPart &&
|
|
uliFreeBytesAvailableToCaller.QuadPart < 100000000i64)
|
|
{
|
|
if(m_bWriteImage)
|
|
{
|
|
SYSTEMTIME st;
|
|
|
|
GetLocalTime(&st);
|
|
|
|
StoreInformation("Disk space exceed (<100Mb), not enough room for images", st);
|
|
m_bWriteImage = FALSE;
|
|
}
|
|
}
|
|
|
|
if(50000000i64 > uliFreeBytesAvailableToCaller.QuadPart)
|
|
{
|
|
if(m_bWriteText)
|
|
{
|
|
SYSTEMTIME st;
|
|
|
|
GetLocalTime(&st);
|
|
|
|
if(m_bWriteImage)
|
|
{
|
|
StoreInformation("Disk space exceed (<50Mb), not enough room for images and text", st);
|
|
m_bWriteImage = FALSE;
|
|
}
|
|
else
|
|
StoreInformation( "Disk space exceed (<50Mb), not enough room for text", st );
|
|
|
|
m_bWriteText = FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
bInside = FALSE;
|
|
}
|
|
}
|