Example #1
0
//---------------------------------------------------------------------------
//	@function:
//		CIOUtils::Dump
//
//	@doc:
//		Dump given string to output file
//
//---------------------------------------------------------------------------
void
CIOUtils::Dump
	(
	CHAR *file_name,
	CHAR *sz
	)
{
	CAutoSuspendAbort asa;

	const ULONG ulWrPerms = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;

	GPOS_TRY
	{
		CFileWriter fw;
		fw.Open(file_name, ulWrPerms);
		const BYTE *pb = reinterpret_cast<const BYTE*>(sz);
		ULONG_PTR ulpLength = (ULONG_PTR) clib::Strlen(sz);
		fw.Write(pb, ulpLength);
		fw.Close();
	}
	GPOS_CATCH_EX(ex)
	{
		// ignore exceptions during dumping
		GPOS_RESET_EX;
	}
	GPOS_CATCH_END;

	// reset time slice
#ifdef GPOS_DEBUG
    CWorker::Self()->ResetTimeSlice();
#endif // GPOS_DEBUG
}
/*
 * TestUnlockResourcesL: Test that the CloseOutputPlugin method ???
 *
 * Expected Verdict: PASS/FAIL/PANIC
 *
 * Prerequisites:
 *
 * Description: Retrieve and print some data from an external ini data file
 *
 */
void CFile0Step::TestUnlockResourcesL()
	{
	CFileWriter* fileWriter = CFileWriter::NewL();
	INFO_PRINTF1(_L("Invoking CFileWriter::CloseOutputPlugin(). CloseOutputPlugin() is supposed to do nothing."));
	fileWriter->CloseOutputPlugin();
	ASSERT_TRUE(ETrue);
	delete fileWriter;
	}
/*
 * TestSettingsL: Test that the Settings method ???
 *
 * Expected Verdict: PASS/FAIL/PANIC
 *
 * Prerequisites:
 *
 * Description: Retrieve and print some data from an external ini data file
 *
 */
void CFile0Step::TestSettingsL()
	{
	CFileWriter* fileWriter = CFileWriter::NewL();
	INFO_PRINTF1(_L("Passing empty RPointerArray to CFileWriter::ConfigureOutputPlugin()"));
	RPointerArray<TPluginConfiguration> emptyPointerArray;
	fileWriter->ConfigureOutputPlugin(emptyPointerArray);

	delete fileWriter;
	}
Example #4
0
Holly::IWriter* CHolly::CreateFileWriter( const std::string& strFileName )
{
	CFileWriter* pWriter = new CFileWriter();
	if ( !pWriter->Open( strFileName ) )
	{
		pWriter->Delete();
		return NULL;
	}

	return pWriter;
}
// The implementation for this is not working correctly! Check this
void CFile0Step::TestWriteL()
	{
	INFO_PRINTF1(_L("Checking that CFileWriter::Write(const TDesC8&) writes a String correctly to C:\\logs\\log.txt"));

	// Create new CFileWriter instance
	CFileWriter* fileWriter = CFileWriter::NewL();
	_LIT8(KTxt, "Test");
	INFO_PRINTF1(_L("Writing 'Test' to the log using CFileWriter::Write()"));
	ASSERT_EQUALS(KErrNone, fileWriter->Write(KTxt));

	delete fileWriter;
	}
Example #6
0
Datum
DumpQueryToFile(PG_FUNCTION_ARGS)
{
	char *szSql = textToString(PG_GETARG_TEXT_P(0));
	char *szFilename = textToString(PG_GETARG_TEXT_P(1));

	size_t iQueryStringLen = -1;
	char *pcQuery = getQueryBinary(szSql, &iQueryStringLen);

	CFileWriter fw;
	fw.Open(szFilename, S_IRUSR | S_IWUSR);
	fw.Write(reinterpret_cast<const BYTE*>(&iQueryStringLen), sizeof(iQueryStringLen));
	fw.Write(reinterpret_cast<const BYTE*>(pcQuery), iQueryStringLen);
	fw.Close();

	PG_RETURN_UINT32( (ULONG) iQueryStringLen);
}
Example #7
0
Datum
DumpPlanToFile(PG_FUNCTION_ARGS)
{
	char *szSql = text_to_cstring(PG_GETARG_TEXT_P(0));
	char *szFilename = text_to_cstring(PG_GETARG_TEXT_P(1));

	size_t iBinaryLen = -1;
	char *pcBinary = getPlannedStmtBinary(szSql, &iBinaryLen);

	CFileWriter fw;
	fw.Open(szFilename, S_IRUSR | S_IWUSR);
	fw.Write(reinterpret_cast<const BYTE*>(&iBinaryLen), sizeof(iBinaryLen));
	fw.Write(reinterpret_cast<const BYTE*>(pcBinary), iBinaryLen);
	fw.Close();

	PG_RETURN_UINT32((ULONG) iBinaryLen);
}
Example #8
0
static int translateQueryToFile
	(
	char *szSqlText,
	char *szFilename
	)
{
	Query *pquery = parseSQL(szSqlText);

	Assert(pquery);

	char *szXmlString = COptTasks::SzDXL(pquery);
	int iLen = (int) gpos::clib::UlStrLen(szXmlString);

	CFileWriter fw;
	fw.Open(szFilename, S_IRUSR | S_IWUSR);
	fw.Write(reinterpret_cast<const BYTE*>(szXmlString), iLen + 1);
	fw.Close();

	return iLen;
}
Example #9
0
Datum
DumpPlanToDXLFile(PG_FUNCTION_ARGS)
{
	char *szSql = textToString(PG_GETARG_TEXT_P(0));
	char *szFilename = textToString(PG_GETARG_TEXT_P(1));

	PlannedStmt *pplstmt = planQuery(szSql);
	Assert(pplstmt);

	char *szXmlString = COptTasks::SzDXL(pplstmt);

	int iLen = (int) gpos::clib::UlStrLen(szXmlString);

	CFileWriter fw;
	fw.Open(szFilename, S_IRUSR | S_IWUSR);
	fw.Write(reinterpret_cast<const BYTE*>(szXmlString), iLen + 1);
	fw.Close();

	PG_RETURN_INT32(iLen);

}
Example #10
0
void CShowOneDescriptionDlg::OnButton(wxCommandEvent& event)
{
    if (event.GetId()==wxID_OK)
    {
        int         err;
        wxString CurrentDir = wxGetCwd();
        if (!m_descr)
            return;
        wxFileDialog dialog(GetParent(),
                            wxT("Save current text"),
                            wxT(""),
                            wxT(""),
                            wxT(SZ_ALL_FILES),
                            wxFD_SAVE |  wxFD_OVERWRITE_PROMPT );
        err = dialog.ShowModal();
        wxSetWorkingDirectory(CurrentDir);

        if (wxID_OK == err)
        {
            CFileWriter F;
            if (F.Open(dialog.GetPath().mb_str()))
            {
                F.WriteBuf(m_descr, strlen(m_descr));

                F.Close();
            }
            else
                wxMessageBox(wxT("Can not open file"));

        }

    }
    else if (event.GetId()==wxID_CANCEL)
    {
        StoreSize();
        EndModal(wxID_CANCEL);
    }
}
Example #11
0
void Tokenize (SDoc &p_soDoc)
{
	int iFnRes;
	CFileWriter coFileWriter;

	iFnRes = coFileWriter.Init ();
	if (iFnRes)
		return;
	iFnRes = coFileWriter.CreateOutputFile ("out.wbxml");
	if (iFnRes)
		return;

	/* формируем версию */
	p_soDoc.m_strBinHedr.append ((unsigned char*)&p_soDoc.m_soHdr.m_soVersion, sizeof (p_soDoc.m_soHdr.m_soVersion));
	/* формируем public_id */
	p_soDoc.m_strBinHedr.append ((unsigned char*)&p_soDoc.m_soHdr.m_soPublicId, sizeof (p_soDoc.m_soHdr.m_soPublicId));
	/* формируем charset */
	p_soDoc.m_strBinHedr.append ((unsigned char*)&p_soDoc.m_soHdr.m_soCharSet, sizeof (p_soDoc.m_soHdr.m_soCharSet));
	/* формируем body */
	u_int8 ui8CodePage = 0;
	TokenizeBody (p_soDoc.m_psoBodyFirst, p_soDoc.m_strBinBody, p_soDoc);
	/* формируем strtbl */
	std::string strStrTbl;
	for (unsigned int i = 0; i < p_soDoc.m_soHdr.m_vectStrTbl.size (); i++) {
		strStrTbl.append (p_soDoc.m_soHdr.m_vectStrTbl[i].data (), p_soDoc.m_soHdr.m_vectStrTbl[i].length () + 1);
	}
	std::basic_string<mb_u_int32> strStrLen;
	LongLong_toub_u_int32 (strStrTbl.length (), strStrLen);
	p_soDoc.m_strBinHedr.append ((unsigned char*)strStrLen.data (), strStrLen.length());
	if (strStrTbl.length ())
		p_soDoc.m_strBinHedr.append ((unsigned char*)strStrTbl.data (), strStrTbl.length ());

	coFileWriter.WriteData (p_soDoc.m_strBinHedr.data (), p_soDoc.m_strBinHedr.size ());
	coFileWriter.WriteData (p_soDoc.m_strBinBody.data (), p_soDoc.m_strBinBody.size ());

	coFileWriter.Finalise ();
}
Example #12
0
void CShowDescriptionListDlg::SaveAs()
{
    int            err, i;
    CBaseObject  * pObj;
    CStr           S(128);

    wxString CurrentDir = wxGetCwd();
    wxFileDialog dialog(GetParent(),
                        wxT("Save current text"),
                        wxT(""),
                        wxT(""),
                        wxT(SZ_ALL_FILES),
                        wxFD_SAVE |  wxFD_OVERWRITE_PROMPT );
    err = dialog.ShowModal();
    wxSetWorkingDirectory(CurrentDir);

    if (wxID_OK == err)
    {
        CFileWriter F;
        if (F.Open(dialog.GetPath().mb_str()))
        {
            for (i=0; i<m_pItems->Count(); i++)
            {
                pObj = (CBaseObject*)m_pItems->At(i);
                S    = pObj->Description;
                S.TrimRight(TRIM_ALL);
                S << EOL_FILE;
                F.WriteBuf(S.GetData(), S.GetLength());
            }
            F.Close();
        }
        else
            wxMessageBox(wxT("Can not open file"));

    }

}
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();

	}
Example #14
0
RCType
TraceGen::generate(J9TDFOptions *options, const char *currentTDFFile)
{
	RCType rc = RC_FAILED;
	unsigned int groupCount = 0;
	J9TDFGroup *groups = NULL;
	J9TDFFile *tdf = NULL;

	FileReader reader;
	TDFParser parser;

	Path *current = _visitedFile;
	char *realPath = NULL;

	/**
	 * User might specify multiple scan roots for example -root src,src/omr
	 * To avoid processing trace files multiple times keep the record of processed files.
	 * To handle relative paths omrfile_realpath is used to resolve canonicalized absolute pathname.
	 */
	if (NULL == (realPath = Port::omrfile_realpath(currentTDFFile))) {
		FileUtils::printError("Failed to resolve full path to file: %s\n", currentTDFFile);
		goto done;
	}
	while (NULL != current) {
		if (0 == strcmp(current->path, realPath)) {
			break;
		}
		current = current->next;
	}
	if (NULL == current) {
		Path *tmp = (Path *) Port::omrmem_calloc(1, sizeof(Path));
		tmp->path = realPath;
		tmp->next = _visitedFile;
		_visitedFile = tmp;
	} else if (options->debugOutput) {
		FileUtils::printError("File %s was already processed\n", realPath);
		goto done;
	}

	printf("Processing tdf file %s\n", currentTDFFile);

	rc = reader.init(currentTDFFile);
	if (RC_OK != rc) {
		FileUtils::printError("Failed to read from file: %s\n", currentTDFFile);
		goto done;
	}

	parser.init(&reader, options->treatWarningAsError);
	tdf = parser.parse();
	if (NULL == tdf) {
		rc = RC_FAILED;
		goto done;
	}

	tdf->fileName = strdup(currentTDFFile);
	if (NULL == tdf->fileName) {
		eprintf("Failed to allocate memory");
		rc = RC_FAILED;
		goto done;
	}

	groups = calculateGroups(tdf, &groupCount);
	if (NULL == groups) {
		FileUtils::printError("Failed to calculate tracepoint groups");
		rc = RC_FAILED;
		goto done;
	}

	TraceHeaderWriter hfw;
	DATFileWriter dfw;
	CFileWriter cfw;

	rc = hfw.writeOutputFiles(options, tdf);
	if (RC_OK != rc) {
		FileUtils::printError("Failed to generate header file for %s\n", currentTDFFile);
		goto done;
	}
	rc = dfw.writeOutputFiles(options, tdf);
	if (RC_OK != rc) {
		FileUtils::printError("Failed to generate DAT file for %s\n", currentTDFFile);
		goto done;
	}

	if (options->generateCFiles) {
		rc = cfw.writeOutputFiles(options, tdf, groups, groupCount);
		if (RC_OK != rc) {
			FileUtils::printError("Failed to generate C file for %s\n", currentTDFFile);
			goto done;
		}
	}

done:
	if (NULL != tdf) {
		Port::omrmem_free((void **)&tdf->fileName);
		Port::omrmem_free((void **)&tdf->header.datfilename);
		Port::omrmem_free((void **)&tdf->header.executable);
		Port::omrmem_free((void **)&tdf->header.submodules);

		J9TDFTracepoint *tp = tdf->tracepoints;
		while (NULL != tp) {
			J9TDFTracepoint *next = tp->nexttp;
			Port::omrmem_free((void **)&tp->name);
			if (NULL != tp->groups) {
				unsigned int groupIndex = 0;
				while (NULL != tp->groups[groupIndex]) {
					Port::omrmem_free((void **)&tp->groups[groupIndex]);
					groupIndex += 1;
				}
				tp->groups = NULL;
			}
			Port::omrmem_free((void **)&tp->format);
			Port::omrmem_free((void **)&tp->parameters);

			tp = next;
		}
	}

	if (NULL != groups) {
		freeGroups(groups);
		groups = NULL;
	}
	return rc;
}
//================================================================================================================
CreateGameDirectory::CreateGameDirectory(GameDirectory3D* gd)
{
	_mkdir(gd->GAME_FOLDER.c_str());
	_mkdir(gd->m_required_textures.c_str());
	_mkdir(gd->m_menu_sprites_path.c_str());
	_mkdir(gd->m_hud_path.c_str());
	_mkdir(gd->m_scripts_path.c_str());
	_mkdir(gd->m_music_path.c_str());
	_mkdir(gd->m_materials_path.c_str());
	_mkdir(gd->m_heightmaps_path.c_str());
	_mkdir(gd->m_template_poly_path.c_str());
	_mkdir(gd->m_models_path.c_str());
	_mkdir(gd->m_textures_path.c_str());
	_mkdir(gd->m_xml_path.c_str());
	//_mkdir(gd->m_xml_menu_path.c_str());
	//_mkdir(gd->m_xml_hud_path.c_str());
	_mkdir(gd->m_xml_maps_path.c_str());
	
	CFileWriter fileWriter;
	fileWriter.Open(gd->m_game_ini_path);
	fileWriter.Write("[GAME]\n");
	fileWriter.Write("\n");
	fileWriter.Write(";Game can either be Topdown or Platformer, 3D for 3D game\n");
	fileWriter.Write("GameType=3D\n");
	fileWriter.Close();
	
	CFileWriter fileMainMenuWriter;
	fileMainMenuWriter.Open(gd->m_xml_main_menu_path);
	fileMainMenuWriter.Close();

	CFileWriter fileInGameMenuWriter;
	fileInGameMenuWriter.Open(gd->m_xml_ingame_menu_path);
	fileInGameMenuWriter.Close();
	
	CFileWriter fileHUDWriter;
	fileHUDWriter.Open(gd->m_xml_hud_path);
	fileHUDWriter.Close();
	
	CopyFolder("RequiredTextures", gd->m_required_textures);
	CopyFolder("RequiredScripts", gd->m_scripts_path);
	CopyFolder("TemplatePolys", gd->m_template_poly_path);
}
//================================================================================================================
//================================================================================================================
CreateGameDirectory::CreateGameDirectory(GameDirectory2D* gd, GameType2D gameType)
{
	_mkdir(gd->GAME_FOLDER.c_str());
	_mkdir(gd->m_required_textures.c_str());
	_mkdir(gd->m_sprites_path.c_str());
	_mkdir(gd->m_menu_sprites_path.c_str());
	_mkdir(gd->m_hud_path.c_str());
	_mkdir(gd->m_tiles_path.c_str());
	_mkdir(gd->m_scripts_path.c_str());
	_mkdir(gd->m_music_path.c_str());
	_mkdir(gd->m_animation_profiles_path.c_str());
	_mkdir(gd->m_animation_profile_sprites_path.c_str());
	_mkdir(gd->m_animation_profile_tiles_path.c_str());
	_mkdir(gd->m_xml_path.c_str());
	_mkdir(gd->m_xml_maps_path.c_str());
	_mkdir(gd->m_xml_sprites_path.c_str());
	//_mkdir(gd->m_xml_menu_path.c_str());
	//_mkdir(gd->m_xml_hud_path.c_str());
	_mkdir(gd->m_xml_worlds_path.c_str());

	if (gameType == TOPDOWN)
	{
		CFileWriter fileWriter;
		fileWriter.Open(gd->m_game_ini_path);
		fileWriter.Write("[GAME]\n");
		fileWriter.Write("\n");
		fileWriter.Write(";Game can either be Topdown or Platformer, 3D for 3D game\n");
		fileWriter.Write("GameType=Topdown\n");
		fileWriter.Close();
	}
	else if (gameType == PLATFORMER)
	{
		CFileWriter fileWriter;
		fileWriter.Open(gd->m_game_ini_path);
		fileWriter.Write("[GAME]\n");
		fileWriter.Write("\n");
		fileWriter.Write(";Game can either be Topdown or Platformer, 3D for 3D game\n");
		fileWriter.Write("GameType=Platformer\n");
		fileWriter.Close();
	}
	
	CFileWriter fileMainMenuWriter;
	fileMainMenuWriter.Open(gd->m_xml_main_menu_path);
	fileMainMenuWriter.Close();
	
	CFileWriter fileInGameMenuWriter;
	fileInGameMenuWriter.Open(gd->m_xml_ingame_menu_path);
	fileInGameMenuWriter.Close();

	CFileWriter fileHUDWriter;
	fileHUDWriter.Open(gd->m_xml_hud_path);
	fileHUDWriter.Close();
	
	CFileWriter fileInventoryWriter;
	fileInventoryWriter.Open(gd->m_xml_inventory_path);
	fileInventoryWriter.Close();
	
	CopyFolder("RequiredTextures", gd->m_required_textures);
	CopyFolder("RequiredScripts", gd->m_scripts_path);
}