/*
  PROGRAM BY EMAN FOR 2K-SOFT 
  WWW : WWW.2K-SOFT.GAMECODE.CZ   
*/

#include "LogFile.h"

//const char *g_cestaLog = "Data/Log/";

C_LOG_FILE::C_LOG_FILE()
{
	_file_name = NULL;
	_soubor = NULL;
}

C_LOG_FILE::C_LOG_FILE(std::string name)
{
	this->Create( name.c_str() );
}

C_LOG_FILE::~C_LOG_FILE()
{
	this->Write("end.");
	if(_soubor != 0) fclose(_soubor);
}

bool C_LOG_FILE::Create(const char *filename)
{
	_soubor = NULL;
	
	char m_fileName[255];
	sprintf(m_fileName, "Data/Log/%s", filename);

	_soubor = fopen(m_fileName, "wt");
	if (_soubor == 0) return FALSE;
	
	_file_name = (char*)filename;	
	fprintf(_soubor, "Start log file(eMan W-Engine) name : %s ...OK", filename);
	_n();_n();

	return TRUE;
}
void C_LOG_FILE::Clear()
{
	//soubor = NULL;
	if(_file_name == NULL) return;
	fclose(_soubor);
	_soubor = fopen(_file_name,"wt");
}

void C_LOG_FILE::Write(const char *string)
{
	if(string == NULL) return;
	fprintf(_soubor, string);
	_n();
}

void C_LOG_FILE::Write(int value)
{
	char string[20];
	sprintf(string,"%d",value);
	fprintf(_soubor, string);
	_n();
}

void C_LOG_FILE::ExWrite(std::string text)
{
	if(text.size() == 0) return;
	fprintf(_soubor, text.c_str());
}

void C_LOG_FILE::ExWriteln(std::string text)
{
	if(text.size() == 0) return;
	fprintf(_soubor, text.c_str());
	_n();
}

