For DOS Protected Mode version of sensor core software
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.

1331 lines
40 KiB

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 09/11/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgReportProvider.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgReportProvider.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgReportProvider.h"
  16. CLgReportProvider::CLgReportProvider()
  17. {
  18. _tcsncpy( m_pRootPath, _T("\\REPORT"), MAX_PATH );
  19. memset( &m_Storage, 0, sizeof(m_Storage) );
  20. memset( &m_Loader, 0, sizeof(m_Loader) );
  21. m_bPendingReset = FALSE;
  22. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgReportProvider::CLgReportProvider") );
  23. }
  24. CLgReportProvider::~CLgReportProvider()
  25. {
  26. LoaderProviderToClientLinkP::Unlink();
  27. StorageProviderToClientLinkSP::Unlink();
  28. Destroy();
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, _T("CLgReportProvider::~CLgReportProvider") );
  30. }
  31. BOOL CLgReportProvider::Create( LPCTSTR pProviderName, LPCTSTR pPathRoot, INT nMaxStorageDays )
  32. {
  33. if( !CLgReportLoaderProvider::Create( pProviderName ) )
  34. return FALSE;
  35. _tcsncpy( m_pRootPath, pPathRoot, MAX_PATH );
  36. m_nMaxStorageDays = nMaxStorageDays;
  37. if( !DoWriteReset() )
  38. return FALSE;
  39. return Start( FALSE );
  40. }
  41. void CLgReportProvider::Destroy()
  42. {
  43. Stop( TRUE );
  44. CLgReportLoaderClient::Destroy();
  45. }
  46. //todo: fix preview day reports must be included to selected reoports also the export must be end at exact time
  47. BOOL CLgReportProvider::Export( LPCTSTR pFileName, LPSYSTEMTIME pStart, LPSYSTEMTIME pEnd ){
  48. FILE *m_fHandle = fopen( pFileName, _T("a") );
  49. if( m_fHandle ){
  50. TCHAR pSearchPath[MAX_PATH];
  51. _tcsncpy( pSearchPath, m_pRootPath, MAX_PATH );
  52. ::PathAppend( pSearchPath, _T("*.*") );
  53. WIN32_FIND_DATA ffd;
  54. HANDLE hFindFile = ::FindFirstFile( pSearchPath, &ffd );
  55. if( hFindFile != INVALID_HANDLE_VALUE ){
  56. REPORT_POSITION pos = 0;
  57. while( TRUE ){
  58. INT nYear, nMonth, nDay;
  59. if( ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY &&
  60. ffd.cFileName[0] != _T('.') &&
  61. _stscanf( ffd.cFileName, PATH_DATE_FORMAT, &nYear, &nMonth, &nDay ) == 3 )
  62. { // Report Folder Detected
  63. TCHAR tSearchPath[MAX_PATH];
  64. _tcsncpy( tSearchPath, m_pRootPath, MAX_PATH );
  65. ::PathAppend( tSearchPath, ffd.cFileName );
  66. ::PathAppend( tSearchPath, _T("\\*.*") );
  67. WIN32_FIND_DATA dffd;
  68. HANDLE hFindFile2 = ::FindFirstFile( tSearchPath, &dffd );
  69. if( hFindFile2 != INVALID_HANDLE_VALUE )
  70. {
  71. REPORT_POSITION pos = 0;
  72. while( TRUE )
  73. {
  74. INT nHour, nMinute, nSecond;
  75. if( ( dffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY &&
  76. dffd.cFileName[0] != _T('.') &&
  77. _stscanf( dffd.cFileName, PATH_TIME_FORMAT, &nHour, &nMinute, &nSecond ) == 3 )
  78. { //Report Time Detected
  79. // create path
  80. TCHAR pFullPath[MAX_PATH];
  81. _tcsncpy( pFullPath, m_pRootPath, MAX_PATH );
  82. ::PathAppend( pFullPath, ffd.cFileName );
  83. ::PathAppend( pFullPath, _T("\\") );
  84. ::PathAppend( pFullPath, dffd.cFileName );
  85. ::PathAppend( pFullPath, _T("\\") );
  86. ::PathAppend( pFullPath, PATH_EVENT );
  87. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  88. if( hFile == INVALID_HANDLE_VALUE )
  89. break;
  90. // end of read
  91. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  92. // read data
  93. LARGE_INTEGER liPos;
  94. liPos.QuadPart = 0;//1 * sizeof( REPORT_EVENT );
  95. REPORT_EVENT pEvent[1];
  96. INT ST, ET;
  97. ST = pStart->wHour * 60 + pStart->wMinute;
  98. ET = pEnd->wHour * 60 + pEnd->wMinute;
  99. DWORD STA;
  100. DWORD STB;
  101. DWORD ETA;
  102. DWORD ETB;
  103. STA = ( pStart->wYear << 16 ) | pStart->wMonth;
  104. STB = ( ( pStart->wDay & 0xFF ) << 24 ) |
  105. ( ( pStart->wHour & 0xFF ) << 16 ) |
  106. ( ( pStart->wMinute & 0xFF ) << 8 ) |
  107. ( pStart->wSecond & 0xFF );
  108. ETA = ( pEnd->wYear << 16 ) | pEnd->wMonth;
  109. ETB = ( ( pEnd->wDay & 0xFF ) << 24 ) |
  110. ( ( pEnd->wHour & 0xFF ) << 16 ) |
  111. ( ( pEnd->wMinute & 0xFF ) << 8 ) |
  112. ( pEnd->wSecond & 0xFF );
  113. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER ){
  114. DWORD dwRead = 0UL;
  115. DWORD dwToRead = sizeof(REPORT_EVENT) * 1;
  116. while( ::ReadFile( hFile, pEvent, dwToRead, &dwRead, NULL ) && dwToRead == dwRead ){
  117. //if(( pStart->wYear == (2000+nYear) ) &&
  118. // ( pStart->wMonth == nMonth ) &&
  119. // ( pStart->wDay == nDay ) )
  120. {
  121. INT CT;
  122. CT = pEvent->stTime.wHour * 60 + pEvent->stTime.wMinute;
  123. DWORD CTA;
  124. DWORD CTB;
  125. CTA = ( pEvent->stTime.wYear << 16 ) | pEvent->stTime.wMonth;
  126. CTB = ( ( pEvent->stTime.wDay & 0xFF ) << 24 ) |
  127. ( ( pEvent->stTime.wHour & 0xFF ) << 16 ) |
  128. ( ( pEvent->stTime.wMinute & 0xFF ) << 8 ) |
  129. ( pEvent->stTime.wSecond & 0xFF );
  130. //fprintf( m_fHandle, ">%02d/%02d/%02d %02d:%02d:%02d\n", pStart->wYear, pStart->wMonth, pStart->wDay, pStart->wHour, pStart->wMinute, pStart->wSecond );
  131. //fprintf( m_fHandle, "?20%02d/%02d/%02d %02d:%02d:%02d\n", nYear, nMonth, nDay, nHour, nMinute, nSecond );
  132. //fprintf( m_fHandle, "+%02d/%02d/%02d %02d:%02d:%02d\n", pEnd->wYear, pEnd->wMonth, pEnd->wDay, pEnd->wHour, pEnd->wMinute, pEnd->wSecond );
  133. /*
  134. typedef struct _SYSTEMTIME {
  135. WORD wYear;
  136. WORD wMonth;
  137. WORD wDayOfWeek;
  138. WORD wDay;
  139. WORD wHour;
  140. WORD wMinute;
  141. WORD wSecond;
  142. WORD wMilliseconds;
  143. }
  144. */
  145. //if( CT > ST && CT < ET ) fprintf( m_fHandle, "20%02d/%02d/%02d %02d:%02d:%02d %s\n", nYear, nMonth, nDay, nHour, nMinute, nSecond, pEvent->pText );
  146. //if(( CT => ST ) && ( CT =< ET ) )
  147. if( ( CTA >= STA ) &&
  148. ( CTB >= STB ) &&
  149. ( CTA <= ETA ) &&
  150. ( CTB <= ETB )
  151. )
  152. fprintf( m_fHandle, "%04d/%02d/%02d, %02d:%02d:%02d, %s\n", pEvent->stTime.wYear, pEvent->stTime.wMonth, pEvent->stTime.wDay, pEvent->stTime.wHour, pEvent->stTime.wMinute, pEvent->stTime.wSecond, pEvent->pText );
  153. };
  154. };
  155. //*pRead = dwRead / sizeof(REPORT_EVENT);
  156. }
  157. else
  158. eResult = RR_RESULT_SUCCESS;
  159. }
  160. // get next data
  161. if( !::FindNextFile( hFindFile2, &dffd ) ){
  162. break;
  163. }
  164. }
  165. // close handle
  166. ::FindClose( hFindFile2 );
  167. }
  168. }
  169. // get next data
  170. if( !::FindNextFile( hFindFile, &ffd ) ){
  171. break;
  172. }
  173. }
  174. // close handle
  175. ::FindClose( hFindFile );
  176. }
  177. fclose( m_fHandle );
  178. } else {
  179. MessageBox( NULL, _T("Error While Exporting!"), _T("Export Report"), MB_OK | MB_ICONERROR );
  180. return FALSE;
  181. };
  182. MessageBox( NULL, _T("Export Successfully Done."), _T("Export Report"), MB_OK | MB_ICONINFORMATION );
  183. return TRUE;
  184. }
  185. E_REPORT_RESULT CLgReportProvider::DoReadSite( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_PATH ppPath, INT nCount, PINT pRead )
  186. {
  187. return ReadSite( rHandle, pPosition, ppPath, nCount, pRead );
  188. }
  189. E_REPORT_RESULT CLgReportProvider::DoReadSiteDate( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_DATE pDate, INT nCount, PINT pRead )
  190. {
  191. // lock handles
  192. CLgLocker Lock( GetHandleLock() );
  193. // get handle info
  194. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  195. // if provider handle is valid then pass it through
  196. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  197. return ReadSiteDate( rHandle, pPosition, pDate, nCount, pRead );
  198. TCHAR pSearchPath[MAX_PATH];
  199. _tcsncpy( pSearchPath, m_pRootPath, MAX_PATH );
  200. ::PathAppend( pSearchPath, _T("*.*") );
  201. // prImage errors on upper levels
  202. *pRead = 0;
  203. // end of search
  204. BOOL bEnd = TRUE;
  205. WIN32_FIND_DATA ffd;
  206. HANDLE hFindFile = ::FindFirstFile( pSearchPath, &ffd );
  207. if( hFindFile != INVALID_HANDLE_VALUE )
  208. {
  209. REPORT_POSITION pos = 0;
  210. while( TRUE )
  211. {
  212. INT nYear, nMonth, nDay;
  213. if( ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY &&
  214. ffd.cFileName[0] != _T('.') &&
  215. _stscanf( ffd.cFileName, PATH_DATE_FORMAT, &nYear, &nMonth, &nDay ) == 3 )
  216. {
  217. if( pos++ >= *pPosition )
  218. {
  219. // mark that it is not the end of search
  220. bEnd = FALSE;
  221. // store value
  222. PREPORT_DATE pDatePtr = pDate + (*pRead)++;
  223. pDatePtr->bYear = nYear;
  224. pDatePtr->bMonth = nMonth;
  225. pDatePtr->bDay = nDay;
  226. // decrease number
  227. if( !--nCount )
  228. break;
  229. }
  230. }
  231. // get next data
  232. if( !::FindNextFile( hFindFile, &ffd ) )
  233. {
  234. bEnd = TRUE;
  235. break;
  236. }
  237. }
  238. // close handle
  239. ::FindClose( hFindFile );
  240. }
  241. // update position
  242. *pPosition = *pPosition + *pRead;
  243. return bEnd ? RR_RESULT_SUCCESS : RR_RESULT_SUCCESS_PENDING;
  244. }
  245. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTime( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_DATE_TIME pDateTime, INT nCount, PINT pRead )
  246. {
  247. // lock handles
  248. CLgLocker Lock( GetHandleLock() );
  249. // get handle info
  250. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  251. // if provider handle is valid then pass it through
  252. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  253. return ReadSiteDateTime( rHandle, pPosition, pDateTime, nCount, pRead );
  254. TCHAR pSearchPath[MAX_PATH];
  255. BuildPath( pSearchPath, NULL, &pHandleInfo->rDateTime );
  256. ::PathAppend( pSearchPath, _T("*.*") );
  257. // prImage errors on upper levels
  258. *pRead = 0;
  259. // end of search
  260. BOOL bEnd = TRUE;
  261. WIN32_FIND_DATA ffd;
  262. HANDLE hFindFile = ::FindFirstFile( pSearchPath, &ffd );
  263. if( hFindFile != INVALID_HANDLE_VALUE )
  264. {
  265. REPORT_POSITION pos = 0;
  266. while( TRUE )
  267. {
  268. INT nHour, nMinute, nSecond;
  269. if( ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY &&
  270. ffd.cFileName[0] != _T('.') &&
  271. _stscanf( ffd.cFileName, PATH_TIME_FORMAT, &nHour, &nMinute, &nSecond ) == 3 )
  272. {
  273. if( pos++ >= *pPosition )
  274. {
  275. // mark that it is not the end of search
  276. bEnd = FALSE;
  277. // store value
  278. PREPORT_DATE_TIME pDateTimePtr = pDateTime + (*pRead)++;
  279. pDateTimePtr->bYear = pHandleInfo->rDateTime.bYear;
  280. pDateTimePtr->bMonth = pHandleInfo->rDateTime.bMonth;
  281. pDateTimePtr->bDay = pHandleInfo->rDateTime.bDay;
  282. pDateTimePtr->bHour = nHour;
  283. pDateTimePtr->bMinute = nMinute;
  284. pDateTimePtr->bSecond = nSecond;
  285. // decrease number
  286. if( !--nCount )
  287. break;
  288. }
  289. }
  290. // get next data
  291. if( !::FindNextFile( hFindFile, &ffd ) )
  292. {
  293. bEnd = TRUE;
  294. break;
  295. }
  296. }
  297. // close handle
  298. ::FindClose( hFindFile );
  299. }
  300. // update position
  301. *pPosition = *pPosition + *pRead;
  302. return bEnd ? RR_RESULT_SUCCESS : RR_RESULT_SUCCESS_PENDING;
  303. }
  304. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeBackground( REPORT_HANDLE rHandle, PREPORT_IMAGE pImage )
  305. {
  306. // lock handles
  307. CLgLocker Lock( GetHandleLock() );
  308. // get handle info
  309. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  310. // if provider handle is valid then pass it through
  311. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  312. return ReadSiteDateTimeBackground( rHandle, pImage );
  313. // create path
  314. TCHAR pFullPath[MAX_PATH];
  315. BuildPathFull( pFullPath, pHandleInfo->rPath, &pHandleInfo->rDateTime );
  316. ::PathAppend( pFullPath, PATH_BACKGROUND );
  317. return pImage->Load( pFullPath ) ? RR_RESULT_SUCCESS : RR_RESULT_FAILURE;
  318. }
  319. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeFilterEvent( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_FILTER_EVENT pFilterEvent, INT nCount, PINT pRead )
  320. {
  321. // lock handles
  322. CLgLocker Lock( GetHandleLock() );
  323. // get handle info
  324. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  325. // if provider handle is valid then pass it through
  326. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  327. return ReadSiteDateTimeFilterEvent( rHandle, pPosition, pFilterEvent, nCount, pRead );
  328. // create path
  329. TCHAR pFullPath[MAX_PATH];
  330. BuildPathFull( pFullPath, pHandleInfo->rPath, &pHandleInfo->rDateTime );
  331. ::PathAppend( pFullPath, PATH_FILTER_EVENT );
  332. // reset counter
  333. *pRead = 0;
  334. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  335. if( hFile == INVALID_HANDLE_VALUE )
  336. return RR_RESULT_FAILURE;
  337. // end of read
  338. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  339. // read data
  340. LARGE_INTEGER liPos;
  341. liPos.QuadPart = *pPosition * sizeof( REPORT_FILTER_EVENT );
  342. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER )
  343. {
  344. DWORD dwRead = 0UL;
  345. DWORD dwToRead = sizeof(REPORT_FILTER_EVENT) * nCount;
  346. if( !::ReadFile( hFile, pFilterEvent, dwToRead, &dwRead, NULL ) || dwToRead != dwRead )
  347. eResult = RR_RESULT_SUCCESS;
  348. *pRead = dwRead / sizeof(REPORT_FILTER_EVENT);
  349. }
  350. else
  351. eResult = RR_RESULT_SUCCESS;
  352. // update position
  353. *pPosition = *pPosition + *pRead;
  354. ::CloseHandle( hFile );
  355. return eResult;
  356. }
  357. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeFilterSource( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_FILTER_SOURCE pFilterSource, INT nCount, PINT pRead )
  358. {
  359. // lock handles
  360. CLgLocker Lock( GetHandleLock() );
  361. // get handle info
  362. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  363. // if provider handle is valid then pass it through
  364. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  365. return ReadSiteDateTimeFilterSource( rHandle, pPosition, pFilterSource, nCount, pRead );
  366. // create path
  367. TCHAR pFullPath[MAX_PATH];
  368. BuildPathFull( pFullPath, pHandleInfo->rPath, &pHandleInfo->rDateTime );
  369. ::PathAppend( pFullPath, PATH_FILTER_SOURCE );
  370. // reset counter
  371. *pRead = 0;
  372. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  373. if( hFile == INVALID_HANDLE_VALUE )
  374. return RR_RESULT_FAILURE;
  375. // end of read
  376. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  377. // read data
  378. LARGE_INTEGER liPos;
  379. liPos.QuadPart = *pPosition * sizeof( REPORT_FILTER_SOURCE );
  380. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER )
  381. {
  382. DWORD dwRead = 0UL;
  383. DWORD dwToRead = sizeof(REPORT_FILTER_SOURCE) * nCount;
  384. if( !::ReadFile( hFile, pFilterSource, dwToRead, &dwRead, NULL ) || dwToRead != dwRead )
  385. eResult = RR_RESULT_SUCCESS;
  386. *pRead = dwRead / sizeof(REPORT_FILTER_SOURCE);
  387. }
  388. else
  389. eResult = RR_RESULT_SUCCESS;
  390. // update position
  391. *pPosition = *pPosition + *pRead;
  392. ::CloseHandle( hFile );
  393. return eResult;
  394. }
  395. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeEvent( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_EVENT pEvent, INT nCount, PINT pRead )
  396. {
  397. // lock handles
  398. CLgLocker Lock( GetHandleLock() );
  399. // get handle info
  400. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  401. // if provider handle is valid then pass it through
  402. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  403. return ReadSiteDateTimeEvent( rHandle, pPosition, pEvent, nCount, pRead );
  404. // create path
  405. TCHAR pFullPath[MAX_PATH];
  406. BuildPathFull( pFullPath, pHandleInfo->rPath, &pHandleInfo->rDateTime );
  407. ::PathAppend( pFullPath, PATH_EVENT );
  408. // reset counter
  409. *pRead = 0;
  410. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  411. if( hFile == INVALID_HANDLE_VALUE )
  412. return RR_RESULT_FAILURE;
  413. // end of read
  414. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  415. // read data
  416. LARGE_INTEGER liPos;
  417. liPos.QuadPart = *pPosition * sizeof( REPORT_EVENT );
  418. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER )
  419. {
  420. DWORD dwRead = 0UL;
  421. DWORD dwToRead = sizeof(REPORT_EVENT) * nCount;
  422. if( !::ReadFile( hFile, pEvent, dwToRead, &dwRead, NULL ) || dwToRead != dwRead )
  423. eResult = RR_RESULT_SUCCESS;
  424. *pRead = dwRead / sizeof(REPORT_EVENT);
  425. }
  426. else
  427. eResult = RR_RESULT_SUCCESS;
  428. // update position
  429. *pPosition = *pPosition + *pRead;
  430. ::CloseHandle( hFile );
  431. return eResult;
  432. }
  433. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeImage( REPORT_HANDLE rHandle, PREPORT_POSITION pPosition, PREPORT_IMAGE pImage )
  434. {
  435. // lock handles
  436. CLgLocker Lock( GetHandleLock() );
  437. // get handle info
  438. REPORT_HANDLE_INFO *pHandleInfo = GetHandleInfo( rHandle );
  439. // if provider handle is valid then pass it through
  440. if( pHandleInfo->rProviderHandle != REPORT_INVALID_HANDLE_VALUE )
  441. return ReadSiteDateTimeImage( rHandle, pPosition, pImage );
  442. // create path
  443. TCHAR pFullPath[MAX_PATH];
  444. BuildPathFull( pFullPath, pHandleInfo->rPath, &pHandleInfo->rDateTime );
  445. // create image path
  446. TCHAR pImagePath[MAX_PATH];
  447. _sntprintf( pImagePath, MAX_PATH, PATH_IMAGE_FULL_FORMAT, pFullPath, (DWORD)( *pPosition / IMAGES_IN_BLOCK ), (DWORD)( *pPosition % IMAGES_IN_BLOCK ) );
  448. return pImage->Load( pImagePath ) ? RR_RESULT_SUCCESS : RR_RESULT_FAILURE;
  449. }
  450. /*
  451. E_REPORT_RESULT CLgReportProvider::DoReadSite( REPORT_PATH pPath, PREPORT_POSITION pPosition, PREPORT_PATH ppPathChild, INT nCount, PINT pRead )
  452. {
  453. return CLgReportLoaderClient::ReadSite( pPath, pPosition, ppPathChild, nCount, pRead );
  454. }
  455. E_REPORT_RESULT CLgReportProvider::DoReadSiteDate( REPORT_PATH pPath, PREPORT_POSITION pPosition, PREPORT_DATE pDate, INT nCount, PINT pRead )
  456. {
  457. // NOTE: should be changed: first of all should be checked cache !!!
  458. if( pPath && *pPath )
  459. return CLgReportLoaderClient::ReadSiteDate( pPath, pPosition, pDate, nCount, pRead );
  460. TCHAR pSearchPath[MAX_PATH];
  461. _tcsncpy( pSearchPath, m_pRootPath, MAX_PATH );
  462. ::PathAppend( pSearchPath, _T("*.*") );
  463. // prImage errors on upper levels
  464. *pRead = 0;
  465. // end of search
  466. BOOL bEnd = TRUE;
  467. WIN32_FIND_DATA ffd;
  468. HANDLE hFindFile = ::FindFirstFile( pSearchPath, &ffd );
  469. if( hFindFile != INVALID_HANDLE_VALUE )
  470. {
  471. REPORT_POSITION pos = 0;
  472. while( TRUE )
  473. {
  474. INT nYear, nMonth, nDay;
  475. if( ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY &&
  476. ffd.cFileName[0] != _T('.') &&
  477. _stscanf( ffd.cFileName, PATH_DATE_FORMAT, &nYear, &nMonth, &nDay ) == 3 )
  478. {
  479. if( pos++ >= *pPosition )
  480. {
  481. // mark that it is not the end of search
  482. bEnd = FALSE;
  483. // store value
  484. PREPORT_DATE pDatePtr = pDate + (*pRead)++;
  485. pDatePtr->bYear = nYear;
  486. pDatePtr->bMonth = nMonth;
  487. pDatePtr->bDay = nDay;
  488. // decrease number
  489. if( !--nCount )
  490. break;
  491. }
  492. }
  493. // get next data
  494. if( !::FindNextFile( hFindFile, &ffd ) )
  495. {
  496. bEnd = TRUE;
  497. break;
  498. }
  499. }
  500. // close handle
  501. ::FindClose( hFindFile );
  502. }
  503. // update position
  504. *pPosition = *pPosition + *pRead;
  505. return bEnd ? RR_RESULT_SUCCESS : RR_RESULT_SUCCESS_PENDING;
  506. }
  507. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTime( REPORT_PATH pPath, PREPORT_DATE pDate, PREPORT_POSITION pPosition, PREPORT_DATE_TIME pDateTime, INT nCount, PINT pRead )
  508. {
  509. // NOTE: should be changed: first of all should be checked cache !!!
  510. if( pPath && *pPath )
  511. return CLgReportLoaderClient::ReadSiteDateTime( pPath, pDate, pPosition, pDateTime, nCount, pRead );
  512. TCHAR pSearchPath[MAX_PATH];
  513. BuildPath( pSearchPath, NULL, pDate );
  514. ::PathAppend( pSearchPath, _T("*.*") );
  515. // prImage errors on upper levels
  516. *pRead = 0;
  517. // end of search
  518. BOOL bEnd = TRUE;
  519. WIN32_FIND_DATA ffd;
  520. HANDLE hFindFile = ::FindFirstFile( pSearchPath, &ffd );
  521. if( hFindFile != INVALID_HANDLE_VALUE )
  522. {
  523. REPORT_POSITION pos = 0;
  524. while( TRUE )
  525. {
  526. INT nHour, nMinute, nSecond;
  527. if( ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) == FILE_ATTRIBUTE_DIRECTORY &&
  528. ffd.cFileName[0] != _T('.') &&
  529. _stscanf( ffd.cFileName, PATH_TIME_FORMAT, &nHour, &nMinute, &nSecond ) == 3 )
  530. {
  531. if( pos++ >= *pPosition )
  532. {
  533. // mark that it is not the end of search
  534. bEnd = FALSE;
  535. // store value
  536. PREPORT_DATE_TIME pDateTimePtr = pDateTime + (*pRead)++;
  537. pDateTimePtr->bYear = pDate->bYear;
  538. pDateTimePtr->bMonth = pDate->bMonth;
  539. pDateTimePtr->bDay = pDate->bDay;
  540. pDateTimePtr->bHour = nHour;
  541. pDateTimePtr->bMinute = nMinute;
  542. pDateTimePtr->bSecond = nSecond;
  543. // decrease number
  544. if( !--nCount )
  545. break;
  546. }
  547. }
  548. // get next data
  549. if( !::FindNextFile( hFindFile, &ffd ) )
  550. {
  551. bEnd = TRUE;
  552. break;
  553. }
  554. }
  555. // close handle
  556. ::FindClose( hFindFile );
  557. }
  558. // update position
  559. *pPosition = *pPosition + *pRead;
  560. return bEnd ? RR_RESULT_SUCCESS : RR_RESULT_SUCCESS_PENDING;
  561. }
  562. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeBackground( REPORT_PATH pPath, PREPORT_DATE_TIME pDateTime, PREPORT_IMAGE pImage )
  563. {
  564. // NOTE: should be changed: first of all should be checked cache !!!
  565. if( pPath && *pPath )
  566. return CLgReportLoaderClient::ReadSiteDateTimeBackground( pPath, pDateTime, pImage );
  567. // create path
  568. TCHAR pFullPath[MAX_PATH];
  569. BuildPathFull( pFullPath, pPath, pDateTime );
  570. ::PathAppend( pFullPath, PATH_BACKGROUND );
  571. return pImage->Load( pFullPath ) ? RR_RESULT_SUCCESS : RR_RESULT_FAILURE;
  572. }
  573. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeFilterEvent( REPORT_PATH pPath, PREPORT_DATE_TIME pDateTime, PREPORT_POSITION pPosition, PREPORT_FILTER_EVENT pFilterEvent, INT nCount, PINT pRead )
  574. {
  575. // NOTE: should be changed: first of all should be checked cache !!!
  576. if( pPath && *pPath )
  577. return CLgReportLoaderClient::ReadSiteDateTimeFilterEvent( pPath, pDateTime, pPosition, pFilterEvent, nCount, pRead );
  578. // create path
  579. TCHAR pFullPath[MAX_PATH];
  580. BuildPathFull( pFullPath, pPath, pDateTime );
  581. ::PathAppend( pFullPath, PATH_FILTER_EVENT );
  582. // reset counter
  583. *pRead = 0;
  584. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  585. if( hFile == INVALID_HANDLE_VALUE )
  586. return RR_RESULT_FAILURE;
  587. // end of read
  588. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  589. // read data
  590. LARGE_INTEGER liPos;
  591. liPos.QuadPart = *pPosition * sizeof( REPORT_FILTER_EVENT );
  592. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER )
  593. {
  594. DWORD dwRead = 0UL;
  595. DWORD dwToRead = sizeof(REPORT_FILTER_EVENT) * nCount;
  596. if( !::ReadFile( hFile, pFilterEvent, dwToRead, &dwRead, NULL ) || dwToRead != dwRead )
  597. eResult = RR_RESULT_SUCCESS;
  598. *pRead = dwRead / sizeof(REPORT_FILTER_EVENT);
  599. }
  600. else
  601. eResult = RR_RESULT_SUCCESS;
  602. // update position
  603. *pPosition = *pPosition + *pRead;
  604. ::CloseHandle( hFile );
  605. return eResult;
  606. }
  607. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeFilterSource( REPORT_PATH pPath, PREPORT_DATE_TIME pDateTime, PREPORT_POSITION pPosition, PREPORT_FILTER_SOURCE pFilterSource, INT nCount, PINT pRead )
  608. {
  609. // NOTE: should be changed: first of all should be checked cache !!!
  610. if( pPath && *pPath )
  611. return CLgReportLoaderClient::ReadSiteDateTimeFilterSource( pPath, pDateTime, pPosition, pFilterSource, nCount, pRead );
  612. // create path
  613. TCHAR pFullPath[MAX_PATH];
  614. BuildPathFull( pFullPath, pPath, pDateTime );
  615. ::PathAppend( pFullPath, PATH_FILTER_SOURCE );
  616. // reset counter
  617. *pRead = 0;
  618. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  619. if( hFile == INVALID_HANDLE_VALUE )
  620. return RR_RESULT_FAILURE;
  621. // end of read
  622. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  623. // read data
  624. LARGE_INTEGER liPos;
  625. liPos.QuadPart = *pPosition * sizeof( REPORT_FILTER_SOURCE );
  626. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER )
  627. {
  628. DWORD dwRead = 0UL;
  629. DWORD dwToRead = sizeof(REPORT_FILTER_SOURCE) * nCount;
  630. if( !::ReadFile( hFile, pFilterSource, dwToRead, &dwRead, NULL ) || dwToRead != dwRead )
  631. eResult = RR_RESULT_SUCCESS;
  632. *pRead = dwRead / sizeof(REPORT_FILTER_SOURCE);
  633. }
  634. else
  635. eResult = RR_RESULT_SUCCESS;
  636. // update position
  637. *pPosition = *pPosition + *pRead;
  638. ::CloseHandle( hFile );
  639. return eResult;
  640. }
  641. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeEvent( REPORT_PATH pPath, PREPORT_DATE_TIME pDateTime, PREPORT_POSITION pPosition, PREPORT_EVENT pEvent, INT nCount, PINT pRead )
  642. {
  643. // NOTE: should be changed: first of all should be checked cache !!!
  644. if( pPath && *pPath )
  645. return CLgReportLoaderClient::ReadSiteDateTimeEvent( pPath, pDateTime, pPosition, pEvent, nCount, pRead );
  646. // create path
  647. TCHAR pFullPath[MAX_PATH];
  648. BuildPathFull( pFullPath, pPath, pDateTime );
  649. ::PathAppend( pFullPath, PATH_EVENT );
  650. // reset counter
  651. *pRead = 0;
  652. HANDLE hFile = ::CreateFile( pFullPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
  653. if( hFile == INVALID_HANDLE_VALUE )
  654. return RR_RESULT_FAILURE;
  655. // end of read
  656. E_REPORT_RESULT eResult = RR_RESULT_SUCCESS_PENDING;
  657. // read data
  658. LARGE_INTEGER liPos;
  659. liPos.QuadPart = *pPosition * sizeof( REPORT_EVENT );
  660. if( ::SetFilePointer( hFile, liPos.LowPart, &liPos.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER )
  661. {
  662. DWORD dwRead = 0UL;
  663. DWORD dwToRead = sizeof(REPORT_EVENT) * nCount;
  664. if( !::ReadFile( hFile, pEvent, dwToRead, &dwRead, NULL ) || dwToRead != dwRead )
  665. eResult = RR_RESULT_SUCCESS;
  666. *pRead = dwRead / sizeof(REPORT_EVENT);
  667. }
  668. else
  669. eResult = RR_RESULT_SUCCESS;
  670. // update position
  671. *pPosition = *pPosition + *pRead;
  672. ::CloseHandle( hFile );
  673. return eResult;
  674. }
  675. E_REPORT_RESULT CLgReportProvider::DoReadSiteDateTimeImage( REPORT_PATH pPath, PREPORT_DATE_TIME pDateTime, PREPORT_POSITION pPosition, PREPORT_IMAGE pImage, INT nCount, PINT pRead )
  676. {
  677. // NOTE: should be changed: first of all should be checked cache !!!
  678. if( pPath && *pPath )
  679. return CLgReportLoaderClient::ReadSiteDateTimeImage( pPath, pDateTime, pPosition, pImage, nCount, pRead );
  680. // create path
  681. TCHAR pFullPath[MAX_PATH];
  682. BuildPathFull( pFullPath, pPath, pDateTime );
  683. // create image path
  684. TCHAR pImagePath[MAX_PATH];
  685. _sntprintf( pImagePath, MAX_PATH, PATH_IMAGE_FULL_FORMAT, pFullPath, (DWORD)( *pPosition / IMAGES_IN_BLOCK ), (DWORD)( *pPosition % IMAGES_IN_BLOCK ) );
  686. return ( *pRead = pImage->Load( pImagePath ) ? 1 : 0 ) ? RR_RESULT_SUCCESS : RR_RESULT_FAILURE;
  687. }
  688. */
  689. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  690. //
  691. //
  692. //
  693. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  694. void CLgReportProvider::DoReset()
  695. {
  696. // prepare new names
  697. ::GetLocalTime( &m_Storage.stReportTime );
  698. // convert to our format
  699. m_Storage.rdtReportTime.bYear = (BYTE)( m_Storage.stReportTime.wYear - 2000 );
  700. m_Storage.rdtReportTime.bMonth = (BYTE)m_Storage.stReportTime.wMonth;
  701. m_Storage.rdtReportTime.bDay = (BYTE)m_Storage.stReportTime.wDay;
  702. m_Storage.rdtReportTime.bHour = (BYTE)m_Storage.stReportTime.wHour;
  703. m_Storage.rdtReportTime.bMinute = (BYTE)m_Storage.stReportTime.wMinute;
  704. m_Storage.rdtReportTime.bSecond = (BYTE)m_Storage.stReportTime.wSecond;
  705. m_bPendingReset = TRUE;
  706. }
  707. void CLgReportProvider::CheckReset()
  708. {
  709. if( !m_bPendingReset )
  710. return;
  711. m_bPendingReset = FALSE;
  712. // build pathes
  713. TCHAR pDateTime[MAX_PATH];
  714. _sntprintf( pDateTime, MAX_PATH, PATH_DATE_FORMAT _T("\\") PATH_TIME_FORMAT, m_Storage.rdtReportTime.bYear, m_Storage.rdtReportTime.bMonth, m_Storage.rdtReportTime.bDay, m_Storage.rdtReportTime.bHour, m_Storage.rdtReportTime.bMinute, m_Storage.rdtReportTime.bSecond );
  715. TCHAR pPath[MAX_PATH];
  716. _tcsncpy( pPath, m_pRootPath, MAX_PATH );
  717. ::PathAppend( pPath, pDateTime );
  718. strcpy( m_Storage.pPathBackground, pPath );
  719. ::PathAppend( m_Storage.pPathBackground, PATH_BACKGROUND );
  720. strcpy( m_Storage.pPathFilterSource, pPath );
  721. ::PathAppend( m_Storage.pPathFilterSource, PATH_FILTER_SOURCE );
  722. strcpy( m_Storage.pPathFilterEvent, pPath );
  723. ::PathAppend( m_Storage.pPathFilterEvent, PATH_FILTER_EVENT );
  724. strcpy( m_Storage.pPathEvent, pPath );
  725. ::PathAppend( m_Storage.pPathEvent, PATH_EVENT );
  726. strcpy( m_Storage.pPathImage, pPath );
  727. ::PathAppend( m_Storage.pPathImage, PATH_IMAGE );
  728. // create path
  729. LgCreateDirectory( pPath );
  730. // reset storage positions
  731. m_Storage.nEventPosition = 0;
  732. m_Storage.nImageIndex = 0;
  733. m_Storage.nImageFolderIndex = -1;
  734. // call initialize procedure create site
  735. CLgLocker Lock( &StorageProviderToClientLinkSP::GetLock() );
  736. if( StorageProviderToClientLinkSP::GetLinkThis() )
  737. StorageProviderToClientLinkSP::GetLinkThis()->OnCreateSite();
  738. // notify loader provider about changes
  739. OnChange( RRT_SITE_DATE_TIME, NULL, &m_Storage.rdtReportTime );
  740. }
  741. BOOL CLgReportProvider::DoWriteReset()
  742. {
  743. DoReset();
  744. // CheckReset();
  745. return TRUE;
  746. }
  747. BOOL CLgReportProvider::DoWriteBackground( PREPORT_IMAGE pImage )
  748. {
  749. CheckReset();
  750. if( !pImage->Save( m_Storage.pPathBackground ) )
  751. {
  752. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteBackground"), _T("Can't store jpeg to <%s>"), (LPCTSTR)m_Storage.pPathBackground );
  753. return FALSE;
  754. }
  755. // notify loader provider about changes
  756. OnChange( RRT_SITE_DATE_TIME_BACKGROUND, NULL, &m_Storage.rdtReportTime );
  757. return TRUE;
  758. }
  759. BOOL CLgReportProvider::DoWriteFilterSource( PREPORT_FILTER_SOURCE pFilterSource )
  760. {
  761. CheckReset();
  762. FILE *pFile = fopen( m_Storage.pPathFilterSource, _T("ab+") );
  763. if( !pFile )
  764. {
  765. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteFilterSource"), _T("Can't open <%s>"), m_Storage.pPathFilterSource );
  766. return FALSE;
  767. }
  768. if( fwrite( pFilterSource, sizeof(REPORT_FILTER_SOURCE), 1, pFile ) != 1 )
  769. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteFilterSource"), _T("Can't write filter info") );
  770. fclose( pFile );
  771. // notify loader provider about changes
  772. OnChange( RRT_SITE_DATE_TIME_FILTER_SOURCE, NULL, &m_Storage.rdtReportTime );
  773. return TRUE;
  774. }
  775. BOOL CLgReportProvider::DoWriteFilterEvent( PREPORT_FILTER_EVENT pFilterEvent )
  776. {
  777. CheckReset();
  778. FILE *pFile = fopen( m_Storage.pPathFilterEvent, _T("ab+") );
  779. if( !pFile )
  780. {
  781. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteFilterEvent"), _T("Can't open <%s>"), m_Storage.pPathFilterEvent );
  782. return FALSE;
  783. }
  784. if( fwrite( pFilterEvent, sizeof(REPORT_FILTER_EVENT), 1, pFile ) != 1 )
  785. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteFilterEvent"), _T("Can't write filter info") );
  786. fclose( pFile );
  787. // notify loader provider about changes
  788. OnChange( RRT_SITE_DATE_TIME_FILTER_EVENT, NULL, &m_Storage.rdtReportTime );
  789. return TRUE;
  790. }
  791. BOOL CLgReportProvider::DoWriteEvent( PREPORT_EVENT pEvent, PREPORT_POSITION pPosition )
  792. {
  793. CheckReset();
  794. FILE *pFile = fopen( m_Storage.pPathEvent, m_Storage.nEventPosition ? _T("r+b") : _T("wb") );
  795. if( !pFile )
  796. {
  797. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteEvent"), _T("Can't open event file <%s>"), (LPCTSTR)m_Storage.pPathEvent );
  798. return FALSE;
  799. }
  800. if( fsetpos( pFile, &m_Storage.nEventPosition ) )
  801. {
  802. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteEvent"), _T("Can't set file position for read") );
  803. fclose( pFile );
  804. return FALSE;
  805. }
  806. if( fwrite( pEvent, sizeof(REPORT_EVENT), 1, pFile ) != 1 )
  807. {
  808. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteEvent"), _T("Can't store event") );
  809. fclose( pFile );
  810. return FALSE;
  811. }
  812. // return storage position
  813. if( pPosition )
  814. *pPosition = m_Storage.nEventPosition;
  815. // increase storage position
  816. m_Storage.nEventPosition += sizeof(REPORT_EVENT);
  817. fclose( pFile );
  818. // notify loader provider about changes
  819. OnChange( RRT_SITE_DATE_TIME_EVENT, NULL, &m_Storage.rdtReportTime );
  820. return TRUE;
  821. }
  822. BOOL CLgReportProvider::DoWriteImage( PREPORT_IMAGE pImage, PREPORT_POSITION pPosition )
  823. {
  824. CheckReset();
  825. INT nFolderIndex = m_Storage.nImageIndex / IMAGES_IN_BLOCK;
  826. INT nImageIndex = m_Storage.nImageIndex % IMAGES_IN_BLOCK;
  827. // create new subfolder as nessessary
  828. if( nFolderIndex != m_Storage.nImageFolderIndex )
  829. {
  830. _sntprintf( m_Storage.pPathImageFolder, MAX_PATH, PATH_IMAGE_FOLDER_FORMAT, m_Storage.pPathImage, nFolderIndex );
  831. LgCreateDirectory( m_Storage.pPathImageFolder );
  832. m_Storage.nImageFolderIndex = nFolderIndex;
  833. }
  834. TCHAR pImagePath[MAX_PATH];
  835. _sntprintf( pImagePath, MAX_PATH, PATH_IMAGE_FORMAT, m_Storage.pPathImageFolder, nImageIndex );
  836. if( !pImage->Save( pImagePath ) )
  837. return FALSE;
  838. if( pPosition )
  839. {
  840. FILE *pFile = fopen( m_Storage.pPathEvent, _T("r+b") );
  841. if( !pFile )
  842. {
  843. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteImage"), _T("Can't open event file <%s>"), (LPCTSTR)m_Storage.pPathEvent );
  844. return FALSE;
  845. }
  846. REPORT_EVENT re;
  847. if( fsetpos( pFile, pPosition ) )
  848. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteImage"), _T("Can't set file position for read") );
  849. if( fread( &re, sizeof(REPORT_EVENT), 1, pFile ) != 1 )
  850. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteImage"), _T("Can't read event") );
  851. // update image index
  852. if( re.bImageCount < REPORT_EVENT_IMAGE_MAX )
  853. re.dwImageIndex[ re.bImageCount++ ] = m_Storage.nImageIndex++;
  854. if( fsetpos( pFile, pPosition ) )
  855. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteImage"), _T("Can't set file position for write") );
  856. if( fwrite( &re, sizeof(REPORT_EVENT), 1, pFile ) != 1 )
  857. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_ERROR, this, _T("CLgReportProvider::DoWriteImage"), _T("Can't store event") );
  858. fclose( pFile );
  859. }
  860. // notify loader provider about changes
  861. OnChange( RRT_SITE_DATE_TIME_IMAGE, NULL, &m_Storage.rdtReportTime );
  862. return TRUE;
  863. }
  864. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  865. //
  866. //
  867. //
  868. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  869. void CLgReportProvider::BuildPath( LPSTR pPath, REPORT_PATH pReportPath, PREPORT_DATE pDate )
  870. {
  871. TCHAR pDateTimePath[MAX_PATH];
  872. _sntprintf( pDateTimePath, MAX_PATH, PATH_DATE_FORMAT, pDate->bYear, pDate->bMonth, pDate->bDay );
  873. _tcsncpy( pPath, m_pRootPath, MAX_PATH );
  874. if( pReportPath && *pReportPath ) ::PathAppend( pPath, (LPCSTR)pReportPath );
  875. ::PathAppend( pPath, pDateTimePath );
  876. }
  877. void CLgReportProvider::BuildPathFull( LPSTR pPath, REPORT_PATH pReportPath, PREPORT_DATE_TIME pDateTime )
  878. {
  879. TCHAR pDateTimePath[MAX_PATH];
  880. _sntprintf( pDateTimePath, MAX_PATH, PATH_DATE_FORMAT _T("\\") PATH_TIME_FORMAT, pDateTime->bYear, pDateTime->bMonth, pDateTime->bDay, pDateTime->bHour, pDateTime->bMinute, pDateTime->bSecond );
  881. _tcsncpy( pPath, m_pRootPath, MAX_PATH );
  882. if( pReportPath && *pReportPath ) ::PathAppend( pPath, (LPCSTR)pReportPath );
  883. ::PathAppend( pPath, pDateTimePath );
  884. }
  885. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  886. //
  887. // CLEANUP ENGINE
  888. //
  889. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  890. void CLgReportProvider::DeleteOldFiles(SYSTEMTIME st)
  891. {
  892. WIN32_FIND_DATA win32FD;
  893. LARGE_INTEGER ft;
  894. _TCHAR pBuffer[MAX_PATH];
  895. LPTSTR pNames = NULL;
  896. INT nNamesCount = 0;
  897. ::SystemTimeToFileTime( &st, (LPFILETIME)&ft );
  898. ft.QuadPart -= DAY2NANO( m_nMaxStorageDays );
  899. _tcsncpy( pBuffer, (LPCTSTR)m_pRootPath, MAX_PATH );
  900. ::PathAppend( pBuffer, _T("*.*") );
  901. HANDLE hFF = ::FindFirstFile(pBuffer, &win32FD);
  902. if(hFF != INVALID_HANDLE_VALUE)
  903. do{
  904. if( ( win32FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != FILE_ATTRIBUTE_DIRECTORY )
  905. continue;
  906. SYSTEMTIME cst = { 0 };
  907. if( _stscanf( win32FD.cFileName, PATH_DATE_FORMAT, &cst.wYear, &cst.wMonth, &cst.wDay ) != 3 )
  908. continue;
  909. // if it is current report then don't delete it
  910. if( m_Storage.stReportTime.wYear == cst.wYear &&
  911. m_Storage.stReportTime.wMonth == cst.wMonth &&
  912. m_Storage.stReportTime.wDay == cst.wDay )
  913. continue;
  914. LARGE_INTEGER cft;
  915. ::SystemTimeToFileTime(&cst, (LPFILETIME)&cft);
  916. if( cft.QuadPart >= ft.QuadPart )
  917. continue;
  918. _tcsncpy( pBuffer, (LPCTSTR)m_pRootPath, MAX_PATH );
  919. ::PathAppend( pBuffer, win32FD.cFileName );
  920. INT nLength = _tcslen(pBuffer) + 1;
  921. pNames = (LPTSTR)realloc( pNames, sizeof( TCHAR ) * ( nNamesCount + nLength ) );
  922. if( pNames )
  923. {
  924. memcpy( pNames + nNamesCount, pBuffer, nLength );
  925. nNamesCount += nLength;
  926. }
  927. }while(::FindNextFile(hFF, &win32FD));
  928. if( nNamesCount )
  929. {
  930. pNames = (LPTSTR)realloc( pNames, sizeof( TCHAR ) * ( nNamesCount + 1 ) );
  931. if( pNames )
  932. {
  933. // add one more zero
  934. pNames[nNamesCount] = 0;
  935. SHFILEOPSTRUCT sfs = { 0 };
  936. sfs.wFunc = FO_DELETE;
  937. sfs.pFrom = pNames;
  938. sfs.fFlags = FOF_NOCONFIRMATION | FOF_SIMPLEPROGRESS;
  939. sfs.lpszProgressTitle = _T("Deleting old history...");
  940. ::SHFileOperation(&sfs);
  941. delete pNames;
  942. }
  943. }
  944. ::FindClose(hFF);
  945. }
  946. BOOL CLgReportProvider::CheckOldFiles(SYSTEMTIME st)
  947. {
  948. WIN32_FIND_DATA win32FD;
  949. LARGE_INTEGER ft;
  950. _TCHAR pBuffer[MAX_PATH];
  951. BOOL fExist = FALSE;
  952. ::SystemTimeToFileTime(&st, (LPFILETIME)&ft);
  953. ft.QuadPart -= DAY2NANO( m_nMaxStorageDays );
  954. _tcsncpy( pBuffer, (LPCTSTR)m_pRootPath, MAX_PATH );
  955. ::PathAppend( pBuffer, _T("*.*") );
  956. HANDLE hFF = ::FindFirstFile(pBuffer, &win32FD);
  957. if(hFF != INVALID_HANDLE_VALUE)
  958. do{
  959. if(win32FD.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  960. {
  961. SYSTEMTIME cst;
  962. memset( &cst, 0, sizeof(cst) );
  963. if(_stscanf(win32FD.cFileName, PATH_DATE_FORMAT, &cst.wYear, &cst.wMonth, &cst.wDay ) == 3)
  964. {
  965. LARGE_INTEGER cft;
  966. memset( &cft, 0, sizeof(cft) );
  967. cst.wYear += 2000;
  968. if( !::SystemTimeToFileTime(&cst, (LPFILETIME)&cft) )
  969. {
  970. DWORD dwError = GetLastError();
  971. }
  972. if(cft.QuadPart < ft.QuadPart)
  973. fExist = TRUE;
  974. }
  975. }
  976. }while(::FindNextFile(hFF, &win32FD));
  977. ::FindClose(hFF);
  978. return fExist;
  979. }
  980. DWORD CLgReportProvider::ThreadProc()
  981. {
  982. try
  983. {
  984. TIME_ZONE_INFORMATION tzi;
  985. LARGE_INTEGER lt;
  986. SYSTEMTIME st;
  987. BOOL fNeedCheck = TRUE;
  988. ::GetTimeZoneInformation(&tzi);
  989. HANDLE hTimer = ::CreateWaitableTimer(NULL, FALSE, NULL);
  990. ::GetLocalTime(&st);
  991. st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
  992. ::SystemTimeToFileTime( &st, (LPFILETIME)&lt );
  993. lt.QuadPart += DAY2NANO( 1 ) + MINUTE2NANO( tzi.Bias );
  994. ::SetWaitableTimer(hTimer, &lt, 0UL, NULL, NULL, FALSE);
  995. HANDLE phEvents[] = { CLgThread::GetThreadStopEvent(), hTimer };
  996. if( CheckOldFiles( st ) )
  997. {
  998. // ask about deletition
  999. CLgLocker Lock( &StorageProviderToClientLinkSP::GetLock() );
  1000. if( StorageProviderToClientLinkSP::GetLinkThis() &&
  1001. StorageProviderToClientLinkSP::GetLinkThis()->OnAskForDeleteOld() )
  1002. DeleteOldFiles(st);
  1003. }
  1004. while(TRUE)
  1005. {
  1006. switch(::WaitForMultipleObjects(2, phEvents, FALSE, INFINITE))
  1007. {
  1008. case WAIT_OBJECT_0 + 0:
  1009. goto THREAD_EXIT;
  1010. case WAIT_OBJECT_0 + 1:
  1011. ::CancelWaitableTimer(hTimer);
  1012. ::GetLocalTime(&st);
  1013. DeleteOldFiles(st);
  1014. st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
  1015. ::SystemTimeToFileTime(&st, (LPFILETIME)&lt);
  1016. lt.QuadPart += DAY2NANO( 1 ) + MINUTE2NANO( tzi.Bias );
  1017. ::SetWaitableTimer(hTimer, &lt, 0UL, NULL, NULL, FALSE);
  1018. break;
  1019. default:
  1020. break;
  1021. }
  1022. } // end of while(TRUE)
  1023. THREAD_EXIT:
  1024. ::CancelWaitableTimer(hTimer);
  1025. ::CloseHandle(hTimer);
  1026. }
  1027. catch( ... )
  1028. {
  1029. LGLOG( LOG_LEVEL_LOW, LOG_TYPE_ERROR, this, _T("CLgReportProvider::ThreadProc"), _T("C++ eception") );
  1030. }
  1031. return 0UL;
  1032. }
  1033. BOOL CLgReportProvider::SetMaxStoreTime(INT nDays)
  1034. {
  1035. m_nMaxStorageDays = nDays;
  1036. return TRUE;
  1037. }
  1038. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1039. //
  1040. //
  1041. //
  1042. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////