Пример #1
0
Datum
RestorePlanFromDXLFile(PG_FUNCTION_ARGS)
{
	char *szFilename = textToString(PG_GETARG_TEXT_P(0));

	CFileReader fr;
	fr.Open(szFilename);
	ULLONG ullSize = fr.UllSize();

	char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1);
	fr.UlpRead((BYTE*)pcBuf, ullSize);
	pcBuf[ullSize] = '\0';

	fr.Close();

	int	iProcessed = executeXMLPlan(pcBuf);

	elog(NOTICE, "Processed %d rows.", iProcessed);
	gpdb::GPDBFree(pcBuf);

	StringInfoData str;
	initStringInfo(&str);

	appendStringInfo(&str, "Query processed %d rows", iProcessed);
	text *ptResult = stringToText(str.data);

	PG_RETURN_TEXT_P(ptResult);
}
Пример #2
0
Datum
RestoreQueryFromFile(PG_FUNCTION_ARGS)
{
	char *szFilename = text_to_cstring(PG_GETARG_TEXT_P(0));

	CFileReader fr;
	fr.Open(szFilename);
	ULLONG ullSize = fr.UllSize();
	elog(NOTICE, "(RestoreFromFile) Filesize is " UINT64_FORMAT, (uint64) ullSize);

	char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize);
	fr.UlpRead((BYTE*)pcBuf, ullSize);
	fr.Close();

	int iBinaryLen;
	memcpy(&iBinaryLen, pcBuf, sizeof(int));
	Assert(iBinaryLen == ullSize - sizeof(int));

	elog(NOTICE, "(RestoreFromFile) BinaryLen is %d", iBinaryLen);
	char *pcBinary = pcBuf + sizeof(int);

	int iProcessed = extractFrozenQueryPlanAndExecute(pcBinary);

	elog(NOTICE, "(RestorePlan) PROCESSED %d", iProcessed);
	StringInfoData str;
	initStringInfo(&str);

	appendStringInfo(&str, "Query processed %d rows", iProcessed);
	text *ptResult = cstring_to_text(str.data);

	PG_RETURN_TEXT_P(ptResult);
}
Пример #3
0
Datum
EvalExprFromDXLFile(PG_FUNCTION_ARGS)
{
	char *szFileName = textToString(PG_GETARG_TEXT_P(0));
	CFileReader fr;
	fr.Open(szFileName);
	ULLONG ullSize = fr.UllSize();
	char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1);
	fr.UlpRead((BYTE*)pcBuf, ullSize);
	fr.Close();
	pcBuf[ullSize] = '\0';

	char *szResultDXL = COptTasks::SzEvalExprFromXML(pcBuf);
	gpdb::GPDBFree(pcBuf);

	if (NULL != szResultDXL)
	{
		text *ptResult = stringToText(szResultDXL);
		gpdb::GPDBFree(szResultDXL);
		PG_RETURN_TEXT_P(ptResult);
	}
	else
	{
		// Return a dummy value so the tests can continue
		PG_RETURN_NULL();
	}
}
Пример #4
0
Datum
RestorePlanFromFile(PG_FUNCTION_ARGS)
{
	char *szFilename = textToString(PG_GETARG_TEXT_P(0));

	CFileReader fr;
	fr.Open(szFilename);
	ULLONG ullSize = fr.UllSize();

	char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize);
	fr.UlpRead((BYTE*)pcBuf, ullSize);
	fr.Close();

	int iBinaryLen;
	memcpy(&iBinaryLen, pcBuf, sizeof(int));
	Assert(iBinaryLen == ullSize - sizeof(int));

	char *pcBinary = pcBuf + sizeof(int);

	int	iProcessed = extractFrozenPlanAndExecute(pcBinary);

	elog(NOTICE, "Processed %d rows.", iProcessed);
	gpdb::GPDBFree(pcBuf);

	StringInfoData str;
	initStringInfo(&str);

	appendStringInfo(&str, "Query processed %d rows", iProcessed);
	text *ptResult = stringToText(str.data);

	PG_RETURN_TEXT_P(ptResult);
}
Пример #5
0
// -----------------------------------------------------------------------------
// CFileReader::NewL
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFileReader* CFileReader::NewL(RFile& aFile, TInt aChunkSize, FileConnection* aFileConnection) 
{
    CFileReader* self = new( ELeave ) CFileReader( aFile, aChunkSize, aFileConnection );
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop();
    return self;
}
Пример #6
0
char *read_file(const char *szFilename)
{
	CFileReader fr;
	fr.Open(szFilename);
	ULLONG ullSize = fr.UllSize();

	char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize);
	fr.UlpRead((BYTE*)pcBuf, ullSize);
	pcBuf[ullSize] = '\0';
	
	fr.Close();
	return pcBuf;
}
Пример #7
0
LRESULT CMainFrame::OnReadJpeg( WPARAM wParam, LPARAM lParam )
{
	int nSegmentCount = 0;
	CSegmentData *lpSegmentData = NULL;
	CSegmentInfo *lpSegmentInfo = NULL;

	CFileReader FileReader;
	CJpegAnalyzer JpegAnalyzer;
	CUserDatas* lpUserDatas = ((CIFuzzMakerDoc*)GetActiveDocument())->GetUserDatas();
	
	lpUserDatas->GetReadBufferArray().RemoveAll();
	if( !FileReader.ReadFile( lpUserDatas->GetJpegFileName(), lpUserDatas->GetReadBufferArray() ) )
	{
		//	エラー
		return FALSE;
	}

	//	Jpeg解析
	lpUserDatas->GetSegmentDataArray().RemoveAllWithDelete();
	if( !JpegAnalyzer.Analyze( lpUserDatas->GetReadBufferArray(), m_FixedDatas.GetSegmentInfoMap(), lpUserDatas->GetSegmentDataArray() ) )
		return FALSE;

	//	Exif解析
	for(nSegmentCount=0; nSegmentCount<lpUserDatas->GetSegmentDataArray().GetSize(); nSegmentCount++ )
	{
		lpSegmentData = lpUserDatas->GetSegmentDataArray().GetAt( nSegmentCount );
		if( lpSegmentData )
		{
			lpSegmentInfo = lpSegmentData->GetSegmentInfo();
			if( lpSegmentInfo )
			{
				if( lpSegmentInfo->GetMarker() == _T("FFE1") )
				{
					CExifAnalyzer ExifAnalyzer;
					ExifAnalyzer.Analyze( lpUserDatas->GetReadBufferArray().GetSize(), lpSegmentData, &m_FixedDatas.GetImageFileDirectoryInfoMap(), &m_FixedDatas.GetTagTypeInfoMap() );
				}
				if( lpSegmentInfo->IsAnalysisSegment() )
				{
					CSegmentAnalyzer SegmentAnalyzer;
					SegmentAnalyzer.Analyze( lpUserDatas->GetReadBufferArray().GetSize(), lpSegmentData );
				}
			}
		}
	}

	SendMessageToDescendants( WM_APP_EXIF_ANALYZED, NULL, NULL );

	return TRUE;
}
Пример #8
0
Datum
DumpQueryFromFileToDXLFile(PG_FUNCTION_ARGS)
{
	char *szSqlFilename = textToString(PG_GETARG_TEXT_P(0));
	char *szFilename = textToString(PG_GETARG_TEXT_P(1));

	CFileReader fr;
	fr.Open(szSqlFilename);
	ULLONG ullSize = fr.UllSize();

	char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1);
	fr.UlpRead((BYTE*)pcBuf, ullSize);
	pcBuf[ullSize] = '\0';
	fr.Close();

	int iLen = translateQueryToFile(pcBuf, szFilename);

	gpdb::GPDBFree(pcBuf);

	PG_RETURN_INT32(iLen);
}
Пример #9
0
//=============================================================================
//	初期化
//	ここでsin,cosそれぞれのテーブルを作成
//=============================================================================
void CRadianTable::Init()
{
	CFileReader* sinReader = new CFileReader();
	CFileReader* cosReader = new CFileReader();

	cosReader->FileOpen("data/radianTable/cosTable.txt", "r");
	sinReader->FileOpen("data/radianTable/sinTable.txt", "r");

	char* sinBuff = new char[256];
	char* cosBuff = new char[256];

	for (int count = 0; count < TABELE_MAX; count++)
	{
		sinReader->GetLine(sinBuff);
		cosReader->GetLine(cosBuff);

		sinTable[count] = (float)atof(sinBuff);
		cosTable[count] = (float)atof(cosBuff);
	}

	SAFE_DELETE(sinBuff);
	SAFE_DELETE(cosBuff);
	SAFE_DELETE(sinReader);
	SAFE_DELETE(cosReader);
}
Пример #10
0
//---------------------------------------------------------------------------
//	@function:
//		COstreamFileTest::Unittest_CheckOutputFile
//
//	@doc:
//		Check the contents of the file used by the output stream
//
//---------------------------------------------------------------------------
void
COstreamFileTest::Unittest_CheckOutputFile
	(
	const CHAR *szFile
	)
{
	GPOS_ASSERT(NULL != szFile);

	CFileReader fr;
	fr.Open(szFile);

	const ULONG ulReadBufferSize = 1024;
	WCHAR wszReadBuffer[ulReadBufferSize];

#ifdef GPOS_DEBUG
	ULONG_PTR ulpRead =
#endif // GPOS_DEBUG
	fr.UlpRead((BYTE *) wszReadBuffer, GPOS_ARRAY_SIZE(wszReadBuffer));

	CWStringConst strExpected(GPOS_WSZ_LIT("WC102-10some regular stringdeadbeef"));

	GPOS_ASSERT(ulpRead == (ULONG_PTR) strExpected.UlLength() * GPOS_SIZEOF(WCHAR));
	GPOS_ASSERT(strExpected.FEquals(&strExpected));
}
Пример #11
0
int Encode (CFileReader &p_coFileReader)
{
	int iRetVal = 0;
	XML_Parser psoParser;

	psoParser = XML_ParserCreate ("UTF-8");
	if (NULL == psoParser) {
		iRetVal = ENOMEM;
		return iRetVal;
	}

	SDoc soDoc;

	/* регистрация обработчика данных */
	XML_SetElementHandler (psoParser, StartElementHandler, EndElementHandler);
	XML_SetXmlDeclHandler (psoParser, XmlDeclHandler);
	XML_SetDoctypeDeclHandler (psoParser, StartDoctypeDeclHandler, EndDoctypeDeclHandler);
	XML_SetUserData (psoParser, &soDoc);

	/* парсинг данных */
	char mcBuf[256];
	int iDataLen;
	int iIsFinal = 0;
	do {
		iDataLen = sizeof (mcBuf);
		if (p_coFileReader.ReadData ((unsigned char*)mcBuf, iDataLen))
			iIsFinal = 1;
		XML_Parse (psoParser, mcBuf, iDataLen, iIsFinal);
		if (iIsFinal)
			break;
	} while (1);

	Tokenize (soDoc);

	if (psoParser) {
		XML_ParserFree (psoParser);
		psoParser = NULL;
	}

	return iRetVal;
}
TVerdict CSymmetricCipherObjectReuseStep::doTestStepL()
	{
	INFO_PRINTF1(_L("*** Symmetric Cipher - Object Reuse ***"));
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());
  	if (TestStepResult()==EPass)
		{
		
		//Assume failure, unless all is successful
		SetTestStepResult(EFail);
		
		TPtrC keyPath;
		TPtrC srcPath;
		TVariantPtrC algorithm;
		TVariantPtrC operationMode;
		TVariantPtrC paddingMode;
		
		if(	!GetStringFromConfig(ConfigSection(),KConfigEncryptKey, keyPath) ||
			!GetStringFromConfig(ConfigSection(),KConfigSourcePath, srcPath) || 
			!GetStringFromConfig(ConfigSection(),KConfigAlgorithmUid, algorithm) || 
			!GetStringFromConfig(ConfigSection(),KConfigOperationMode, operationMode) ||
			!GetStringFromConfig(ConfigSection(),KConfigPaddingMode, paddingMode ))
			{
			User::Leave(KErrNotFound);
			}
		else
			{
			
			//Create an instance of TKeyProperty
			TKeyProperty keyProperty;
			
			//Load the key data using the
			CFileReader* keyData = CFileReader::NewLC(keyPath);
			
			CCryptoParams* params = CCryptoParams::NewLC(); 
			params->AddL( *keyData, KSymmetricKeyParameterUid); 
			
			CKey* key=CKey::NewL(keyProperty, *params);
			CleanupStack::PushL(key);
			
			CCryptoParams* xparams = NULL;
			
			if (TUid(algorithm) == KArc4Uid)
				{
				//Set the RC4 DiscardBytes to 0
				xparams = CCryptoParams::NewL();
				xparams->AddL(NULL, KARC4DiscardBytes);
				CleanupStack::PushL(xparams);
				}

			if (TUid(algorithm) == KRc2Uid)
				{
				TInt keylen = TPtrC8(*keyData).Length() * 8;
				xparams = CCryptoParams::NewLC();
				
				//Set the RC2 EffectiveKeyLen according to the input key size
				xparams->AddL( keylen, KRC2EffectiveKeyLenBits);
				}
			
			INFO_PRINTF1(_L("Creating Symmetric Cipher Object..."));

			// Create a Symmetric Cipher with the values from the ini config file	
			CryptoSpi::CSymmetricCipher * impl = NULL;	
			TRAPD(err,CSymmetricCipherFactory::CreateSymmetricCipherL
										(
										impl,
										algorithm,
										*key,
										KCryptoModeEncryptUid,
										operationMode,
										paddingMode,
										xparams));
	
			if(impl && (err == KErrNone))
				{
				CleanupStack::PushL(impl);
				
				const TInt KObjectReuseItterations = 5; // 5 iterations should be enough to check the object reuse feature
														// the no of iteration is reduced, to reduce the time taken for execution
				
				//Boolean to denote the state				
				TBool testPass = ETrue;
				
				/*************** Encrypt/Decrypt Reuse Loop ****************/
				for(TInt index = 0; index < KObjectReuseItterations; index++)
					{
					INFO_PRINTF3(_L("i=%d : START HEAP CELLS: %d"),index, User::CountAllocCells());
					
					//-----RESET IMPLEMENTATION OBJECT (NORMAL LOGGING)----------
					
					impl->Reset();
					
					TRAP(err,impl->SetKeyL(*key));
					
					if(err != KErrNone)
						{
						ERR_PRINTF3(_L("*** ERROR:%d - SetKeyL() i=%d ***"),err,index);
						User::Leave(err);	
						}
						
					TRAP(err,impl->SetCryptoModeL(KCryptoModeEncryptUid));
					
					if(err != KErrNone)
						{
						ERR_PRINTF3(_L("*** ERROR:%d - SetCryptoModeL() i=%d ***"),err,index);
						User::Leave(err);	
						}
						
					if(TUid(algorithm) != KArc4Uid)
						{
						
						impl->SetOperationModeL(operationMode);
					
						if(err != KErrNone)
							{
							ERR_PRINTF3(_L("*** ERROR:%d - SetOperationModeL() i=%d ***"),err,index);
							User::Leave(err);	
							}
							
						TRAP(err,impl->SetPaddingModeL(paddingMode));
						
						if(err != KErrNone)
							{
							ERR_PRINTF3(_L("*** ERROR:%d - SetPaddingModeL() i=%d ***"),err,index);
							User::Leave(err);	
							}
								
						}

					//------------------------------------------------------
					
					//find out the block size for this algorithm
					TInt blockSize(0);
					
					if (TUid(operationMode) == KOperationModeCTRUid)
						{
						blockSize = CtrModeCalcBlockSizeL(*impl);
						}
					else
						{
						blockSize = impl->BlockSize();	
						}
					
					HBufC8* iv = NULL;
					
					if ((TUid(operationMode) == KOperationModeCBCUid) || (TUid(operationMode) == KOperationModeCTRUid))
						{
						// block size is in bits so to allocate the correct number of bytes divide by 8
						// iv is left on the cleanup stack for the duration of the test and deleted in a conditional at the end of the outer block.
						// If this conditional block changes, take care to update the condition for deleting this allocated IV, near the end of this function.
						iv = HBufC8::NewLC(blockSize/8);	
						
						// blocksize is in bits so to allocate the correct number of 8 byte chunks divide by 64
						for(TInt i = 0 ; i <blockSize/64 ; i++)
						{
							iv->Des().Append(_L8("12345678"));
						}
		
						TRAP_LOG(err,impl->SetIvL(iv->Des())); 
						}
					
					// convert to bytesize
					blockSize/=8;
					blockSize += iOffset;
					
					//read from src file
					CFileReader* srcData = CFileReader::NewLC(srcPath,blockSize);
					
					// first step is to read from the src file one block
					// at a time, encrypt that block and then write
					// the encrypted block out to a temporary file.
					CFileWriter* encryptedDataWriter = CFileWriter::NewLC(TPtrC(KTempEncryptedFilePath));
					
					TInt numBlocks = srcData->NumBlocks();
					
					INFO_PRINTF1(_L("Starting Incremental Encryption..."));
					
					for(TInt i = 1 ; i <= numBlocks ; i++)
						{
						TRAP_LOG(err,srcData->ReadBlockL());
					
						//Create buffer for encrypted data
						TInt maxOutputLength = impl->MaxFinalOutputLength(TPtrC8(*srcData).Length());
						HBufC8* encrypted =	HBufC8::NewLC(maxOutputLength);
						TPtr8 encryptedPtr = encrypted->Des();
					
						if(i == numBlocks)
							{
							TRAP(err,impl->ProcessFinalL(*srcData, encryptedPtr));
							
							if(err != KErrNone)
								{
								ERR_PRINTF3(_L("*** ERROR:%d - ProcessFinalL() Block=%d ***"),err,i);
								User::Leave(err);	
								}
							}
						else
							{
							TRAP(err,impl->ProcessL(*srcData, encryptedPtr));
							
							if(err != KErrNone)
								{
								ERR_PRINTF3(_L("*** ERROR:%d - ProcessL() Block=%d ***"),err,i);
								User::Leave(err);	
								}
							}	
						
						TRAP_LOG(err,encryptedDataWriter->WriteBlockL(encryptedPtr));
					
						CleanupStack::PopAndDestroy(encrypted); 
						}
						
					CleanupStack::PopAndDestroy(encryptedDataWriter); 
						
					//Switch to Decrypt Crypto Mode
					TRAP(err,impl->SetCryptoModeL(KCryptoModeDecryptUid));
					
					if(err != KErrNone)
						{
						ERR_PRINTF3(_L("*** ERROR:%d - SetCryptoModeL() i=%d ***"),err,index);
						User::Leave(err);	
						}

					//If in CTR mode need to reset the keystream to the start of the sequence used for encryption.
					if(TUid(operationMode) == KOperationModeCTRUid)
						{
						impl->SetIvL(iv->Des());
						}

					
					// the next step is to read the previously encrypted data
					// from the temporary file decrypting this one block
					// at a time and outputing this to a temporary file.
					CFileReader* encryptedDataReader = CFileReader::NewLC(TPtrC(KTempEncryptedFilePath),blockSize);
					CFileWriter* decryptedDataWriter = CFileWriter::NewLC(TPtrC(KTempDecryptedFilePath));
					
					numBlocks = encryptedDataReader->NumBlocks();
					
					INFO_PRINTF1(_L("Starting Incremental Decryption..."));
					
					for(TInt i = 1 ; i <= numBlocks ; i++)
						{
						encryptedDataReader->ReadBlockL();
						//Create buffer for encrypted data
						TInt maxOutputLength = impl->MaxFinalOutputLength(TPtrC8(*encryptedDataReader).Length());
						HBufC8* decrypted =	HBufC8::NewLC(maxOutputLength);
						TPtr8 decryptedPtr = decrypted->Des();

						//Perform the decryption operation
						if(i == numBlocks)
							{
							TRAP(err,impl->ProcessFinalL(*encryptedDataReader, decryptedPtr));
							
							if(err != KErrNone)
								{
								ERR_PRINTF3(_L("*** ERROR:%d - ProcessFinalL() Block=%d ***"),err,i);
								User::Leave(err);	
								}
							}
						else
							{
							TRAP(err,impl->ProcessL(*encryptedDataReader, decryptedPtr));
							
							if(err != KErrNone)
								{
								ERR_PRINTF3(_L("*** ERROR:%d - ProcessL() Block=%d ***"),err,i);
								User::Leave(err);	
								}
							}
							
						TRAP_LOG(err,decryptedDataWriter->WriteBlockL(decryptedPtr));
					
						CleanupStack::PopAndDestroy(decrypted); 
						}
						
					CleanupStack::PopAndDestroy(decryptedDataWriter); 
					CleanupStack::PopAndDestroy(encryptedDataReader); 
					CleanupStack::PopAndDestroy(srcData);
					
					if((TUid(operationMode) == KOperationModeCBCUid) || (TUid(operationMode) == KOperationModeCTRUid))
						{
						// Iv is left on the cleanupstack at creation.  
						// If it becomes possible for operationMode to be modified during
						// the test this needs to be re-engineered.
						CleanupStack::PopAndDestroy(iv);
						}
					
					
					// compare the src with the file thats been
					// encrypted then decrypted
					// Note: Returning 0 means that the files match
					if(!TFileCompare::CompareL(srcPath,TPtrC(KTempDecryptedFilePath)))
						{
						INFO_PRINTF2(_L("*** PASS = Source File and Decrypted Data Match - i=%d ***"),index);
						}
					else
						{
						testPass = EFalse;
						ERR_PRINTF2(_L("*** ERROR: Source File and Decrypted Data Mismatch - i=%d ***"),index);
						}
						
					RFs rFs;
					rFs.Connect();
					rFs.Delete(	KTempDecryptedFilePath );
					rFs.Delete(	KTempEncryptedFilePath );
					rFs.Close();
										
					INFO_PRINTF3(_L("*** i=%d : END HEAP CELLS: %d ***"),index, User::CountAllocCells());
					}
					
				/*************** END OF LOOP ****************/
					
				CleanupStack::PopAndDestroy(impl);
				
				if(testPass == EFalse)
					{
					ERR_PRINTF1(_L("*** TEST FAIL : Symmetric Cipher - Object Reuse ***"));
					}
				else
					{
					INFO_PRINTF1(_L("*** TEST PASS : Symmetric Cipher - Object Reuse ***"));
					SetTestStepResult(EPass);	
					}
				
				}
			else
				{
				ERR_PRINTF2(_L("*** FAIL: Failed to Create Symmetric Object - %d ***"), err);
				User::Leave(err);	
				}
								
			if (TUid(algorithm) == KArc4Uid || TUid(algorithm) == KRc2Uid)
				{
				CleanupStack::PopAndDestroy(xparams);				
				}
				
			CleanupStack::PopAndDestroy(key);
			CleanupStack::PopAndDestroy(params);
			CleanupStack::PopAndDestroy(keyData);
			}
		}
	INFO_PRINTF2(_L("HEAP CELLS: %d"), User::CountAllocCells());

	return TestStepResult();

	}
Пример #13
0
LRESULT CMainFrame::OnReadGroup( WPARAM wParam, LPARAM lParam )
{
	int nGroupCount = 0;
	CUserDatas* lpUserDatas = ((CIFuzzMakerDoc*)GetActiveDocument())->GetUserDatas();

	lpUserDatas->GetPatternGroupDataArray().RemoveAllWithDelete();

	CPatternGroupInfoLoader PatternGroupInfoLoader;
	CPatternGroupInfoArray PatternGroupInfoArray;
	if( !PatternGroupInfoLoader.LoadText( lpUserDatas->GetGroupFileName(), &PatternGroupInfoArray ) )
		return FALSE;

	for( nGroupCount=0; nGroupCount<PatternGroupInfoArray.GetSize(); nGroupCount++ )
	{
		CPatternGroupInfo *lpPatternGroupInfo = PatternGroupInfoArray.GetAt( nGroupCount );
		CPatternInfoLoader PatternInfoLoader;
		if( !PatternInfoLoader.LoadText( lpPatternGroupInfo->GetFileName(), lpPatternGroupInfo->GetPatternInfoArray() ) )
		{
		}
	}

	for( nGroupCount=0; nGroupCount<PatternGroupInfoArray.GetSize(); nGroupCount++ )
	{
		CPatternGroupInfo *lpPatternGroupInfo = PatternGroupInfoArray.GetAt( nGroupCount );
		if( lpPatternGroupInfo->GetDispFlag() )
		{
			CPatternGroupData* lpPatternGroupData = NULL;
			lpUserDatas->GetPatternGroupDataArray().AddWithNew( lpPatternGroupData );
			lpPatternGroupData->SetDispName( lpPatternGroupInfo->GetDispName() );

			for(int nPatternInfoCnt=0; nPatternInfoCnt<lpPatternGroupInfo->GetPatternInfoArray()->GetSize(); nPatternInfoCnt++ )
			{
				CPatternInfo* lpPatternInfo = lpPatternGroupInfo->GetPatternInfoArray()->GetAt(nPatternInfoCnt);
				CPatternData* lpPatternData = NULL;
				CReadBufferArray BinaryDataArray;

				CStringA szValue = CT2A(lpPatternInfo->GetValue());
				BYTE nDecValueByte = 0;
				unsigned short nDecValueShort = 0;
				unsigned int nDecValueInteger = 0;
				unsigned char* lpBuffer = NULL;

				if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_TEXT )
				{
					//
					BinaryDataArray.SetSize( szValue.GetLength() * (!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()) );
					lpBuffer = BinaryDataArray.GetData();
					for( int nRepeat=0; nRepeat<(!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()); nRepeat++ )
					{
						CopyMemory( &lpBuffer[nRepeat*szValue.GetLength()], szValue.GetBuffer(), szValue.GetLength() );
					}
				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_DEC_8 )
				{
					nDecValueByte = (BYTE)strtoul( szValue, NULL, 10 );
					BinaryDataArray.SetSize( sizeof(nDecValueByte) * (!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()) );
					lpBuffer = BinaryDataArray.GetData();
					for( int nRepeat=0; nRepeat<(!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()); nRepeat++ )
					{
						CopyMemory( &lpBuffer[nRepeat*sizeof(nDecValueByte)], &nDecValueByte, sizeof(nDecValueByte) );
					}
				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_DEC_16_LITTLE )
				{
					nDecValueShort = (unsigned short)strtoul( szValue, NULL, 10 );
					nDecValueShort = CEndianConverter::ConvertToShort( (unsigned char*)&nDecValueShort, FALSE );
					BinaryDataArray.SetSize( sizeof(nDecValueShort) * (!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()) );
					lpBuffer = BinaryDataArray.GetData();
					for( int nRepeat=0; nRepeat<(!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()); nRepeat++ )
					{
						CopyMemory( &lpBuffer[nRepeat*sizeof(nDecValueShort)], &nDecValueShort, sizeof(nDecValueShort) );
					}
				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_DEC_16_BIG )
				{
					nDecValueShort = (unsigned short)strtoul( szValue, NULL, 10 );
					nDecValueShort = CEndianConverter::ConvertToShort( (unsigned char*)&nDecValueShort, TRUE );
					BinaryDataArray.SetSize( sizeof(nDecValueShort) * (!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()) );
					lpBuffer = BinaryDataArray.GetData();
					for( int nRepeat=0; nRepeat<(!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()); nRepeat++ )
					{
						CopyMemory( &lpBuffer[nRepeat*sizeof(nDecValueShort)], &nDecValueShort, sizeof(nDecValueShort) );
					}

				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_DEC_32_LITTLE )
				{
					nDecValueInteger = (unsigned int)strtoul( szValue, NULL, 10 );
					nDecValueInteger = CEndianConverter::ConvertToInteger( (unsigned char*)&nDecValueInteger, FALSE );
					BinaryDataArray.SetSize( sizeof(nDecValueInteger) * (!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()) );
					lpBuffer = BinaryDataArray.GetData();
					for( int nRepeat=0; nRepeat<(!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()); nRepeat++ )
					{
						CopyMemory( &lpBuffer[nRepeat*sizeof(nDecValueInteger)], &nDecValueInteger, sizeof(nDecValueInteger) );
					}
				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_DEC_32_BIG )
				{
					nDecValueInteger = (unsigned int)strtoul( szValue, NULL, 10 );
					nDecValueInteger = CEndianConverter::ConvertToInteger( (unsigned char*)&nDecValueInteger, TRUE );
					BinaryDataArray.SetSize( sizeof(nDecValueInteger) * (!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()) );
					lpBuffer = BinaryDataArray.GetData();
					for( int nRepeat=0; nRepeat<(!lpPatternInfo->GetRepeat()?1:lpPatternInfo->GetRepeat()); nRepeat++ )
					{
						CopyMemory( &lpBuffer[nRepeat*sizeof(nDecValueInteger)], &nDecValueInteger, sizeof(nDecValueInteger) );
					}
				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_HEX )
				{
					//
					BinaryDataArray.SetSize( (int)(szValue.GetLength()/2) );
					for( int cCnt=0; cCnt<(int)(szValue.GetLength()/2); cCnt++ )
					{
						unsigned int nVal = strtol( szValue.Mid( cCnt*2, 2 ),NULL,16 );
						BinaryDataArray.SetAt(cCnt, nVal);
					}
				}else if( lpPatternInfo->GetDataType() == CPatternData::DATATYPE_BIN )
				{
					//
					CFileReader fl;
					if( !fl.ReadFile( lpPatternInfo->GetFileName(), BinaryDataArray ) )
						continue;
				}
				lpPatternGroupData->GetPatternDataArray()->AddWithNew( lpPatternData );

				lpPatternData->SetCheck( lpPatternInfo->GetSelectFlag() );
				lpPatternData->SetDispName( lpPatternInfo->GetDispName() );
				lpPatternData->SetDataType( lpPatternInfo->GetDataType() );
				lpPatternData->SetValue( lpPatternInfo->GetValue() );
				lpPatternData->SetRepeat( lpPatternInfo->GetRepeat() );
				lpPatternData->SetWriteMode( lpPatternInfo->GetWriteMode() );
				lpPatternData->SetFuzzArea( lpPatternInfo->GetFuzzArea() );
				lpPatternData->SetSearchField( lpPatternInfo->GetSearchField() );
				lpPatternData->SetFieldKey( lpPatternInfo->GetFieldKey() );
				lpPatternData->SetDescription( lpPatternInfo->GetDescription() );
				lpPatternData->SetBinaryDataArray( BinaryDataArray );

				if( lpPatternInfo->GetFuzzArea() == CPatternData::FUZZAREA_FILE )
				{
					TCHAR* endptr = NULL;
					int nFilePos = _tcstol( lpPatternInfo->GetFieldKey(), &endptr, 10 );
					if( _tcslen(endptr) )
						continue;
					lpPatternData->SetFilePos( nFilePos );
				}

				if( lpPatternData->GetSearchField() == CPatternData::SEARCHFIELD_TAG ||
					lpPatternData->GetSearchField() == CPatternData::SEARCHFIELD_TYPE ||
					lpPatternData->GetSearchField() == CPatternData::SEARCHFIELD_SEGMENT )
				{
					POSITION pos = NULL;
					CString szKey;
					CImageFileDirectoryInfo *lpImageFileDirectoryInfo = NULL;
					CFealdEntryInfo* lpFealdEntryInfo = NULL;
					CSegmentItemInfo* lpSegmentItemInfo = NULL;
					CTagTypeInfo* lpTagTypeInfo = NULL;
					int nFieldKey = 0;

					switch(lpPatternData->GetSearchField())
					{
					case CPatternData::SEARCHFIELD_TAG:
						pos = m_FixedDatas.GetImageFileDirectoryInfoMap().GetStartPosition();
						while(pos)
						{
							m_FixedDatas.GetImageFileDirectoryInfoMap().GetNextAssoc( pos, szKey, lpImageFileDirectoryInfo );
							if( lpImageFileDirectoryInfo->GetFealdEntryInfoMap()->Lookup( lpPatternData->GetFieldKey(), lpFealdEntryInfo ) )
								break;
						}
						break;
					case CPatternData::SEARCHFIELD_TYPE:
						nFieldKey = _tstol(lpPatternData->GetFieldKey());
						m_FixedDatas.GetTagTypeInfoMap().Lookup( nFieldKey, lpTagTypeInfo );
						break;
					case CPatternData::SEARCHFIELD_SEGMENT:
						m_FixedDatas.GetSegmentItemInfoMap().Lookup( lpPatternData->GetFieldKey(), lpSegmentItemInfo );
						break;
					}
					lpPatternData->SetFealdEntryInfo( lpFealdEntryInfo );
					lpPatternData->SetTagTypeInfo( lpTagTypeInfo );
					lpPatternData->SetSegmentItemInfo( lpSegmentItemInfo );
				}
			}
		}
	}

	SendMessageToDescendants( WM_APP_GROUP_DISP, NULL, NULL );

	return TRUE;
}
Пример #14
0
/************************************************************************************************
  WinMain (...)
************************************************************************************************/
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	// Always perform a leak check just before app exits.
	int nDbgFlags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	nDbgFlags |= _CRTDBG_LEAK_CHECK_DF;
	_CrtSetDbgFlag(nDbgFlags);

  //instantiate log object and log
  CLog *pLog = CLog::Instance();
  pLog->Log("*********************************************************");
  pLog->Log("Program starting..................");
  pLog->SetDelimiter(':');
  pLog->LogDate();
  pLog->LogTime();
  pLog->Log("************************ *********************************");


  pLog->Log ("***********************************************");
  pLog->Log("Game Challenge 6");
  pLog->LogDate();
  pLog->LogTime();
  pLog->Log("***********************************************");

  Graphics g_con;  
  CAudioManager *pAudio = CAudioManager::Instance();

  //***********************************************************************
  //read config.ini file
  // C O N F I G . I N I
  //***********************************************************************
  pLog->Log("************ Config.ini ************");
  CINIReader config;          //reads and stores INI file data
  config.LoadFile("config.ini");
  std::string sValue;
  std::string sParameter;
  int nParameterValue;

  //default values
  g_Global.g_screenWidth = 1024;
  g_Global.g_screenHeight = 768;

  if(config.IsValid() == true){
    pLog->Log("Valid config.ini file");
    pLog->Log("Numbers of lines in config file",config.GetNumberOfLines());

    for(int j=0; j< config.GetNumberOfLines();j++){
      sParameter = config.GetTerm(config.GetLineFromFile(j),1);
      sValue = config.GetTerm(config.GetLineFromFile(j),2);
      nParameterValue =  atoi(sValue.c_str());

      pLog->Log(sParameter, nParameterValue);      
      
      //load g_Global object with config.ini data
      if(sParameter == "WindowedMode" && nParameterValue == 1)
        g_Global.g_WindowedMode = true;
      else if(sParameter == "WindowedMode" && nParameterValue == 0)
        g_Global.g_WindowedMode = false;
      //else if(sParameter == "ScreenWidth" && nParameterValue > 0)
      //  g_Global.g_screenWidth = nParameterValue;
      //else if(sParameter == "ScreenHeight" && nParameterValue > 0)
      //  g_Global.g_screenHeight = nParameterValue;
      //else if(sParameter == "GameLevel" && nParameterValue > 0 && nParameterValue < 6)
      //  g_Global.g_GameLevel = nParameterValue;
      //else if(sParameter == "GameSnow" && nParameterValue == 1)
      //  g_Global.g_bGameSnow = true;
      //else if(sParameter == "GameSnow" && nParameterValue == 0)
      //  g_Global.g_bGameSnow = false;
      else if(sParameter == "GameAudio" && nParameterValue == 1)
        g_Global.g_bGameAudio = true;
      else if(sParameter == "GameAudio" && nParameterValue == 0)
        g_Global.g_bGameAudio = false;
      else if(sParameter == "FrameRate" && nParameterValue == 1)
        g_Global.g_bDisplayFramerate = true;
      else if(sParameter == "FrameRate" && nParameterValue == 0)
        g_Global.g_bDisplayFramerate = false;
    }
  } 
  pLog->Log("Reading Config.ini file is complete!");
	// Break on specific memory allocation number
	//_CrtSetBreakAlloc(175);
  
  MSG msg;    
  g_bRunning = true;//Start program running

  //Make a window and initialize DirectX in windowed mode
  MakeWindow(hInstance, g_Global.g_WindowedMode, g_con);

  //map game state information
  g_pStateIntro->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStateMain->addTransitionEvent(EVENT_GO_HISTORY, g_pStateHistory);
  g_pStateMain->addTransitionEvent(EVENT_GO_RELOAD, g_pStateReload);
  g_pStateMain->addTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits);
  g_pStateMain->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStateHistory->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStateReload->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStateCredits->addTransitionEvent(EVENT_GO_END, g_pStateEnd);
  g_pStateSelect->addTransitionEvent(EVENT_GO_AWARDS, g_pStateAwards);
  g_pStateAwards->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);  
  g_pStateSelect->addTransitionEvent(EVENT_GO_PLAY, g_pStatePlay);
  g_pStateSelect->addTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
  g_pStatePlay->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStatePlay->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);
  g_pStateWin->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStateLose->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStatePlay->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStatePlay->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);
  
  //sonar transitions
  g_pStateSonar->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateSonar->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateSonar->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateSonar->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateSonar->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //radar transitions
  g_pStateRadar->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateRadar->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateRadar->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateRadar->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateRadar->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //scope transitions
  g_pStateScope->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);
  g_pStateScope->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStateScope->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);
  
  //conn transitions
  g_pStateControl->addTransitionEvent(EVENT_GO_PLAY, g_pStatePlay);
  g_pStateControl->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateControl->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateControl->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateControl->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateControl->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateControl->addTransitionEvent(EVENT_GO_SCOPE, g_pStateScope);
  g_pStateControl->addTransitionEvent(EVENT_GO_SELECT, g_pStateSelect);
  g_pStateControl->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStateControl->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);

  //fire control transitions
  g_pStateFireControl->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateFireControl->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateFireControl->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateFireControl->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateFireControl->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //status transitions
  g_pStateStatus->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateStatus->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateStatus->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateStatus->addTransitionEvent(EVENT_GO_CHART, g_pStateChart);  
  g_pStateStatus->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);

  //chart transitions
  g_pStateChart->addTransitionEvent(EVENT_GO_SONAR, g_pStateSonar);
  g_pStateChart->addTransitionEvent(EVENT_GO_RADAR, g_pStateRadar);
  g_pStateChart->addTransitionEvent(EVENT_GO_FIRECONTROL, g_pStateFireControl);
  g_pStateChart->addTransitionEvent(EVENT_GO_STATUS, g_pStateStatus);
  g_pStateChart->addTransitionEvent(EVENT_GO_CONTROL, g_pStateControl);
  g_pStateChart->addTransitionEvent(EVENT_GO_WIN, g_pStateWin);
  g_pStateChart->addTransitionEvent(EVENT_GO_LOSE, g_pStateLose);

  g_Timer.initialize();
  g_LoopTimer.initialize();
  g_FPS_Timer.initialize();
  g_con.InitD3D (g_hWnd, g_Global.g_WindowedMode);

  //***********************************************************************
  //load textures from graphics file
  // G R A P H I C F I L E S . D A T
  //***********************************************************************
  pLog->Log("************ Graphicfiles.dat ************");
  CFileReader* cfr = new CFileReader;
  cfr->LoadFile("data\\graphicfiles.dat");
  int fileNumber;
  std::string fileName;
  if(cfr->IsValid()== true){
    pLog->Log("Numbers of lines in file",cfr->GetNumberOfLines());
    for(int j=0; j< cfr->GetNumberOfLines();j++){
      sValue =cfr->GetTerm(cfr->GetLineFromFile(j),1);
      fileNumber = atoi(sValue.c_str());
      sValue = cfr->GetTerm(cfr->GetLineFromFile(j),2);
      fileName = "assets\\artwork\\";
      fileName = fileName + sValue;
      //pLog->Log("Loaded file",fileName);
      pLog->Log(fileName, fileNumber);
      g_con.LoadTexture(fileName, fileNumber);
    }
  } 
  else{
    pLog->Log("ERROR****************** Failure to load textures (graphicfiles.dat)");
    delete cfr;
    g_con.CloseD3D();
    pLog->Log("DirectX closed!");
    Shutdown();
    return 0;
  }

  if(g_Sprite.LoadSprites() == true){
    pLog->Log("Sprites loaded!");
  }
  else{
    pLog->Log("ERROR****************** Failure to sprite data (sprites.dat)");
  }

  //used for framerate display
  std::ostringstream oss;
  std::string sFramerate;
  std::string sText;
  int nDisplayFPSCount = 0;

  //initialize audio manager
  //***************************************************************
  if(g_Global.g_bGameAudio == true){
    pLog->Log("Loading audio clip...");
    if(pAudio->IsValidSound())
      pLog->Log("Audio system is okay!");
    else
      pLog->Log("Audio system failure!");
    
    //load sounds
    pAudio->LoadSample(SOUND_BEEP, "assets\\sounds\\beep-03.wav");
    pAudio->LoadSample(SOUND_REMEMBER, "assets\\sounds\\remember.mp3");
    pAudio->LoadSample(SOUND_HYMN, "assets\\sounds\\navy_hymn.mp3");
    pAudio->LoadSample(SOUND_PERISCOPE, "assets\\sounds\\periscop.wav");
    pAudio->LoadSample(SOUND_BUTTON_CLICK, "assets\\sounds\\button_click.wav");
    pAudio->LoadSample(SOUND_DEPTH_CHARGE1,"assets\\sounds\\dc1.mp3");
    pAudio->LoadSample(SOUND_DEPTH_CHARGE2,"assets\\sounds\\dc2.mp3");
    pAudio->LoadSample(SOUND_TORPEDO1,"assets\\sounds\\torpedo3.mp3");
    pAudio->LoadSample(SOUND_TORPEDO2,"assets\\sounds\\torpedo4.mp3");
    pAudio->LoadSample(SOUND_AMBIENCE1,"assets\\sounds\\ambience1.mp3");
    pAudio->LoadSample(SOUND_CLEAR_BRIDGE,"assets\\sounds\\clear_bridge.wav");
    pAudio->LoadSample(SOUND_DIVING,"assets\\sounds\\diving.mp3");
    pAudio->LoadSample(SOUND_GQ,"assets\\sounds\\general_quarters.wav");
    pAudio->LoadSample(SOUND_ANCHORS,"assets\\sounds\\AnchorsAway.mp3");
    pAudio->LoadSample(SOUND_TAPS,"assets\\sounds\\Taps.mp3");
    pAudio->LoadSample(SOUND_SINKING,"assets\\sounds\\sinking2.mp3");
    pAudio->LoadSample(SOUND_ANTHEM,"assets\\sounds\\USA.mp3");
    pAudio->LoadSample(SOUND_FUNERAL,"assets\\sounds\\fnrlMrch.wav");
    pAudio->LoadSample(SOUND_PING,"assets\\sounds\\sonar1.mp3");
    
    //load stream
    pAudio->LoadStream(SOUND_BIO, "assets\\sounds\\fish.mp3");
    pAudio->AddStreamClip(SOUND_BIO1, SOUND_BIO, 0, 17708);
    pAudio->AddStreamClip(SOUND_BIO2, SOUND_BIO, 17708, 26434);
    pAudio->AddStreamClip(SOUND_BIO3, SOUND_BIO, 26434, 42859);
    pAudio->AddStreamClip(SOUND_BIO4, SOUND_BIO, 42859, 59541);
    pAudio->AddStreamClip(SOUND_BIO5, SOUND_BIO, 59541, 80073);

    for(int i = 0; i < pAudio->Size(); i++){
      pLog->Log(pAudio->GetFilename(i), i); //write filename and file index to log file
    }
  }
  else{
    pLog->Log("Audio disabled");
  }

  pLog->Log("Main game loop entered!");
  ::ShowCursor(false); 
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Version Number
  g_strFPS = "Game Challenge 6 (Chuck Bolin) - \"Sinking of the Rising Sun\", v0.047 Final Version";
  ::SetWindowText(g_hWnd, g_strFPS.c_str());
  double timeDelta;

  g_con.InitializePyro();

  //Main application loop
  //*******************************************************
  while (g_bRunning)
  {
    //Handle messages
    if (PeekMessage (&msg,NULL,0,0,PM_REMOVE)){
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }        
    else{}
      timeDelta = g_LoopTimer.getTimeDifference();
      g_pNext = g_pCurrent->update(timeDelta);
      if(g_pNext == g_pStateEnd)
        g_bRunning = false;
      else if(NULL != g_pNext)
	    {
        g_pCurrent->deactivate();
        g_pCurrent = g_pNext;
        g_pCurrent->activate();
      }
     
	  // Render our current game object
    g_pCurrent->render(g_con);

    //call each second update FPS
    nDisplayFPSCount++;
    if(g_FPS_Timer.getTimer(1)){
      //g_FPS_Counter++;
      oss.str(""); //clear oss
      oss << (int) nDisplayFPSCount;
      //if(g_FPS_Counter > 60){  //call every 60 seconds
      //  pLog->Log("FPS",oss.str());
      //  g_FPS_Counter == 0;
      //}

  	  // update our FPS string.
	    // This thing can be rendered inside any of the game objects.
      g_strFPS = "FPS " + oss.str();
      g_Global.g_strFPS = "FPS " + oss.str();

      nDisplayFPSCount=0;//reset frame count
    }
  }//while(...
  g_con.ClosePyro();
  g_con.CloseD3D();
  pLog->Log("DirectX closed!");
  Shutdown();

  return 0;//(int)msg.wParam;  //returns exit code to operating system
}