#include "stdafx.h"
#include "CLS_MyPublic.h"


void trace_r(const char* _pszFormat, ...)
{
	static const int iMaxPath = 512;
	char pcData[iMaxPath] = {0};
	int iLen = (int)strlen(pcData);
	va_list marker;
	va_start(marker, _pszFormat);
	vsnprintf(pcData+iLen, iMaxPath-iLen, _pszFormat, marker);
	va_end(marker);
	::OutputDebugString(pcData);
}

void trace_d(const char* _pszFormat, ...)
{
#ifdef _DEBUG
	static const int iMaxPath = 512;
	char pcData[iMaxPath] = {0};
	int iLen = (int)strlen(pcData);
	va_list marker;
	va_start(marker, _pszFormat);
	vsnprintf(pcData+iLen, iMaxPath-iLen, _pszFormat, marker);
	va_end(marker);
	::OutputDebugString(pcData);
#endif
}

int	CheckFileSize(const char* _pszFileName)
{
	
// 	FILE* fpTry = _fsopen(_pszFileName, "rb", _SH_DENYNO);
// 	if (NULL == fpTry)
// 	{
// 		return -1;
// 	}
// 
// 	fseek(fpTry, 0, SEEK_END);
// 	unsigned int uiLength = ftell(fpTry);
// 	if (uiLength > INT_MAX)
// 	{
// 		fclose(fpTry);
// 		return -2;
// 	}
// 	fclose(fpTry);
	return 0;
}

void OutPutLogMsg( const char* _pcLogFmt, ...)
{
	if (NULL == _pcLogFmt)
	{
		_pcLogFmt = "";
	}
	char cLogBuf[4096] = {0};
	va_list vlsLog;
	va_start( vlsLog, _pcLogFmt );
	_vsnprintf(cLogBuf, 4096, _pcLogFmt, vlsLog);
	va_end(vlsLog);

	::OutputDebugString(cLogBuf);
}

void OutPutLogMsgEx( const char* _pcLogFmt, ...)
{
	if (NULL == _pcLogFmt)
	{
		_pcLogFmt = "";
	}
	char cLogBuf[4096] = {0};
	va_list vlsLog;
	va_start( vlsLog, _pcLogFmt );
	_vsnprintf(cLogBuf, 4096, _pcLogFmt, vlsLog);
	va_end(vlsLog);

	char* pcLogInfo = strcat(cLogBuf, "\n");
	::OutputDebugString(pcLogInfo);
}

CString	DialogFileOpenPath(char* _pcType)
{
	CString cstrPath;
	if (NULL == _pcType)
	{
		return cstrPath;
	}
	
	CFileDialog dlgFile(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _pcType, NULL);
	if (dlgFile.DoModal() == IDOK)
	{
		cstrPath = dlgFile.GetPathName();
	}

	return cstrPath;
}