testtoolsconn/stat/desktop/source/lib/src/cstatimageverify.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "stdafx.h"
       
    22 #include <STATCommon.h>
       
    23 #include "CSTATImageVerify.h"
       
    24 
       
    25 //----------------------------------------------------------------------------
       
    26 //standard constructor
       
    27 CSTATImageVerify::CSTATImageVerify(CSTATLogFile *pLog)
       
    28 : iImageCount(0), margin(0), lastrefimageloaded(0), pLogFile(pLog),
       
    29   m_pDib(NULL), m_pDib2(NULL), m_pDibBits(NULL), m_pDibBits2(NULL),
       
    30   m_pBIH(NULL), m_pBIH2(NULL), m_pPalette(NULL), m_pPalette2(NULL),
       
    31   m_dwDibSize(0), m_dwDibSize2(0), m_nPaletteEntries(0), m_nPaletteEntries2(0)
       
    32 {
       
    33 }
       
    34 
       
    35 //----------------------------------------------------------------------------
       
    36 //destructor
       
    37 CSTATImageVerify::~CSTATImageVerify()
       
    38 {
       
    39 	if (m_pDib)
       
    40 	{
       
    41 		delete [] m_pDib;
       
    42 		m_pDib = NULL;
       
    43 	}
       
    44 
       
    45 	if (m_pDib2)
       
    46 	{
       
    47 		delete [] m_pDib2;
       
    48 		m_pDib2 = NULL;
       
    49 	}
       
    50 }
       
    51 
       
    52 //----------------------------------------------------------------------------
       
    53 
       
    54 //image verification function (loading + blitting)
       
    55 int CSTATImageVerify::VerifyImage(CString& lastscreenshot)	
       
    56 {
       
    57 	TCHAR buffer[70];
       
    58 	_stprintf(buffer, _T("User set margin of error (percentage) : %ld"), margin);
       
    59 
       
    60 	pLogFile->Set(START_VERIFICATION, buffer);
       
    61 
       
    62 	// make sure we've got at least 1 image left
       
    63 	if(ImagesRemaining())
       
    64 	{
       
    65 		if(LoadRefImage())
       
    66 			pLogFile->Set(REFIMAGELOAD_OK, refimagearray[lastrefimageloaded++].completefilenamepath);
       
    67 		else
       
    68 			return pLogFile->Set(REFIMAGELOAD_FAILURE);
       
    69 
       
    70 		Sleep(500);
       
    71 
       
    72 		if(LoadNewImage(lastscreenshot))
       
    73 			pLogFile->Set(NEWIMAGELOAD_OK);
       
    74 		else
       
    75 			return pLogFile->Set(NEWIMAGELOAD_FAILURE);
       
    76 	}
       
    77 	else
       
    78 		return pLogFile->Set(REFIMAGELOAD_FAILURE_LIMIT);	//run out of reference images
       
    79 
       
    80 	//compare images and decide if difference is greater than margin value set earlier
       
    81 
       
    82 	// If we have not data we can't draw.
       
    83 	if (!m_pDib2)
       
    84 		return pLogFile->Set(VERIFICATION_FAILURE);
       
    85 
       
    86 	//set width and height of images
       
    87 	int nWidth = m_pBIH2 -> biWidth;
       
    88 	int nHeight = m_pBIH2 -> biHeight;
       
    89 
       
    90 	HDC hdc, hMaskDC, hImageDC;
       
    91 	HBITMAP hMaskBitmap, hImageBitmap;
       
    92 
       
    93 	hdc = GetDC(NULL);
       
    94 
       
    95 	//---------------------
       
    96 
       
    97 	hMaskDC = CreateCompatibleDC(hdc);
       
    98 	hImageDC = CreateCompatibleDC(hdc);
       
    99 	
       
   100 	hMaskBitmap = CreateCompatibleBitmap(hdc, nWidth, nHeight);
       
   101 	
       
   102 	SelectObject(hMaskDC, hMaskBitmap);
       
   103 	SetTextColor(hMaskDC, RGB(0, 0, 255)); 
       
   104 
       
   105 	//---------------------
       
   106 
       
   107 	hImageBitmap = CreateCompatibleBitmap(hdc, nWidth, nHeight);
       
   108 
       
   109 	// release the object now we're finished with it
       
   110 	ReleaseDC(NULL, hdc);
       
   111 
       
   112 	SelectObject(hImageDC, hImageBitmap);
       
   113 	SetTextColor(hImageDC, RGB(0, 0, 255)); 
       
   114 
       
   115 	//---------------------
       
   116 
       
   117 	//set MaskBitmap pixel data to that of the original DIB
       
   118 	SetDIBits(hMaskDC, hMaskBitmap, 0L, nHeight, m_pDibBits, (BITMAPINFO *)m_pBIH, (DWORD)DIB_RGB_COLORS);
       
   119 	
       
   120 	//create a new DIB using second image data
       
   121 	SetDIBits(hImageDC, hImageBitmap, 0L, nHeight, m_pDibBits2, (BITMAPINFO *)m_pBIH2, (DWORD)DIB_RGB_COLORS);
       
   122 
       
   123 	//XOR new image with original image (so new pic on top of pic 2)
       
   124 	BitBlt(hMaskDC, 0, 0, nWidth, nHeight, hImageDC, 0, 0, SRCINVERT);
       
   125 
       
   126 	//***************************************************
       
   127 
       
   128 	//now work on percentage difference in images
       
   129 
       
   130 	//need to use 'new' otherwise you get a stack overflow with anything big like this (1MB+)
       
   131 	COLORREF (*pixelcoord) [480];
       
   132 	pixelcoord = new COLORREF [640][480];
       
   133 	if (!pixelcoord)
       
   134 		return pLogFile->Set(VERIFICATION_FAILURE);
       
   135 
       
   136 	int x, y, myheight, mywidth;
       
   137 	float totalpixelarea;
       
   138 
       
   139 	x = 0;
       
   140 	y = 0;
       
   141 	int difference = 0;
       
   142 	float finalpercentage = 0;
       
   143 	totalpixelarea = 0;
       
   144 	myheight = 0;
       
   145 	mywidth = 0;
       
   146 
       
   147 	mywidth = m_pBIH -> biWidth;
       
   148 	myheight = m_pBIH -> biHeight;
       
   149 
       
   150 	// convert total to float for later % calculation
       
   151 	totalpixelarea = (float)(mywidth * myheight);
       
   152 
       
   153 	//initialisation
       
   154 	for(y = 0; y < 480; y++)
       
   155 	{
       
   156 		//go across picture left to right at each line
       
   157 		for(x = 0; x < 640; x++)
       
   158 		{
       
   159 			//get colorref value from coordinates
       
   160 			pixelcoord[x][y] = 0;
       
   161 		}
       
   162 	}
       
   163 
       
   164 	//check pixels - start at line 0
       
   165 	for(y = 0; y < myheight; y++)
       
   166 	{
       
   167 		//go across picture left to right at each line
       
   168 		for(x = 0; x < mywidth; x++)
       
   169 		{
       
   170 			//get colorref value from coordinates
       
   171 			pixelcoord[x][y] = GetPixel(hMaskDC, x, y);
       
   172 
       
   173 			//if not a  black pixel then increment counter
       
   174 			if(pixelcoord[x][y] != 0)
       
   175 			{
       
   176 				difference++;
       
   177 			}
       
   178 		}
       
   179 	}
       
   180 
       
   181 	// release resources
       
   182 	delete [] pixelcoord;
       
   183 	DeleteDC(hMaskDC);
       
   184 	DeleteDC(hImageDC);
       
   185 	DeleteObject(hMaskBitmap);
       
   186 	DeleteObject(hImageBitmap);
       
   187 
       
   188 	if (m_pDib)
       
   189 	{
       
   190 		delete [] m_pDib;
       
   191 		m_pDib = NULL;
       
   192 	}
       
   193 
       
   194 	if (m_pDib2)
       
   195 	{
       
   196 		delete [] m_pDib2;
       
   197 		m_pDib2 = NULL;
       
   198 	}
       
   199 
       
   200 	//now calculate percentage of pic that is not black
       
   201 	finalpercentage = ((difference / totalpixelarea) * 100);
       
   202 
       
   203 	// write conversion info to file
       
   204 
       
   205 
       
   206 	CString cBuffer;
       
   207 	cBuffer.Format(_T("Margin %ld : Difference %f"), margin, finalpercentage);
       
   208 	pLogFile->Set(cBuffer);
       
   209 
       
   210 	if(finalpercentage > margin)
       
   211 		return pLogFile->Set(VERIFICATION_FAILURE);
       
   212 
       
   213 	return pLogFile->Set(VERIFICATION_PASS);
       
   214 }
       
   215 
       
   216 
       
   217 //----------------------------------------------------------------------------
       
   218 //image loading for current new image
       
   219 bool CSTATImageVerify::LoadNewImage(CString& newimage)
       
   220 {
       
   221 	CFile cf;
       
   222 
       
   223 	// Attempt to open the Dib file for reading.
       
   224 	if(!cf.Open(newimage, CFile::modeRead))
       
   225 		return false;
       
   226 
       
   227 	// Get the size of the file and store
       
   228 	// in a local variable. Subtract the
       
   229 	// size of the BITMAPFILEHEADER structure
       
   230 	// since we won't keep that in memory.
       
   231 	DWORD dwDibSize;
       
   232 	dwDibSize = cf.GetLength() - sizeof( BITMAPFILEHEADER );
       
   233 
       
   234 	// Attempt to allocate the Dib memory.
       
   235 	unsigned char *pDib;
       
   236 	pDib = new unsigned char [dwDibSize];
       
   237 	if(!pDib)
       
   238 	{
       
   239 		cf.Close();
       
   240 		return false;
       
   241 	}
       
   242 
       
   243 	BITMAPFILEHEADER BFH;
       
   244 
       
   245 	// Read in the Dib header and data.
       
   246 	try
       
   247 	{
       
   248 		// Did we read in the entire BITMAPFILEHEADER?
       
   249 		if( cf.Read( &BFH, sizeof( BITMAPFILEHEADER ) )
       
   250 			!= sizeof( BITMAPFILEHEADER ) ||
       
   251 
       
   252 			// Is the type 'MB'?
       
   253 			BFH.bfType != 'MB' ||
       
   254 
       
   255 			// Did we read in the remaining data?
       
   256 			cf.Read( pDib, dwDibSize ) != dwDibSize )
       
   257 		{
       
   258 
       
   259 			// Delete the memory if we had any
       
   260 			// errors and return FALSE.
       
   261 			delete [] pDib;
       
   262 			cf.Close();
       
   263 			return false;
       
   264 			}
       
   265 		}
       
   266 
       
   267 	// If we catch an exception, delete the
       
   268 	// exception, the temporary Dib memory,
       
   269 	// and return FALSE.
       
   270 	catch( CFileException *e )
       
   271 	{
       
   272 		e->Delete();
       
   273 		delete [] pDib;
       
   274 		cf.Close();
       
   275 		return( FALSE );
       
   276 	}
       
   277 	
       
   278 	// If we got to this point, the Dib has been
       
   279 	// loaded. If a Dib was already loaded into
       
   280 	// this class, we must now delete it.
       
   281 	if (m_pDib2)
       
   282 	{
       
   283 		delete [] m_pDib2;
       
   284 		m_pDib2 = NULL;
       
   285 	}
       
   286 
       
   287 	// Store the local Dib data pointer and
       
   288 	// Dib size variables in the class member
       
   289 	// variables.
       
   290 	m_pDib2 = pDib;
       
   291 	m_dwDibSize2 = dwDibSize;
       
   292 
       
   293 	// Pointer our BITMAPINFOHEADER and RGBQUAD
       
   294 	// variables to the correct place in the Dib data.
       
   295 	m_pBIH2 = (BITMAPINFOHEADER *) m_pDib2;
       
   296 	m_pPalette2 =
       
   297 		(RGBQUAD *) &m_pDib2[sizeof(BITMAPINFOHEADER)];
       
   298 
       
   299 	// Calculate the number of palette entries.
       
   300 	m_nPaletteEntries = 1 << m_pBIH2->biBitCount;
       
   301 	if( m_pBIH2->biBitCount > 8 )
       
   302 		m_nPaletteEntries = 0;
       
   303 	else if( m_pBIH2->biClrUsed != 0 )
       
   304 		m_nPaletteEntries = m_pBIH2->biClrUsed;
       
   305 
       
   306 	// Point m_pDib2Bits to the actual Dib bits data.
       
   307 	m_pDibBits2 =
       
   308 		&m_pDib2[sizeof(BITMAPINFOHEADER)+
       
   309 			m_nPaletteEntries*sizeof(RGBQUAD)];
       
   310 
       
   311 	// If we have a valid palette, delete it.
       
   312 	if( m_Palette.GetSafeHandle() != NULL )
       
   313 		m_Palette.DeleteObject();
       
   314 
       
   315 	// If there are palette entries, we'll need
       
   316 	// to create a LOGPALETTE then create the
       
   317 	// CPalette palette.
       
   318 	if( m_nPaletteEntries != 0 )
       
   319 	{
       
   320 		// Allocate the LOGPALETTE structure.
       
   321 		LOGPALETTE *pLogPal = (LOGPALETTE *) new char [sizeof(LOGPALETTE) + m_nPaletteEntries*sizeof(PALETTEENTRY)];
       
   322 		if (pLogPal)
       
   323 		{
       
   324 			// Set the LOGPALETTE to version 0x300
       
   325 			// and store the number of palette
       
   326 			// entries.
       
   327 			pLogPal->palVersion = 0x300;
       
   328 			pLogPal->palNumEntries = (WORD)m_nPaletteEntries;
       
   329 
       
   330 			// Store the RGB values into each
       
   331 			// PALETTEENTRY element.
       
   332 			for( int i=0; i<m_nPaletteEntries; i++ )
       
   333 			{
       
   334 				pLogPal->palPalEntry[i].peRed =
       
   335 					m_pPalette2[i].rgbRed;
       
   336 				pLogPal->palPalEntry[i].peGreen =
       
   337 					m_pPalette2[i].rgbGreen;
       
   338 				pLogPal->palPalEntry[i].peBlue =
       
   339 					m_pPalette2[i].rgbBlue;
       
   340 			}
       
   341 
       
   342 			// Create the CPalette object and
       
   343 			// delete the LOGPALETTE memory.
       
   344 			m_Palette.CreatePalette( pLogPal );
       
   345 			delete [] pLogPal;
       
   346 		}
       
   347 		else
       
   348 			return false;
       
   349 	}
       
   350 
       
   351 	cf.Close();
       
   352 
       
   353 	return true;
       
   354 }
       
   355 
       
   356 //----------------------------------------------------------------------------
       
   357 //image loading for current reference image
       
   358 bool CSTATImageVerify::LoadRefImage()
       
   359 {
       
   360 	CFile cf;
       
   361 	if( !cf.Open(refimagearray[lastrefimageloaded].completefilenamepath, CFile::modeRead ) )
       
   362 		return false;
       
   363 
       
   364 	// Get the size of the file and store
       
   365 	// in a local variable. Subtract the
       
   366 	// size of the BITMAPFILEHEADER structure
       
   367 	// since we won't keep that in memory.
       
   368 	DWORD dwDibSize;
       
   369 	dwDibSize = cf.GetLength() - sizeof( BITMAPFILEHEADER );
       
   370 
       
   371 	// Attempt to allocate the Dib memory.
       
   372 	unsigned char *pDib;
       
   373 	pDib = new unsigned char [dwDibSize];
       
   374 	if(!pDib)
       
   375 	{
       
   376 		cf.Close();
       
   377 		return false;
       
   378 	}
       
   379 
       
   380 	BITMAPFILEHEADER BFH;
       
   381 
       
   382 	// Read in the Dib header and data.
       
   383 	try
       
   384 	{
       
   385 
       
   386 		// Did we read in the entire BITMAPFILEHEADER?
       
   387 		if( cf.Read( &BFH, sizeof( BITMAPFILEHEADER ) )
       
   388 			!= sizeof( BITMAPFILEHEADER ) ||
       
   389 
       
   390 			// Is the type 'MB'?
       
   391 			BFH.bfType != 'MB' ||
       
   392 
       
   393 			// Did we read in the remaining data?
       
   394 			cf.Read( pDib, dwDibSize ) != dwDibSize )
       
   395 		{
       
   396 
       
   397 			// Delete the memory if we had any
       
   398 			// errors and return FALSE.
       
   399 			delete [] pDib;
       
   400 			cf.Close();
       
   401 			return false;
       
   402 		}
       
   403 	}
       
   404 
       
   405 	// If we catch an exception, delete the
       
   406 	// exception, the temporary Dib memory,
       
   407 	// and return FALSE.
       
   408 	catch( CFileException *e )
       
   409 	{
       
   410 		e->Delete();
       
   411 		delete [] pDib;
       
   412 		cf.Close();
       
   413 		return false;
       
   414 	}
       
   415 	
       
   416 	// If we got to this point, the Dib has been
       
   417 	// loaded. If a Dib was already loaded into
       
   418 	// this class, we must now delete it.
       
   419 	if(m_pDib)
       
   420 	{
       
   421 		delete m_pDib;
       
   422 		m_pDib = NULL;
       
   423 	}
       
   424 
       
   425 	// Store the local Dib data pointer and
       
   426 	// Dib size variables in the class member
       
   427 	// variables.
       
   428 	m_pDib = pDib;
       
   429 	m_dwDibSize = dwDibSize;
       
   430 
       
   431 	// Pointer our BITMAPINFOHEADER and RGBQUAD
       
   432 	// variables to the correct place in the Dib data.
       
   433 	m_pBIH = (BITMAPINFOHEADER *) m_pDib;
       
   434 	m_pPalette =
       
   435 		(RGBQUAD *) &m_pDib[sizeof(BITMAPINFOHEADER)];
       
   436 
       
   437 	// Calculate the number of palette entries.
       
   438 	m_nPaletteEntries = 1 << m_pBIH->biBitCount;
       
   439 	if( m_pBIH->biBitCount > 8 )
       
   440 		m_nPaletteEntries = 0;
       
   441 	else if( m_pBIH->biClrUsed != 0 )
       
   442 		m_nPaletteEntries = m_pBIH->biClrUsed;
       
   443 
       
   444 	// Point m_pDibBits to the actual Dib bits data.
       
   445 	m_pDibBits =
       
   446 		&m_pDib[sizeof(BITMAPINFOHEADER)+
       
   447 			m_nPaletteEntries*sizeof(RGBQUAD)];
       
   448 
       
   449 	// If we have a valid palette, delete it.
       
   450 	if (m_Palette.GetSafeHandle())
       
   451 		m_Palette.DeleteObject();
       
   452 
       
   453 	// If there are palette entries, we'll need
       
   454 	// to create a LOGPALETTE then create the
       
   455 	// CPalette palette.
       
   456 	if( m_nPaletteEntries != 0 )
       
   457 	{
       
   458 		// Allocate the LOGPALETTE structure.
       
   459 		LOGPALETTE *pLogPal = (LOGPALETTE *) new char
       
   460 				[sizeof(LOGPALETTE)+
       
   461 				m_nPaletteEntries*sizeof(PALETTEENTRY)];
       
   462 
       
   463 		if(pLogPal)
       
   464 		{
       
   465 
       
   466 			// Set the LOGPALETTE to version 0x300
       
   467 			// and store the number of palette
       
   468 			// entries.
       
   469 			pLogPal->palVersion = 0x300;
       
   470 			pLogPal->palNumEntries = (WORD)m_nPaletteEntries;
       
   471 
       
   472 			// Store the RGB values into each
       
   473 			// PALETTEENTRY element.
       
   474 			for( int i=0; i<m_nPaletteEntries; i++ )
       
   475 			{
       
   476 				pLogPal->palPalEntry[i].peRed =
       
   477 					m_pPalette[i].rgbRed;
       
   478 				pLogPal->palPalEntry[i].peGreen =
       
   479 					m_pPalette[i].rgbGreen;
       
   480 				pLogPal->palPalEntry[i].peBlue =
       
   481 					m_pPalette[i].rgbBlue;
       
   482 			}
       
   483 
       
   484 			// Create the CPalette object and
       
   485 			// delete the LOGPALETTE memory.
       
   486 			m_Palette.CreatePalette( pLogPal );
       
   487 			delete [] pLogPal;
       
   488 		}
       
   489 		else
       
   490 			return false;
       
   491 	}
       
   492 
       
   493 	cf.Close();
       
   494 
       
   495 	return true;
       
   496 }
       
   497 
       
   498 //----------------------------------------------------------------------------
       
   499 int CSTATImageVerify::EnableVerification(int fudge)
       
   500 {
       
   501 	// temp variable
       
   502 	FILETIME creationtime;
       
   503 	creationtime.dwLowDateTime = 0;
       
   504 	creationtime.dwHighDateTime = 0;
       
   505 
       
   506 	// initialise settings
       
   507 	iImageCount = 0;
       
   508 	lastrefimageloaded = 0;
       
   509 	margin = fudge;
       
   510 
       
   511 	// check limits
       
   512 	if (margin < 0)
       
   513 		margin = 0;
       
   514 	if (margin > 100)
       
   515 		margin = 100;
       
   516 
       
   517 	// populate our array with images
       
   518 	CFileFind refimagefinder;
       
   519 	if (refimagefinder.FindFile(referenceimagedir + _T("\\*.bmp"), 0))
       
   520 	{
       
   521 		int i = 0;
       
   522 		int iMoreFiles = true;
       
   523 		for (i=0;i<VERIFY_MAX_IMAGES;i++)
       
   524 		{
       
   525 			if (iMoreFiles)
       
   526 			{
       
   527 				iMoreFiles = refimagefinder.FindNextFile();
       
   528   				refimagearray[i].completefilenamepath = refimagefinder.GetFilePath();	//store filename into array string variable
       
   529 				refimagefinder.GetLastWriteTime(&creationtime);		//store corresponding modification time
       
   530 				refimagearray[i].lCreationTime = (((ULONGLONG) creationtime.dwHighDateTime) << 32) + creationtime.dwLowDateTime;
       
   531 				iImageCount++;
       
   532 			}
       
   533 			else
       
   534 			{
       
   535 				refimagearray[i].completefilenamepath = _T("");
       
   536 				refimagearray[i].lCreationTime = 0;
       
   537 			}
       
   538 		}
       
   539 
       
   540 		refimagefinder.Close();
       
   541 	}
       
   542 	
       
   543 	// now sort into date/time order
       
   544 	if (iImageCount)
       
   545 	{
       
   546 		CSTATReferenceImages temp;
       
   547 		bool bNotFinished = true;
       
   548 		int i = 0;
       
   549 		while (bNotFinished)
       
   550 		{
       
   551 			bNotFinished = false;
       
   552 			for (i=0;i<iImageCount;i++)
       
   553 			{
       
   554 				if ((i + 1) < iImageCount &&
       
   555 					refimagearray[i+1].lCreationTime < refimagearray[i].lCreationTime)
       
   556 				{
       
   557 					temp = refimagearray[i];
       
   558 					refimagearray[i]= refimagearray[i+1];
       
   559 					refimagearray[i+1]= temp;
       
   560 					bNotFinished = true;
       
   561 				}
       
   562 			}
       
   563 		}
       
   564 	}
       
   565 
       
   566 	return iImageCount;
       
   567 }
       
   568 //----------------------------------------------------------------------------
       
   569 
       
   570 //----------------------------------------------------------------------------
       
   571 // Get the local reference image directory from the registry
       
   572 int CSTATImageVerify::Initialise(const CString& path)
       
   573 {
       
   574 	int ret = ERROR_REGISTRY;
       
   575 	TCHAR szFullPath[256 + 1];
       
   576 
       
   577 
       
   578 	_tcsncpy(szFullPath, path.operator LPCTSTR(), path.GetLength() + 1);
       
   579 	
       
   580 	//append ref images directory to the stat installation directory as found in registry
       
   581 	_tcscat(szFullPath, _T("\\Reference Images"));
       
   582 	referenceimagedir = szFullPath;
       
   583 
       
   584 	// try to create in case it doesn't exist
       
   585 	CreateDirectory(referenceimagedir, NULL);
       
   586 
       
   587 	// there may be old files to delete...
       
   588 	_tcscat(szFullPath, _T("\\*.*"));
       
   589 	CFileFind finder;
       
   590 	if (finder.FindFile(szFullPath, 0))
       
   591 	{
       
   592 		int iWorking = 1;
       
   593 		int filecount = 0;
       
   594 		while (iWorking)
       
   595 		{
       
   596 			iWorking = finder.FindNextFile();
       
   597 
       
   598 			// skip . and .. files
       
   599 			if (finder.IsDots())
       
   600 				continue;
       
   601 
       
   602 			filecount++;
       
   603 		}
       
   604 
       
   605 		finder.Close();
       
   606 
       
   607 		if (filecount)
       
   608 			ret = REFDIR_FOUND;
       
   609 		else
       
   610 			ret = ITS_OK;
       
   611 	}
       
   612 	else
       
   613 		ret = LOG_DIR_CREATE_FAILURE;
       
   614 	
       
   615 	
       
   616 	
       
   617 	return ret;
       
   618 }
       
   619 
       
   620 //----------------------------------------------------------------------------
       
   621 //reference images copied over to local machine
       
   622 int CSTATImageVerify::CopyReferenceImages(LPTSTR refimagelocation)
       
   623 {
       
   624 	int ret = GENERAL_FAILURE;
       
   625 
       
   626 	// need to copy into null terminated string to have 2 nulls at end as required
       
   627 	TCHAR szFrom[MAX_PATH + 1] = {0};
       
   628 	_tcscpy(szFrom, refimagelocation);
       
   629 	_tcscat(szFrom, _T("\\*.bmp"));
       
   630 
       
   631 	// need to copy into null terminated string to have 2 nulls at end as required
       
   632 	TCHAR szTo[MAX_PATH + 1] = {0};
       
   633 	_tcscpy(szTo, referenceimagedir);
       
   634 
       
   635 	//new file structure for copying files
       
   636 	SHFILEOPSTRUCT fo = {0};
       
   637 	fo.wFunc = FO_COPY;
       
   638 	fo.pFrom = szFrom;
       
   639 	fo.pTo = szTo;
       
   640 	fo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
       
   641 
       
   642 	//copy new images across
       
   643 	if(::SHFileOperation(&fo) != 0) //if fail file operation
       
   644 		return ERR_FILE_COPY_FAILED;
       
   645 
       
   646 	// check that at least 1 bitmap image got copied across
       
   647 	_tcscat(szTo, _T("\\*.bmp"));
       
   648 	CFileFind finder;
       
   649 	ret = finder.FindFile(szTo, 0);
       
   650 	finder.Close();
       
   651 	if (!ret)
       
   652 		return NO_BITMAPS;
       
   653 
       
   654 	return ITS_OK;
       
   655 }
       
   656 
       
   657 //----------------------------------------------------------------------------
       
   658 //local reference images deleted from local machine
       
   659 int CSTATImageVerify::DeleteReferenceImages()
       
   660 {
       
   661 	// need to copy into null terminated string to have 2 nulls at end as required
       
   662 	TCHAR szImages[MAX_PATH + 1] = {0};
       
   663 	_tcscpy(szImages, referenceimagedir);
       
   664 	_tcscat(szImages, _T("\\*.*"));
       
   665 	
       
   666 	//new file structure for deleting files
       
   667 	SHFILEOPSTRUCT fo2 = {0};
       
   668 	fo2.wFunc = FO_DELETE;
       
   669 	fo2.pFrom = szImages;
       
   670 	fo2.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_FILESONLY | FOF_NOERRORUI;
       
   671 
       
   672 	//delete
       
   673 	if(::SHFileOperation(&fo2) != 0) //if fail file deletion
       
   674 		return DELETEIMAGES_FAILURE;
       
   675 
       
   676 	return ITS_OK;
       
   677 }
       
   678