Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1157 lines
35 KiB

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